1 | <?php |
||
11 | class Tmdb implements TmdbInterface |
||
12 | { |
||
13 | |||
14 | // Private variables |
||
15 | private $api_key = null; // API Key |
||
16 | private $language = 'fr-FR'; // Default language for API response |
||
17 | public $base_api_url = 'https://api.themoviedb.org/3/'; // Base URL of the API |
||
18 | private $include_adult = false; // Include adult content in search result |
||
19 | private $page = 1; // API Page result |
||
20 | // Protected variables |
||
21 | protected $configuration = null; // API Configuration |
||
22 | protected $genres = null; // API Genres |
||
23 | |||
24 | /** |
||
25 | * Constructor |
||
26 | * @param string $api_key TMDB API Key |
||
27 | */ |
||
28 | |||
29 | 139 | public function __construct(string $api_key) |
|
33 | |||
34 | /** |
||
35 | * Send cUrl request to TMDB API |
||
36 | * @param Interfaces\HttpRequestInterface $http_request |
||
37 | * @param string $action API action to request |
||
38 | * @param string $query Query of the request (optional) |
||
39 | * @param array $options Array of options of the request (optional) |
||
40 | * @return \stdClass |
||
41 | */ |
||
42 | 5 | public function sendRequest(HttpRequestInterface $http_request, string $action, string $query = null, array $options = array()): \stdClass |
|
82 | |||
83 | /** |
||
84 | * Build URL for HTTP Call |
||
85 | * @param string $action API action to request |
||
86 | * @param string $query Query of the request (optional) |
||
87 | * @param array $options Array of options of the request (optional) |
||
88 | * @return string |
||
89 | */ |
||
90 | private function buildHTTPUrl($action, $query, $options) |
||
110 | |||
111 | /** |
||
112 | * Get API Configuration |
||
113 | * @return \stdClass |
||
114 | */ |
||
115 | 8 | public function getConfiguration(): \stdClass |
|
129 | |||
130 | /** |
||
131 | * Check options rules before send request |
||
132 | * @param array $options Array of options to validate |
||
133 | * @return array |
||
134 | * @throws \Exception |
||
135 | */ |
||
136 | 131 | public function checkOptions(array $options): array |
|
166 | |||
167 | /** |
||
168 | * Check year format |
||
169 | * @param mixed $year year to validate |
||
170 | * @return int year validated |
||
171 | * @throws \Exception |
||
172 | */ |
||
173 | 1 | private function checkYear(int $year): int |
|
178 | |||
179 | /** |
||
180 | * Check language |
||
181 | * @param string $language Language string with format ISO 639-1 |
||
182 | * @return string Language string validated |
||
183 | * @throws \Exception |
||
184 | */ |
||
185 | 44 | private function checkLanguage(string $language): string |
|
194 | |||
195 | } |
||
196 |