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

TumblrController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 1
cbo 2
dl 0
loc 52
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getBlogInfo() 0 6 1
A getPosts() 0 6 1
A getPage() 0 6 1
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