Skip to content

Commit

Permalink
Adding videos method on the API scope.
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfzdotnet committed Apr 5, 2014
1 parent 4d92a83 commit e0cf947
Show file tree
Hide file tree
Showing 13 changed files with 216 additions and 4 deletions.
21 changes: 21 additions & 0 deletions examples/movies/api/videos.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/**
* This file is part of the Tmdb PHP API created by Michael Roterman.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @package Tmdb
* @author Michael Roterman <[email protected]>
* @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);
21 changes: 21 additions & 0 deletions examples/tv/api/episode/videos.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/**
* This file is part of the Tmdb PHP API created by Michael Roterman.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @package Tmdb
* @author Michael Roterman <[email protected]>
* @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);
21 changes: 21 additions & 0 deletions examples/tv/api/season/videos.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/**
* This file is part of the Tmdb PHP API created by Michael Roterman.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @package Tmdb
* @author Michael Roterman <[email protected]>
* @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);
21 changes: 21 additions & 0 deletions examples/tv/api/tv/videos.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/**
* This file is part of the Tmdb PHP API created by Michael Roterman.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @package Tmdb
* @author Michael Roterman <[email protected]>
* @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);
13 changes: 13 additions & 0 deletions lib/Tmdb/Api/Movies.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
19 changes: 16 additions & 3 deletions lib/Tmdb/Api/Tv.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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);
}
}
29 changes: 29 additions & 0 deletions lib/Tmdb/Api/TvEpisode.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
}
14 changes: 14 additions & 0 deletions lib/Tmdb/Api/TvSeason.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
9 changes: 8 additions & 1 deletion lib/Tmdb/Factory/TvFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())
);
}

Expand Down
13 changes: 13 additions & 0 deletions test/Tmdb/Tests/Api/MoviesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
13 changes: 13 additions & 0 deletions test/Tmdb/Tests/Api/TvEpisodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
13 changes: 13 additions & 0 deletions test/Tmdb/Tests/Api/TvSeasonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
13 changes: 13 additions & 0 deletions test/Tmdb/Tests/Api/TvTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit e0cf947

Please sign in to comment.