Skip to content

Commit

Permalink
Expanding the API
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfzdotnet committed Jan 12, 2014
1 parent 2c6d85b commit 5bb3e2f
Show file tree
Hide file tree
Showing 40 changed files with 2,639 additions and 139 deletions.
4 changes: 3 additions & 1 deletion examples/people/model/get.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@
$token = new \Tmdb\ApiToken(TMDB_API_KEY);
$client = new \Tmdb\Client($token);

$person = \Tmdb\Model\Person::load($client, 287, array('append_to_response' => 'images'));
$peopleRepository = \Tmdb\Repository\PeopleRepository($client);

var_dump($person);
22 changes: 22 additions & 0 deletions examples/tv/model/episode.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\TvEpisodeRepository($client);
$episode = $repository->load(1396, 2, 1);

var_dump($episode);
22 changes: 22 additions & 0 deletions examples/tv/model/season.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\TvSeasonRepository($client);
$season = $repository->load(1396, 2);

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

printf('<h1>%s</h1>', $tvShow->getName());

var_dump($tvShow);
31 changes: 30 additions & 1 deletion lib/Tmdb/Api/Tv.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public function getTvshow($tvshow_id, array $options = array(), array $headers =
}

/**
* Get the cast & crew information about a TV series. Just like the website, we pull this information from the last season of the series.
* 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 $tvshow_id
* @param array $options
Expand Down Expand Up @@ -66,4 +67,32 @@ public function getImages($tvshow_id, array $options = array(), array $headers =
{
return $this->get('tv/' . $tvshow_id . '/images', $options, $headers);
}

/**
* Get the list of popular TV shows. This list refreshes every day.
*
* @param array $options
* @param array $headers
* @return mixed
*/
public function getPopular(array $options = array(), array $headers = array())
{
return $this->get('tv/popular', $options, $headers);
}

/**
* Get the list of top rated TV shows.
*
* By default, this list will only include TV shows that have 2 or more votes.
* This list refreshes every day.
*
* @param array $options
* @param array $headers
* @return mixed
*/
public function getTopRated(array $options = array(), array $headers = array())
{
return $this->get('tv/top_rated', $options, $headers);
}

}
2 changes: 0 additions & 2 deletions lib/Tmdb/Api/TvEpisode.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
*/
namespace Tmdb\Api;

use Tmdb\Exception\NotImplementedException;

class TvEpisode
extends AbstractApi
{
Expand Down
41 changes: 41 additions & 0 deletions lib/Tmdb/Factory/CompanyFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?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
*/
namespace Tmdb\Factory;

use Tmdb\Model\Common\Collection;
use Tmdb\Model\Company;

class CompanyFactory extends AbstractFactory
{
/**
* {@inheritdoc}
*/
public static function create(array $data = array())
{
return parent::hydrate(new Company(), $data);
}

/**
* {@inheritdoc}
*/
public static function createCollection(array $data = array())
{
$collection = new Collection();

foreach($data as $item) {
$collection->add(null, self::create($item));
}

return $collection;
}
}
24 changes: 24 additions & 0 deletions lib/Tmdb/Factory/ImageFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,30 @@ public static function createCollectionFromMovie(array $data = array())
return self::createImageCollection($data);
}

/**
* {@inheritdoc}
*/
public static function createCollectionFromTv(array $data = array())
{
return self::createImageCollection($data);
}

/**
* {@inheritdoc}
*/
public static function createCollectionFromTvSeason(array $data = array())
{
return self::createImageCollection($data);
}

/**
* {@inheritdoc}
*/
public static function createCollectionFromTvEpisode(array $data = array())
{
return self::createImageCollection($data);
}

/**
* {@inheritdoc}
*/
Expand Down
3 changes: 2 additions & 1 deletion lib/Tmdb/Factory/MovieFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Tmdb\Factory\People\CrewFactory;
use Tmdb\Model\Common\Collection;
use Tmdb\Model\Common\Trailer\Youtube;
use Tmdb\Model\Common\Translation;
use Tmdb\Model\Movie;

class MovieFactory extends AbstractFactory {
Expand Down Expand Up @@ -74,7 +75,7 @@ public static function create(array $data = array())
}

if (array_key_exists('translations', $data)) {
$movie->setTranslations(GenericCollectionFactory::createCollection($data['translations']['translations'], new Movie\Translation()));
$movie->setTranslations(GenericCollectionFactory::createCollection($data['translations']['translations'], new Translation()));
}

if (array_key_exists('similar_movies', $data)) {
Expand Down
8 changes: 4 additions & 4 deletions lib/Tmdb/Factory/People/CastFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ class CastFactory extends PeopleFactory
/**
* {@inheritdoc}
*/
public static function create(array $data = array())
public static function create(array $data = array(), $person = null)
{
return parent::create($data);
return parent::create($data, $person);
}

/**
* {@inheritdoc}
*/
public static function createCollection(array $data = array())
public static function createCollection(array $data = array(), $person = null)
{
$collection = new Cast();

foreach($data as $item) {
$collection->add(null, parent::create($item));
$collection->add(null, parent::create($item, $person));
}

return $collection;
Expand Down
8 changes: 4 additions & 4 deletions lib/Tmdb/Factory/People/CrewFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ class CrewFactory extends PeopleFactory
/**
* {@inheritdoc}
*/
public static function create(array $data = array())
public static function create(array $data = array(), $person = null)
{
return parent::create($data);
return parent::create($data, $person);
}

/**
* {@inheritdoc}
*/
public static function createCollection(array $data = array())
public static function createCollection(array $data = array(), $person = null)
{
$collection = new Crew();

foreach($data as $item) {
$collection->add(null, parent::create($item));
$collection->add(null, parent::create($item, $person));
}

return $collection;
Expand Down
30 changes: 15 additions & 15 deletions lib/Tmdb/Factory/People/PeopleFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,31 @@
namespace Tmdb\Factory\People;

use Tmdb\Factory\AbstractFactory;
use Tmdb\Factory\ImageFactory;

use Tmdb\Model\Common\Collection;
use Tmdb\Model\Person\CastMember;
use Tmdb\Model\Person\CrewMember;
use Tmdb\Model\Person;

use Tmdb\Factory\Common\ImageFactory;

class PeopleFactory extends AbstractFactory {
/**
* {@inheritdoc}
*/
public static function create(array $data = array())
public static function create(array $data = array(), Person\AbstractMember $person = null)
{
$person = null;
if (!is_object($person)) {
if (array_key_exists('character', $data)) {
$person = new CastMember();
}

if (array_key_exists('character', $data)) {
$person = new CastMember();
}

if (array_key_exists('job', $data)) {
$person = new CrewMember();
}
if (array_key_exists('job', $data)) {
$person = new CrewMember();
}

if (null === $person) {
$person = new Person();
if (null === $person) {
$person = new Person();
}
}

/** Images */
Expand All @@ -51,12 +51,12 @@ public static function create(array $data = array())
/**
* {@inheritdoc}
*/
public static function createCollection(array $data = array())
public static function createCollection(array $data = array(), Person\AbstractMember $person = null)
{
$collection = new Collection();

foreach($data as $item) {
$collection->add(null, self::create($item));
$collection->add(null, self::create($item, $person));
}

return $collection;
Expand Down
Loading

0 comments on commit 5bb3e2f

Please sign in to comment.