Completed
Push — dev ( d3159d...24b104 )
by Darko
08:57
created

FanartTV::_getUrl()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 7
ccs 0
cts 0
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Fanart.TV
4
 * PHP class - wrapper for Fanart.TV's API
5
 * API Documentation - http://docs.fanarttv.apiary.io/#.
6
 *
7
 * @author    confact <[email protected]>
8
 * @author    DariusIII <[email protected]>
9
 * @copyright 2013 confact
10
 * @copyright 2017 NNTmux
11
 * @date 2017-04-12
12
 * @release <0.0.2>
13
 */
14
15
namespace Blacklight\libraries;
16
17
class FanartTV
18
{
19
    /**
20
     * @var string
21
     */
22
    private $apiKey;
23
24
    /**
25
     * @var string
26
     */
27
    private $server;
28
29
    /**
30
     * The constructor setting the config variables.
31
     *
32
     * @param $apiKey
33
     */
34
    public function __construct($apiKey)
35
    {
36
        $this->apiKey = $apiKey;
37
        $this->server = 'https://webservice.fanart.tv/v3';
38
    }
39
40
    /**
41
     * Getting movie pictures.
42
     *
43
     * @param string $id
44
     *
45
     * @return array|false
46
     */
47
    public function getMovieFanArt($id)
48
    {
49
        if ($this->apiKey !== '') {
50
            $fanArt = $this->_getUrl('movies/'.$id);
51
            if (! empty($fanArt) && $fanArt['status'] !== 'error') {
52
                return $fanArt;
53
            }
54
55
            return false;
56
        }
57
58
        return false;
59
    }
60
61
    /**
62
     * Getting tv show pictures.
63
     *
64
     * @param string $id
65
     * @return array|false
66
     */
67
    public function getTVFanart($id)
68
    {
69
        if ($this->apiKey !== '') {
70
            $fanArt = $this->_getUrl('tv/'.$id);
71
            if (! empty($fanArt) && $fanArt['status'] !== 'error') {
72
                return $fanArt;
73
            }
74
75
            return false;
76
        }
77
78
        return false;
79
    }
80
81
    /**
82
     * The function making all the work using curl to call.
83
     *
84
     * @param string $path
85
     * @return false|array
86
     */
87
    private function _getUrl($path)
88
    {
89
        $url = $this->server.'/'.$path.'?api_key='.$this->apiKey;
90
91
        $response = getRawHtml($url);
92
93
        return $response !== false ? json_decode($response, true) : false;
94
    }
95
}
96