Completed
Push — master ( d02f26...daa6b1 )
by PROSPER
03:14
created

TwitterController::getPage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use Illuminate\Http\Request;
6
7
use App\Http\Requests;
8
use App\Http\Controllers\Controller;
9
use Twitter;
10
11
class TwitterController extends Controller
12
{
13
    protected $searchItem;
14
    protected $githubHandle;
15
16
    public function __construct()
17
    {
18
        $this->searchItem = 'laravel';
19
        $this->githubHandle = 'unicodeveloper';
20
    }
21
22
    public function getPage()
23
    {
24
        $searchedTweets = json_decode($this->searchForTweets($this->searchItem), true);
25
26
        return view('api.twitter')->withTweets($searchedTweets['statuses']);
27
    }
28
29
    private function getLatestTweets()
30
    {
31
        return Twitter::getHomeTimeline(['count' => 2, 'format' => 'json']);
32
    }
33
34
    private function searchForTweets($item)
35
    {
36
        return Twitter::getSearch(['q' => $item, 'count' => 4, 'format' => 'json']);
37
    }
38
39
    public function sendTweet(Request $request)
40
    {
41
        $this->validate($request, [
42
            'tweet' => 'required',
43
        ]);
44
45
        $tweet = $request->input('tweet') . ' #LaravelHackathonStarter';
46
47
        Twitter::postTweet(['status' => $tweet, 'format' => 'json']);
48
49
        return redirect()->back()->with('info','Your Tweet has been posted successfully');
50
    }
51
}
52