Skip to content

Commit

Permalink
Adding TV API methods into TvRepository
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfzdotnet committed Feb 9, 2014
1 parent 5d2c907 commit 9586dc6
Show file tree
Hide file tree
Showing 8 changed files with 212 additions and 5 deletions.
22 changes: 22 additions & 0 deletions examples/tv/model/tv/credits.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?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);

$repository = new \Tmdb\Repository\TvRepository($client);
$tvShow = $repository->getCredits(1396);

var_dump($tvShow);
22 changes: 22 additions & 0 deletions examples/tv/model/tv/external_ids.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?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);

$repository = new \Tmdb\Repository\TvRepository($client);
$tvShow = $repository->getExternalIds(1396);

var_dump($tvShow);
22 changes: 22 additions & 0 deletions examples/tv/model/tv/images.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?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);

$repository = new \Tmdb\Repository\TvRepository($client);
$tvShow = $repository->getImages(1396);

var_dump($tvShow);
22 changes: 22 additions & 0 deletions examples/tv/model/tv/on_the_air.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?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);

$repository = new \Tmdb\Repository\TvRepository($client);
$tvShow = $repository->getOnTheAir();

var_dump($tvShow);
22 changes: 22 additions & 0 deletions examples/tv/model/tv/translations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?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);

$repository = new \Tmdb\Repository\TvRepository($client);
$tvShow = $repository->getTranslations(1396);

var_dump($tvShow);
15 changes: 15 additions & 0 deletions lib/Tmdb/Api/Tv.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,19 @@ public function getTopRated(array $parameters = array(), array $headers = array(
return $this->get('tv/top_rated', $parameters, $headers);
}

/**
* Get the list of translations that exist for a TV series.
*
* These translations cascade down to the episode level.
*
* @param int $tvshow_id
* @param array $parameters
* @param array $headers
* @return mixed
*/
public function getTranslations($tvshow_id, array $parameters = array(), array $headers = array())
{
$this->get('tv/' . $tvshow_id . '/translations', $parameters, $headers);
}

}
6 changes: 4 additions & 2 deletions lib/Tmdb/Factory/TvFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ public function __construct()
}

/**
* {@inheritdoc}
* @param array $data
*
* @return Tv
*/
public function create(array $data = array())
{
Expand Down Expand Up @@ -112,7 +114,7 @@ public function create(array $data = array())
}

/** Translations */
if (array_key_exists('translations', $data)) {
if (array_key_exists('translations', $data) && null !== $data['translations']) {
$tvShow->setTranslations($this->createGenericCollection($data['translations']['translations'], new Translation()));
}

Expand Down
86 changes: 83 additions & 3 deletions lib/Tmdb/Repository/TvRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
namespace Tmdb\Repository;

use Tmdb\Factory\TvFactory;
use Tmdb\Model\Common\GenericCollection;
use Tmdb\Model\Tv;
use Tmdb\Model\Tv\QueryParameter\AppendToResponse;

Expand Down Expand Up @@ -48,6 +47,74 @@ public function load($id, array $parameters = array(), array $headers = array())
return $this->getFactory()->create($data);
}

/**
* Get the cast & crew information about a TV series.
*
* Just like the website, we pull this information from the last season of the series.
*
* @param $id
* @param $parameters
* @param $headers
* @return null|\Tmdb\Model\AbstractModel
*/
public function getCredits($id, array $parameters = array(), array $headers = array())
{
$data = $this->getApi()->getCredits($id, $this->parseQueryParameters($parameters), $headers);
$tv = $this->getFactory()->create(array('credits' => $data));

return $tv->getCredits();
}

/**
* Get the external ids that we have stored for a TV series.
*
* @param $id
* @param $parameters
* @param $headers
* @return null|\Tmdb\Model\AbstractModel
*/
public function getExternalIds($id, array $parameters = array(), array $headers = array())
{
$data = $this->getApi()->getExternalIds($id, $this->parseQueryParameters($parameters), $headers);
$tv = $this->getFactory()->create(array('external_ids' => $data));

return $tv->getExternalIds();
}

/**
* Get the images (posters and backdrops) for a TV series.
*
* @param $id
* @param $parameters
* @param $headers
* @return null|\Tmdb\Model\AbstractModel
*/
public function getImages($id, array $parameters = array(), array $headers = array())
{
$data = $this->getApi()->getImages($id, $this->parseQueryParameters($parameters), $headers);
$tv = $this->getFactory()->create(array('images' => $data));

return $tv->getImages();
}

/**
* Get the list of translations that exist for a TV series.
*
* These translations cascade down to the episode level.
*
* @param $id
* @param $parameters
* @param $headers
* @return null|\Tmdb\Model\AbstractModel
*/
public function getTranslations($id, array $parameters = array(), array $headers = array())
{
$data = $this->getApi()->getTranslations($id, $this->parseQueryParameters($parameters), $headers);
$tv = $this->getFactory()->create(array('translations' => $data));

return $tv->getTranslations();
}

/**
* Return the Tvs API Class
*
Expand All @@ -74,7 +141,7 @@ public function getFactory()
*/
public function getPopular(array $options = array())
{
return $this->createCollection(
return $this->getFactory()->createResultCollection(
$this->getApi()->getPopular($options)
);
}
Expand All @@ -87,7 +154,20 @@ public function getPopular(array $options = array())
*/
public function getTopRated(array $options = array())
{
return $this->createCollection(
return $this->getFactory()->createResultCollection(
$this->getApi()->getTopRated($options)
);
}

/**
* Get the list of top rated tvs. By default, this list will only include tvs that have 10 or more votes. This list refreshes every day.
*
* @param array $options
* @return Tv[]
*/
public function getOnTheAir(array $options = array())
{
return $this->getFactory()->createResultCollection(
$this->getApi()->getTopRated($options)
);
}
Expand Down

0 comments on commit 9586dc6

Please sign in to comment.