From e0cf94713ff97c0c7f82c5739587a4f8bfd9a04a Mon Sep 17 00:00:00 2001 From: Michael Roterman Date: Sat, 5 Apr 2014 18:11:44 +0200 Subject: [PATCH] Adding videos method on the API scope. --- examples/movies/api/videos.php | 21 +++++++++++++++++++ examples/tv/api/episode/videos.php | 21 +++++++++++++++++++ examples/tv/api/season/videos.php | 21 +++++++++++++++++++ examples/tv/api/tv/videos.php | 21 +++++++++++++++++++ lib/Tmdb/Api/Movies.php | 13 ++++++++++++ lib/Tmdb/Api/Tv.php | 19 +++++++++++++++--- lib/Tmdb/Api/TvEpisode.php | 29 +++++++++++++++++++++++++++ lib/Tmdb/Api/TvSeason.php | 14 +++++++++++++ lib/Tmdb/Factory/TvFactory.php | 9 ++++++++- test/Tmdb/Tests/Api/MoviesTest.php | 13 ++++++++++++ test/Tmdb/Tests/Api/TvEpisodeTest.php | 13 ++++++++++++ test/Tmdb/Tests/Api/TvSeasonTest.php | 13 ++++++++++++ test/Tmdb/Tests/Api/TvTest.php | 13 ++++++++++++ 13 files changed, 216 insertions(+), 4 deletions(-) create mode 100644 examples/movies/api/videos.php create mode 100644 examples/tv/api/episode/videos.php create mode 100644 examples/tv/api/season/videos.php create mode 100644 examples/tv/api/tv/videos.php diff --git a/examples/movies/api/videos.php b/examples/movies/api/videos.php new file mode 100644 index 00000000..0d8b0ac1 --- /dev/null +++ b/examples/movies/api/videos.php @@ -0,0 +1,21 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +require_once '../../../vendor/autoload.php'; +require_once '../../../apikey.php'; + +$token = new \Tmdb\ApiToken(TMDB_API_KEY); +$client = new \Tmdb\Client($token); + +$videos = $client->getMoviesApi()->getVideos(87421); + +var_dump($videos); diff --git a/examples/tv/api/episode/videos.php b/examples/tv/api/episode/videos.php new file mode 100644 index 00000000..8350565a --- /dev/null +++ b/examples/tv/api/episode/videos.php @@ -0,0 +1,21 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +require_once '../../../../vendor/autoload.php'; +require_once '../../../../apikey.php'; + +$token = new \Tmdb\ApiToken(TMDB_API_KEY); +$client = new \Tmdb\Client($token); + +$result = $client->getTvEpisodeApi()->getVideos(1396, 2, 1); + +var_dump($result); diff --git a/examples/tv/api/season/videos.php b/examples/tv/api/season/videos.php new file mode 100644 index 00000000..7feaf722 --- /dev/null +++ b/examples/tv/api/season/videos.php @@ -0,0 +1,21 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +require_once '../../../../vendor/autoload.php'; +require_once '../../../../apikey.php'; + +$token = new \Tmdb\ApiToken(TMDB_API_KEY); +$client = new \Tmdb\Client($token); + +$result = $client->getTvSeasonApi()->getVideos(1396, 2); + +var_dump($result); diff --git a/examples/tv/api/tv/videos.php b/examples/tv/api/tv/videos.php new file mode 100644 index 00000000..66fcde8c --- /dev/null +++ b/examples/tv/api/tv/videos.php @@ -0,0 +1,21 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +require_once '../../../../vendor/autoload.php'; +require_once '../../../../apikey.php'; + +$token = new \Tmdb\ApiToken(TMDB_API_KEY); +$client = new \Tmdb\Client($token); + +$result = $client->getTvApi()->getVideos(1396); + +var_dump($result); diff --git a/lib/Tmdb/Api/Movies.php b/lib/Tmdb/Api/Movies.php index 38390d94..59a555b1 100644 --- a/lib/Tmdb/Api/Movies.php +++ b/lib/Tmdb/Api/Movies.php @@ -263,4 +263,17 @@ public function rateMovie($id, $rating) { return $this->postJson('movie/' . $id . '/rating', array('value' => (float) $rating)); } + + /** + * Get the videos (trailers, teasers, clips, etc...) for a specific movie id. + * + * @param $movie_id + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getVideos($movie_id, array $parameters = array(), array $headers = array()) + { + return $this->get('movie/' . $movie_id . '/videos', $parameters, $headers); + } } diff --git a/lib/Tmdb/Api/Tv.php b/lib/Tmdb/Api/Tv.php index af066928..68ebb63b 100644 --- a/lib/Tmdb/Api/Tv.php +++ b/lib/Tmdb/Api/Tv.php @@ -111,7 +111,7 @@ public function getTopRated(array $parameters = array(), array $headers = array( */ public function getTranslations($tvshow_id, array $parameters = array(), array $headers = array()) { - $this->get('tv/' . $tvshow_id . '/translations', $parameters, $headers); + return $this->get('tv/' . $tvshow_id . '/translations', $parameters, $headers); } /** @@ -125,7 +125,7 @@ public function getTranslations($tvshow_id, array $parameters = array(), array $ */ public function getOnTheAir(array $parameters = array(), array $headers = array()) { - $this->get('tv/on_the_air', $parameters, $headers); + return $this->get('tv/on_the_air', $parameters, $headers); } /** @@ -139,6 +139,19 @@ public function getOnTheAir(array $parameters = array(), array $headers = array( */ public function getAiringToday(array $parameters = array(), array $headers = array()) { - $this->get('tv/airing_today', $parameters, $headers); + return $this->get('tv/airing_today', $parameters, $headers); + } + + /** + * Get the videos that have been added to a TV series (trailers, opening credits, etc...) + * + * @param int $tvshow_id + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getVideos($tvshow_id, array $parameters = array(), array $headers = array()) + { + return $this->get('tv/' . $tvshow_id . '/videos', $parameters, $headers); } } diff --git a/lib/Tmdb/Api/TvEpisode.php b/lib/Tmdb/Api/TvEpisode.php index e05cb3e1..2a15f48f 100644 --- a/lib/Tmdb/Api/TvEpisode.php +++ b/lib/Tmdb/Api/TvEpisode.php @@ -134,4 +134,33 @@ public function getImages( $headers ); } + + /** + * Get the videos that have been added to a TV episode (teasers, clips, etc...) + * + * @param $tvshow_id + * @param $season_number + * @param $episode_number + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getVideos( + $tvshow_id, + $season_number, + $episode_number, + array $parameters = array(), + array $headers = array() + ) { + return $this->get( + sprintf( + 'tv/%s/season/%s/episode/%s/videos', + $tvshow_id, + $season_number, + $episode_number + ), + $parameters, + $headers + ); + } } diff --git a/lib/Tmdb/Api/TvSeason.php b/lib/Tmdb/Api/TvSeason.php index b4785359..5085dee1 100644 --- a/lib/Tmdb/Api/TvSeason.php +++ b/lib/Tmdb/Api/TvSeason.php @@ -74,4 +74,18 @@ public function getImages($tvshow_id, $season_number, array $parameters = array( { return $this->get(sprintf('tv/%s/season/%s/images', $tvshow_id, $season_number), $parameters, $headers); } + + /** + * Get the videos that have been added to a TV season (trailers, teasers, etc...) + * + * @param $tvshow_id + * @param $season_number + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getVideos($tvshow_id, $season_number, array $parameters = array(), array $headers = array()) + { + return $this->get(sprintf('tv/%s/season/%s/videos', $tvshow_id, $season_number), $parameters, $headers); + } } diff --git a/lib/Tmdb/Factory/TvFactory.php b/lib/Tmdb/Factory/TvFactory.php index 1ad6c7e0..e44bfa0c 100644 --- a/lib/Tmdb/Factory/TvFactory.php +++ b/lib/Tmdb/Factory/TvFactory.php @@ -136,8 +136,15 @@ public function create(array $data = array()) /** Translations */ if (array_key_exists('translations', $data) && null !== $data['translations']) { + + if (array_key_exists('translations', $data['translations'])) { + $translations = $data['translations']['translations']; + } else { + $translations = $data['translations']; + } + $tvShow->setTranslations( - $this->createGenericCollection($data['translations']['translations'], new Translation()) + $this->createGenericCollection($translations, new Translation()) ); } diff --git a/test/Tmdb/Tests/Api/MoviesTest.php b/test/Tmdb/Tests/Api/MoviesTest.php index 92d0c3f7..cef6e85f 100644 --- a/test/Tmdb/Tests/Api/MoviesTest.php +++ b/test/Tmdb/Tests/Api/MoviesTest.php @@ -255,6 +255,19 @@ public function shouldRateMovie() $api->rateMovie(self::MOVIE_ID, 7.5); } + /** + * @test + */ + public function shouldGetVideos() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('movie/' . self::MOVIE_ID . '/videos'); + + $api->getVideos(self::MOVIE_ID); + } + protected function getApiClass() { return 'Tmdb\Api\Movies'; diff --git a/test/Tmdb/Tests/Api/TvEpisodeTest.php b/test/Tmdb/Tests/Api/TvEpisodeTest.php index c0af9f20..1d37dc1f 100644 --- a/test/Tmdb/Tests/Api/TvEpisodeTest.php +++ b/test/Tmdb/Tests/Api/TvEpisodeTest.php @@ -70,6 +70,19 @@ public function shouldGetEpisodeImages() $api->getImages(self::TV_ID, self::SEASON_ID, self::EPISODE_ID); } + /** + * @test + */ + public function shouldGetEpisodeVideos() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('tv/' . self::TV_ID . '/season/' . self::SEASON_ID . '/episode/' . self::EPISODE_ID . '/videos'); + + $api->getVideos(self::TV_ID, self::SEASON_ID, self::EPISODE_ID); + } + protected function getApiClass() { return 'Tmdb\Api\TvEpisode'; diff --git a/test/Tmdb/Tests/Api/TvSeasonTest.php b/test/Tmdb/Tests/Api/TvSeasonTest.php index a1f20ce7..a0421950 100644 --- a/test/Tmdb/Tests/Api/TvSeasonTest.php +++ b/test/Tmdb/Tests/Api/TvSeasonTest.php @@ -69,6 +69,19 @@ public function shouldGetSeasonImages() $api->getImages(self::TV_ID, self::SEASON_ID); } + /** + * @test + */ + public function shouldGetSeasonVideos() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('tv/' . self::TV_ID . '/season/' . self::SEASON_ID . '/videos'); + + $api->getVideos(self::TV_ID, self::SEASON_ID); + } + protected function getApiClass() { return 'Tmdb\Api\TvSeason'; diff --git a/test/Tmdb/Tests/Api/TvTest.php b/test/Tmdb/Tests/Api/TvTest.php index 9eeebcb6..3fd637d8 100644 --- a/test/Tmdb/Tests/Api/TvTest.php +++ b/test/Tmdb/Tests/Api/TvTest.php @@ -133,6 +133,19 @@ public function shouldGetAiringToday() $api->getAiringToday(); } + /** + * @test + */ + public function shouldGetVideos() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('tv/' . self::TV_ID . '/videos'); + + $api->getVideos(self::TV_ID); + } + protected function getApiClass() { return 'Tmdb\Api\Tv';