Completed
Push — master ( 31939f...60959d )
by PROSPER
03:19
created

TumblrController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
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 7
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 Tumblr;
8
use App\Http\Requests;
9
use App\Http\Controllers\Controller;
10
11
class TumblrController extends Controller
12
{
13
    /**
14
     * Instance of Tumblr API
15
     * @var object
16
     */
17
    protected $tumblr;
18
19
     /**
20
     * Initialize the Controller with necessary arguments
21
     */
22
    public function __construct()
23
    {
24
        $this->tumblr = new Tumblr();
25
26
        // Set API key.
27
        $this->tumblr->setApiKey(env('TUMBLR_API_KEY'));
28
    }
29
30
    /**
31
     * Get Basic Information about the blog
32
     * @return array
33
     */
34
    private function getBlogInfo($tumblrBlogUrl)
35
    {
36
        $info = $this->tumblr->blogInfo($tumblrBlogUrl);
37
38
        return (array)$info;
39
    }
40
41
    /**
42
     * Get Posts from the Tumblr blog
43
     * @return array
44
     */
45
    private function getPosts($tumblrBlogUrl)
46
    {
47
        $info = $this->tumblr->posts($tumblrBlogUrl);
48
49
        return (array)$info->response->posts;
50
    }
51
52
    /**
53
     * Return all data to the Tumblr API dashboard
54
     * @return mixed
55
     */
56
    public function getPage()
57
    {
58
        $posts = $this->getPosts('taylorswift.tumblr.com');
59
60
        return view('api.tumblr')->withPosts($posts);
61
    }
62
}
63