some progress
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service\TMDBApi;
|
||||
|
||||
use CodeIgniter\HTTP\CURLRequest;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
abstract class AbstractApiService
|
||||
{
|
||||
const BASE_URL = 'https://api.themoviedb.org/3/';
|
||||
|
||||
/** @var CURLRequest */
|
||||
protected $client;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
// new guzzle client
|
||||
// $this->client = service('curlrequest', options: [
|
||||
// 'timeout' => 10.0,
|
||||
// 'connect_timeout' => 150,
|
||||
// 'debug' => false,
|
||||
// 'verify' => false,
|
||||
// ]);
|
||||
}
|
||||
|
||||
public function get(string $path, array $parameters = [], array $headers = []): array
|
||||
{
|
||||
$path = self::BASE_URL.$path.'?api_key=49a4c5ff00d832668aa505feaf197955';
|
||||
|
||||
$headers['Authorization'] = 'Bearer 49a4c5ff00d832668aa505feaf197955';
|
||||
$headers['accept'] = 'application/json';
|
||||
|
||||
try {
|
||||
$r = Http::withHeaders($headers)->get($path);
|
||||
// $r = $this->client->request('GET', $path, [
|
||||
// 'headers' => $headers
|
||||
// ]);
|
||||
} catch (\Throwable $e) {
|
||||
var_dump($e->getMessage());
|
||||
die;
|
||||
}
|
||||
|
||||
|
||||
return $this->decodeResponse(
|
||||
$r
|
||||
);
|
||||
}
|
||||
|
||||
private function decodeResponse($response)
|
||||
{
|
||||
try {
|
||||
if ($response->body()) {
|
||||
return json_decode($response->body(), true, 512, JSON_THROW_ON_ERROR);
|
||||
}
|
||||
|
||||
return [];
|
||||
} catch (JsonException $e) {
|
||||
throw new UnexpectedResponseException(
|
||||
sprintf(
|
||||
'Unable to decode response with body "%s", %s.',
|
||||
(string)$response->body(),
|
||||
json_last_error_msg()
|
||||
),
|
||||
$response->status(),
|
||||
$e
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,300 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service\TMDBApi;
|
||||
|
||||
class MoviesApi extends AbstractApiService
|
||||
{
|
||||
/**
|
||||
* Get the basic movie information for a specific movie id.
|
||||
*
|
||||
* @param $movieId
|
||||
* @param array $parameters
|
||||
* @param array $headers
|
||||
* @return mixed
|
||||
*/
|
||||
public function getMovie($movieId, array $parameters = [], array $headers = [])
|
||||
{
|
||||
sleep(1);
|
||||
return $this->get('movie/' . $movieId, $parameters, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the alternative titles for a specific movie id.
|
||||
*
|
||||
* @param $movieId
|
||||
* @param array $parameters
|
||||
* @param array $headers
|
||||
* @return mixed
|
||||
*/
|
||||
public function getAlternativeTitles($movieId, array $parameters = [], array $headers = [])
|
||||
{
|
||||
sleep(1);
|
||||
return $this->get('movie/' . $movieId . '/alternative_titles', $parameters, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cast and crew information for a specific movie id.
|
||||
*
|
||||
* @param $movieId
|
||||
* @param array $parameters
|
||||
* @param array $headers
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCredits($movieId, array $parameters = [], array $headers = [])
|
||||
{
|
||||
sleep(1);
|
||||
return $this->get('movie/' . $movieId . '/credits', $parameters, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the images (posters and backdrops) for a specific movie id.
|
||||
*
|
||||
* @param $movieId
|
||||
* @param array $parameters
|
||||
* @param array $headers
|
||||
* @return mixed
|
||||
*/
|
||||
public function getImages($movieId, array $parameters = [], array $headers = [])
|
||||
{
|
||||
sleep(1);
|
||||
return $this->get('movie/' . $movieId . '/images', $parameters, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plot keywords for a specific movie id.
|
||||
*
|
||||
* @param $movieId
|
||||
* @param array $parameters
|
||||
* @param array $headers
|
||||
* @return mixed
|
||||
*/
|
||||
public function getKeywords($movieId, array $parameters = [], array $headers = [])
|
||||
{
|
||||
sleep(1);
|
||||
return $this->get('movie/' . $movieId . '/keywords', $parameters, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the release date by country for a specific movie id.
|
||||
*
|
||||
* @param $movieId
|
||||
* @param array $parameters
|
||||
* @param array $headers
|
||||
* @return mixed
|
||||
*/
|
||||
public function getReleases($movieId, array $parameters = [], array $headers = [])
|
||||
{
|
||||
sleep(1);
|
||||
return $this->get('movie/' . $movieId . '/releases', $parameters, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the trailers for a specific movie id.
|
||||
*
|
||||
* @param $movieId
|
||||
* @param array $parameters
|
||||
* @param array $headers
|
||||
* @return mixed
|
||||
* @deprecated TMDB changed the way of requesting trailers, see getVideos instead!
|
||||
*/
|
||||
public function getTrailers($movieId, array $parameters = [], array $headers = [])
|
||||
{
|
||||
sleep(1);
|
||||
return $this->get('movie/' . $movieId . '/trailers', $parameters, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the translations for a specific movie id.
|
||||
*
|
||||
* @param $movieId
|
||||
* @param array $parameters
|
||||
* @param array $headers
|
||||
* @return mixed
|
||||
*/
|
||||
public function getTranslations($movieId, array $parameters = [], array $headers = [])
|
||||
{
|
||||
sleep(1);
|
||||
return $this->get('movie/' . $movieId . '/translations', $parameters, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the similar movies for a specific movie id.
|
||||
*
|
||||
* @param $movieId
|
||||
* @param array $parameters
|
||||
* @param array $headers
|
||||
* @return mixed
|
||||
*/
|
||||
public function getSimilar($movieId, array $parameters = [], array $headers = [])
|
||||
{
|
||||
sleep(1);
|
||||
return $this->get('movie/' . $movieId . '/similar', $parameters, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the recommended movies for a specific movie id.
|
||||
*
|
||||
* @param $movieId
|
||||
* @param array $parameters
|
||||
* @param array $headers
|
||||
* @return mixed
|
||||
*/
|
||||
public function getRecommendations($movieId, array $parameters = [], array $headers = [])
|
||||
{
|
||||
sleep(1);
|
||||
return $this->get('movie/' . $movieId . '/recommendations', $parameters, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the reviews for a particular movie id.
|
||||
*
|
||||
* @param $movieId
|
||||
* @param array $parameters
|
||||
* @param array $headers
|
||||
* @return mixed
|
||||
*/
|
||||
public function getReviews($movieId, array $parameters = [], array $headers = [])
|
||||
{
|
||||
sleep(1);
|
||||
return $this->get('movie/' . $movieId . '/reviews', $parameters, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the lists that the movie belongs to.
|
||||
*
|
||||
* @param $movieId
|
||||
* @param array $parameters
|
||||
* @param array $headers
|
||||
* @return mixed
|
||||
*/
|
||||
public function getLists($movieId, array $parameters = [], array $headers = [])
|
||||
{
|
||||
sleep(1);
|
||||
return $this->get('movie/' . $movieId . '/lists', $parameters, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the changes for a specific movie id.
|
||||
*
|
||||
* @param $movieId
|
||||
* @param array $parameters
|
||||
* @param array $headers
|
||||
* @return mixed
|
||||
*/
|
||||
public function getChanges($movieId, array $parameters = [], array $headers = [])
|
||||
{
|
||||
sleep(1);
|
||||
return $this->get('movie/' . $movieId . '/changes', $parameters, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the latest movie id.
|
||||
*
|
||||
* @param array $parameters
|
||||
* @param array $headers
|
||||
* @return mixed
|
||||
*/
|
||||
public function getLatest(array $parameters = [], array $headers = [])
|
||||
{
|
||||
sleep(1);
|
||||
return $this->get('movie/latest', $parameters, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of upcoming movies. This list refreshes every day.
|
||||
* The maximum number of items this list will include is 100.
|
||||
*
|
||||
* @param array $parameters
|
||||
* @param array $headers
|
||||
* @return mixed
|
||||
*/
|
||||
public function getUpcoming(array $parameters = [], array $headers = [])
|
||||
{
|
||||
sleep(1);
|
||||
return $this->get('movie/upcoming', $parameters, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of movies playing in theatres. This list refreshes every day.
|
||||
* The maximum number of items this list will include is 100.
|
||||
*
|
||||
* @param array $parameters
|
||||
* @param array $headers
|
||||
* @return mixed
|
||||
*/
|
||||
public function getNowPlaying(array $parameters = [], array $headers = [])
|
||||
{
|
||||
sleep(1);
|
||||
return $this->get('movie/now_playing', $parameters, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of popular movies on The Movie Database.
|
||||
* This list refreshes every day.
|
||||
*
|
||||
* @param array $parameters
|
||||
* @param array $headers
|
||||
* @return mixed
|
||||
*/
|
||||
public function getPopular(array $parameters = [], array $headers = [])
|
||||
{
|
||||
sleep(1);
|
||||
return $this->get('movie/popular', $parameters, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of top rated movies. By default, this list will only include
|
||||
* movies that have 10 or more votes. This list refreshes every day.
|
||||
*
|
||||
* @param array $parameters
|
||||
* @param array $headers
|
||||
* @return mixed
|
||||
*/
|
||||
public function getTopRated(array $parameters = [], array $headers = [])
|
||||
{
|
||||
sleep(1);
|
||||
return $this->get('movie/top_rated', $parameters, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the videos (trailers, teasers, clips, etc...) for a specific movie id.
|
||||
*
|
||||
* @param $movieId
|
||||
* @param array $parameters
|
||||
* @param array $headers
|
||||
* @return mixed
|
||||
*/
|
||||
public function getVideos($movieId, array $parameters = [], array $headers = [])
|
||||
{
|
||||
sleep(1);
|
||||
return $this->get('movie/' . $movieId . '/videos', $parameters, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the watch providers (by region) for a specific movie id.
|
||||
*
|
||||
* @param $movieId
|
||||
* @param array $parameters
|
||||
* @param array $headers
|
||||
* @return mixed
|
||||
*/
|
||||
public function getWatchProviders($movieId, array $parameters = [], array $headers = [])
|
||||
{
|
||||
sleep(1);
|
||||
return $this->get('movie/' . $movieId . '/watch/providers', $parameters, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the external ids that we have stored for a movie.
|
||||
*
|
||||
* @param $movieId
|
||||
* @param array $parameters
|
||||
* @param array $headers
|
||||
* @return mixed
|
||||
*/
|
||||
public function getExternalIds($movieId, array $parameters = [], array $headers = [])
|
||||
{
|
||||
sleep(1);
|
||||
return $this->get('movie/' . $movieId . '/external_ids', $parameters, $headers);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user