diff --git a/examples/phpunit b/examples/phpunit new file mode 120000 index 00000000..0219a5d4 --- /dev/null +++ b/examples/phpunit @@ -0,0 +1 @@ +../phpunit \ No newline at end of file diff --git a/lib/Tmdb/Api/Find.php b/lib/Tmdb/Api/Find.php index cbbb5cf4..83d0af0f 100644 --- a/lib/Tmdb/Api/Find.php +++ b/lib/Tmdb/Api/Find.php @@ -16,14 +16,25 @@ class Find extends AbstractApi { /** - * Get a list of valid jobs. + * The find method makes it easy to search for objects in our database by an external id. For instance, an IMDB ID. This will search all objects (movies, TV shows and people) and return the results in a single response. TV season and TV episode searches will be supported shortly. * + * The supported external sources for each object are as follows: + * + * Movies: imdb_id + * People: imdb_id, freebase_mid, freebase_id, tvrage_id + * TV Series: imdb_id, freebase_mid, freebase_id, tvdb_id, tvrage_id + * + * @param string $id * @param array $parameters * @param array $headers * @return mixed */ - public function getJobs(array $parameters = array(), array $headers = array()) + public function find($id, array $parameters = array(), array $headers = array()) { - return $this->get('job/list', $parameters, $headers); + return $this->get( + sprintf('find/%s', $id), + $parameters, + $headers + ); } } diff --git a/lib/Tmdb/Client.php b/lib/Tmdb/Client.php index 6ffe7ce4..18507e24 100644 --- a/lib/Tmdb/Client.php +++ b/lib/Tmdb/Client.php @@ -131,6 +131,14 @@ public function getCollectionsApi() return new Api\Collections($this); } + /** + * @return Api\Find + */ + public function getFindApi() + { + return new Api\Find($this); + } + /** * @return Api\Movies */ diff --git a/lib/Tmdb/Factory/FindFactory.php b/lib/Tmdb/Factory/FindFactory.php new file mode 100644 index 00000000..ccc20111 --- /dev/null +++ b/lib/Tmdb/Factory/FindFactory.php @@ -0,0 +1,130 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Factory; + +use Tmdb\Model\Common\GenericCollection; +use Tmdb\Model\Find; + +class FindFactory extends AbstractFactory +{ + /** + * @var MovieFactory + */ + private $movieFactory; + + /** + * @var PeopleFactory + */ + private $peopleFactory; + + /** + * @var TvFactory + */ + private $tvFactory; + + /** + * Constructor + */ + public function __construct() + { + $this->movieFactory = new MovieFactory(); + $this->peopleFactory = new PeopleFactory(); + $this->tvFactory = new TvFactory(); + } + + /** + * {@inheritdoc} + */ + public function create(array $data = array()) + { + $find = new Find(); + + if (array_key_exists('movie_results', $data)) { + $find->setMovieResults($this->getMovieFactory()->createCollection($data['movie_results'])); + } + + if (array_key_exists('person_results', $data)) { + $find->setPersonResults($this->getPeopleFactory()->createCollection($data['person_results'])); + } + + if (array_key_exists('tv_results', $data)) { + $find->setTvResults($this->getTvFactory()->createCollection($data['tv_results'])); + } + + return $find; + } + + /** + * {@inheritdoc} + */ + public function createCollection(array $data = array()) + { + return array(); + } + + /** + * @param \Tmdb\Factory\MovieFactory $movieFactory + * @return $this + */ + public function setMovieFactory($movieFactory) + { + $this->movieFactory = $movieFactory; + return $this; + } + + /** + * @return \Tmdb\Factory\MovieFactory + */ + public function getMovieFactory() + { + return $this->movieFactory; + } + + /** + * @param \Tmdb\Factory\PeopleFactory $peopleFactory + * @return $this + */ + public function setPeopleFactory($peopleFactory) + { + $this->peopleFactory = $peopleFactory; + return $this; + } + + /** + * @return \Tmdb\Factory\PeopleFactory + */ + public function getPeopleFactory() + { + return $this->peopleFactory; + } + + /** + * @param \Tmdb\Factory\TvFactory $tvFactory + * @return $this + */ + public function setTvFactory($tvFactory) + { + $this->tvFactory = $tvFactory; + return $this; + } + + /** + * @return \Tmdb\Factory\TvFactory + */ + public function getTvFactory() + { + return $this->tvFactory; + } + + +} diff --git a/lib/Tmdb/Model/Find.php b/lib/Tmdb/Model/Find.php new file mode 100644 index 00000000..c0bb201e --- /dev/null +++ b/lib/Tmdb/Model/Find.php @@ -0,0 +1,90 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model; + +use Tmdb\Model\Collection\People; +use Tmdb\Model\Common\GenericCollection; + +class Find extends AbstractModel { + + /** + * @var GenericCollection + */ + private $movieResults; + + /** + * @var People + */ + private $personResults; + + /** + * @var GenericCollection + */ + private $tvResults; + + /** + * @param \Tmdb\Model\Common\GenericCollection $movieResults + * @return $this + */ + public function setMovieResults($movieResults) + { + $this->movieResults = $movieResults; + return $this; + } + + /** + * @return \Tmdb\Model\Common\GenericCollection + */ + public function getMovieResults() + { + return $this->movieResults; + } + + /** + * @param \Tmdb\Model\Collection\People $personResults + * @return $this + */ + public function setPersonResults($personResults) + { + $this->personResults = $personResults; + return $this; + } + + /** + * @return \Tmdb\Model\Collection\People + */ + public function getPersonResults() + { + return $this->personResults; + } + + /** + * @param \Tmdb\Model\Common\GenericCollection $tvResults + * @return $this + */ + public function setTvResults($tvResults) + { + $this->tvResults = $tvResults; + return $this; + } + + /** + * @return \Tmdb\Model\Common\GenericCollection + */ + public function getTvResults() + { + return $this->tvResults; + } + + +} diff --git a/lib/Tmdb/Repository/FindRepository.php b/lib/Tmdb/Repository/FindRepository.php index 156dd2d5..603cb5bd 100644 --- a/lib/Tmdb/Repository/FindRepository.php +++ b/lib/Tmdb/Repository/FindRepository.php @@ -13,12 +13,39 @@ namespace Tmdb\Repository; // @todo +use Tmdb\Factory\FindFactory; +use Tmdb\Model\Find; + class FindRepository extends AbstractRepository { + /** + * Find something + * + * @param $id + * @param array $parameters + * @param array $headers + * @return Find + */ + public function find($id, array $parameters = array(), array $headers = array()) { + return $this->getFactory()->create( + $this->getApi()->find($id,$parameters, $headers) + ); + } + + /** + * Return the related API class + * + * @return \Tmdb\Api\Find + */ public function getApi() { + return $this->getClient()->getFindApi(); } + /** + * @return FindFactory + */ public function getFactory() { + return new FindFactory(); } } \ No newline at end of file diff --git a/test/Tmdb/Tests/Factory/FindFactoryTest.php b/test/Tmdb/Tests/Factory/FindFactoryTest.php new file mode 100644 index 00000000..2eb50028 --- /dev/null +++ b/test/Tmdb/Tests/Factory/FindFactoryTest.php @@ -0,0 +1,54 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Tests\Factory; + +use Tmdb\Model\Find; + +class FindFactoryTest extends TestCase +{ + /** + * @test + */ + public function shouldConstructFind() + { + $factory = $this->getFactory(); + + /** + * @var Find $find + */ + $find = $factory->create(array( + 'movie_results' => array(array('id' => 1)), + 'person_results' => array(array('id' => 1)), + 'tv_results' => array(array('id' => 1)), + )); + + $this->assertInstanceOf('Tmdb\Model\Find', $find); + + foreach($find->getMovieResults() as $movie) { + $this->assertInstanceOf('Tmdb\Model\Movie', $movie); + } + + foreach($find->getPersonResults() as $person) { + $this->assertInstanceOf('Tmdb\Model\Person', $person); + } + + foreach($find->getTvResults() as $tv) { + $this->assertInstanceOf('Tmdb\Model\Tv', $tv); + } + } + + protected function getFactoryClass() + { + return 'Tmdb\Factory\FindFactory'; + } +} \ No newline at end of file diff --git a/test/Tmdb/Tests/Factory/GenreFactoryTest.php b/test/Tmdb/Tests/Factory/GenreFactoryTest.php index b07cab8f..64fa0ce4 100644 --- a/test/Tmdb/Tests/Factory/GenreFactoryTest.php +++ b/test/Tmdb/Tests/Factory/GenreFactoryTest.php @@ -38,6 +38,22 @@ public function shouldConstructGenres() } } + /** + * @test + */ + public function shouldFilter() + { + $factory = $this->getFactory(); + $data = $this->loadByFile('genre/result.json'); + + $collection = $factory->createCollection($data['genres']); + $filteredGenres = $collection->filterId(self::GENRE_ID); + + foreach($filteredGenres as $filteredGenre) { + $this->assertEquals('Action', $filteredGenre->getName()); + } + } + protected function getFactoryClass() { return 'Tmdb\Factory\GenreFactory'; diff --git a/test/Tmdb/Tests/Repository/FindRepositoryTest.php b/test/Tmdb/Tests/Repository/FindRepositoryTest.php index a654d742..cc71a8f9 100644 --- a/test/Tmdb/Tests/Repository/FindRepositoryTest.php +++ b/test/Tmdb/Tests/Repository/FindRepositoryTest.php @@ -12,9 +12,7 @@ */ namespace Tmdb\Tests\Repository; -use Tmdb\Model\Query\ChangesQuery; - -class ChangesRepositoryTest extends TestCase +class FindRepositoryTest extends TestCase { /** * @test @@ -23,18 +21,16 @@ public function shouldGetMovieChanges() { $repository = $this->getRepositoryWithMockedHttpClient(); - $query = new ChangesQuery(); - - $repository->getMovieChanges($query); + $repository->find('tt2345737'); } protected function getApiClass() { - return 'Tmdb\Api\Changes'; + return 'Tmdb\Api\FindApi'; } protected function getRepositoryClass() { - return 'Tmdb\Repository\ChangesRepository'; + return 'Tmdb\Repository\FindRepository'; } } \ No newline at end of file