diff --git a/README.md b/README.md index 982f91a8..6e5fed3f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ A PHP Wrapper for use with the [TMDB API](http://http://docs.themoviedb.apiary.i --------------- [![Build Status Develop Branch](https://travis-ci.org/wtfzdotnet/php-tmdb-api.png?branch=develop)](https://travis-ci.org/wtfzdotnet/php-tmdb-api) [![Code Coverage](https://scrutinizer-ci.com/g/wtfzdotnet/php-tmdb-api/badges/coverage.png?s=d416e063debb3b400e9b1bc9db019f54cc1dc40e)](https://scrutinizer-ci.com/g/wtfzdotnet/php-tmdb-api/) -[![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/wtfzdotnet/php-tmdb-api/badges/quality-score.png?s=dad36710f36335bdeffeaf2ac256c222862832fa)](https://scrutinizer-ci.com/g/wtfzdotnet/php-tmdb-api/) [![License](https://poser.pugx.org/wtfzdotnet/php-tmdb-api/license.png)](https://packagist.org/packages/wtfzdotnet/php-tmdb-api) Inspired by [php-github-api](https://github.com/KnpLabs/php-github-api), [php-gitlab-api](https://github.com/m4tthumphrey/php-gitlab-api/) and the Symfony2 Community. diff --git a/examples/changes/api/tv.php b/examples/changes/api/tv.php new file mode 100644 index 00000000..2b78da03 --- /dev/null +++ b/examples/changes/api/tv.php @@ -0,0 +1,25 @@ + + * @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); + +$tvChanges = $client->getChangesApi()->getTvChanges(array( + 'page' => 1, + 'start_date' => '2014-01-14', + 'end_date' => '2014-01-21' +)); + +var_dump($tvChanges); diff --git a/examples/changes/model/tv.php b/examples/changes/model/tv.php new file mode 100644 index 00000000..095da352 --- /dev/null +++ b/examples/changes/model/tv.php @@ -0,0 +1,33 @@ + + * @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); + +$query = new \Tmdb\Model\Query\ChangesQuery(); + +$from = new \DateTime('14-01-2014'); +$to = new \DateTime('21-01-2014'); + +$query + ->page(1) + ->from($from) + ->to($to) +; + +$repository = new \Tmdb\Repository\ChangesRepository($client); +$response = $repository->getTvChanges($query); + +var_dump($response); diff --git a/examples/people/model/tagged_images.php b/examples/people/model/tagged_images.php index a92cfac5..fda56bc4 100644 --- a/examples/people/model/tagged_images.php +++ b/examples/people/model/tagged_images.php @@ -10,6 +10,8 @@ * @copyright (c) 2013, Michael Roterman * @version 0.0.1 */ +ini_set('display_errors', 'On'); + require_once '../../../vendor/autoload.php'; require_once '../../../apikey.php'; diff --git a/examples/search/api/multi.php b/examples/search/api/multi.php new file mode 100644 index 00000000..60b0b40c --- /dev/null +++ b/examples/search/api/multi.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->getSearchApi()->searchMulti('jack'); + +var_dump($result); diff --git a/examples/search/model/multi.php b/examples/search/model/multi.php new file mode 100644 index 00000000..9d7e7099 --- /dev/null +++ b/examples/search/model/multi.php @@ -0,0 +1,26 @@ + + * @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); + +$query = new \Tmdb\Model\Search\SearchQuery\KeywordSearchQuery(); +$query->page(1); + +$repository = new \Tmdb\Repository\SearchRepository($client); + +$find = $repository->searchMulti('jack', $query); + +var_dump($find); diff --git a/examples/tv/api/episode/account_states.php b/examples/tv/api/episode/account_states.php new file mode 100644 index 00000000..3fac86b5 --- /dev/null +++ b/examples/tv/api/episode/account_states.php @@ -0,0 +1,24 @@ + + * @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); + +$sessionToken = new \Tmdb\SessionToken(TMDB_SESSION_TOKEN); +$client->setSessionToken($sessionToken); + +$result = $client->getTvEpisodeApi()->getAccountStates(1396, 1, 1); + +var_dump($result); diff --git a/examples/tv/api/episode/rate.php b/examples/tv/api/episode/rate.php new file mode 100644 index 00000000..6f4e40aa --- /dev/null +++ b/examples/tv/api/episode/rate.php @@ -0,0 +1,25 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +ini_set('display_errors', 'On'); +require_once '../../../../vendor/autoload.php'; +require_once '../../../../apikey.php'; + +$token = new \Tmdb\ApiToken(TMDB_API_KEY); +$client = new \Tmdb\Client($token); + +$sessionToken = new \Tmdb\SessionToken(TMDB_SESSION_TOKEN); +$client->setSessionToken($sessionToken); + +$result = $client->getTvEpisodeApi()->rateTvEpisode(1396, 1, 1, 9.5); + +var_dump($result); diff --git a/examples/tv/api/tv/account_states.php b/examples/tv/api/tv/account_states.php new file mode 100644 index 00000000..6f04d0c0 --- /dev/null +++ b/examples/tv/api/tv/account_states.php @@ -0,0 +1,24 @@ + + * @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); + +$sessionToken = new \Tmdb\SessionToken(TMDB_SESSION_TOKEN); +$client->setSessionToken($sessionToken); + +$result = $client->getTvApi()->getAccountStates(1396); + +var_dump($result); diff --git a/examples/tv/api/tv/rate.php b/examples/tv/api/tv/rate.php new file mode 100644 index 00000000..04fe97d7 --- /dev/null +++ b/examples/tv/api/tv/rate.php @@ -0,0 +1,25 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +ini_set('display_errors', 'On'); +require_once '../../../../vendor/autoload.php'; +require_once '../../../../apikey.php'; + +$token = new \Tmdb\ApiToken(TMDB_API_KEY); +$client = new \Tmdb\Client($token); + +$sessionToken = new \Tmdb\SessionToken(TMDB_SESSION_TOKEN); +$client->setSessionToken($sessionToken); + +$result = $client->getTvApi()->rateTvShow(1396, 9.5); + +var_dump($result); diff --git a/examples/tv/model/episode/account_states.php b/examples/tv/model/episode/account_states.php new file mode 100644 index 00000000..600d3636 --- /dev/null +++ b/examples/tv/model/episode/account_states.php @@ -0,0 +1,25 @@ + + * @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); + +$sessionToken = new \Tmdb\SessionToken(TMDB_SESSION_TOKEN); +$client->setSessionToken($sessionToken); + +$repository = new \Tmdb\Repository\TvEpisodeRepository($client); +$tvShow = $repository->getAccountStates(1396, 1, 1); + +var_dump($tvShow); diff --git a/examples/tv/model/episode/rate.php b/examples/tv/model/episode/rate.php new file mode 100644 index 00000000..2b55f280 --- /dev/null +++ b/examples/tv/model/episode/rate.php @@ -0,0 +1,26 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +ini_set('display_errors','on'); +require_once '../../../../vendor/autoload.php'; +require_once '../../../../apikey.php'; + +$token = new \Tmdb\ApiToken(TMDB_API_KEY); +$client = new \Tmdb\Client($token); + +$sessionToken = new \Tmdb\SessionToken(TMDB_SESSION_TOKEN); +$client->setSessionToken($sessionToken); + +$repository = new \Tmdb\Repository\TvEpisodeRepository($client); +$rate = $repository->rate(1396, 1, 1, 9.5); + +var_dump($rate); diff --git a/examples/tv/model/tv/account_states.php b/examples/tv/model/tv/account_states.php new file mode 100644 index 00000000..25b56a67 --- /dev/null +++ b/examples/tv/model/tv/account_states.php @@ -0,0 +1,25 @@ + + * @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); + +$sessionToken = new \Tmdb\SessionToken(TMDB_SESSION_TOKEN); +$client->setSessionToken($sessionToken); + +$repository = new \Tmdb\Repository\TvRepository($client); +$tvShow = $repository->getAccountStates(1396); + +var_dump($tvShow); diff --git a/examples/tv/model/tv/rate.php b/examples/tv/model/tv/rate.php new file mode 100644 index 00000000..b30060d0 --- /dev/null +++ b/examples/tv/model/tv/rate.php @@ -0,0 +1,26 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +ini_set('display_errors','on'); +require_once '../../../../vendor/autoload.php'; +require_once '../../../../apikey.php'; + +$token = new \Tmdb\ApiToken(TMDB_API_KEY); +$client = new \Tmdb\Client($token); + +$sessionToken = new \Tmdb\SessionToken(TMDB_SESSION_TOKEN); +$client->setSessionToken($sessionToken); + +$repository = new \Tmdb\Repository\TvRepository($client); +$rate = $repository->rate(1396, 9.5); + +var_dump($rate); diff --git a/lib/Tmdb/Api/AbstractApi.php b/lib/Tmdb/Api/AbstractApi.php index 4e75af21..49c961bf 100644 --- a/lib/Tmdb/Api/AbstractApi.php +++ b/lib/Tmdb/Api/AbstractApi.php @@ -77,10 +77,10 @@ public function head($path, array $parameters = array(), $headers = array()) /** * Send a POST request * - * @param $path - * @param null $postBody - * @param array $parameters - * @param array $headers + * @param string $path + * @param null $postBody + * @param array $parameters + * @param array $headers * @return mixed */ public function post($path, $postBody = null, array $parameters = array(), $headers = array()) @@ -96,10 +96,10 @@ public function post($path, $postBody = null, array $parameters = array(), $head /** * Send a POST request but json_encode the post body in the request * - * @param $path - * @param null $postBody - * @param array $parameters - * @param array $headers + * @param string $path + * @param array|null $postBody + * @param array $parameters + * @param array $headers * @return mixed */ public function postJson($path, $postBody = null, array $parameters = array(), $headers = array()) @@ -138,10 +138,10 @@ public function put($path, $body = null, array $parameters = array(), $headers = /** * Send a DELETE request * - * @param $path - * @param null $body - * @param array $parameters - * @param array $headers + * @param string $path + * @param null $body + * @param array $parameters + * @param array $headers * @return mixed */ public function delete($path, $body = null, array $parameters = array(), $headers = array()) diff --git a/lib/Tmdb/Api/Authentication.php b/lib/Tmdb/Api/Authentication.php index 2078326d..c697e208 100644 --- a/lib/Tmdb/Api/Authentication.php +++ b/lib/Tmdb/Api/Authentication.php @@ -41,7 +41,7 @@ public function getNewToken() /** * Redirect the user to authenticate the request token * - * @param $token + * @param string $token */ public function authenticateRequestToken($token) { @@ -83,9 +83,9 @@ public function getNewSession($requestToken) /** * Helper method to validate the request_token and obtain a session_token * - * @param $requestToken - * @param $username - * @param $password + * @param RequestToken $requestToken + * @param string $username + * @param string $password * @return mixed * @throws \InvalidArgumentException */ diff --git a/lib/Tmdb/Api/Changes.php b/lib/Tmdb/Api/Changes.php index 084d5926..f16dfc19 100644 --- a/lib/Tmdb/Api/Changes.php +++ b/lib/Tmdb/Api/Changes.php @@ -58,4 +58,24 @@ public function getPersonChanges(array $parameters = array(), array $headers = a { return $this->get('person/changes', $parameters, $headers); } + + /** + * Get a list of tv show ids that have been edited. + * + * By default we show the last 24 hours and only 100 items per page. + * The maximum number of days that can be returned in a single request is 14. + * + * You can then use the tv changes API to get the actual data that has been changed. + * + * Please note that the change log system to support this was changed + * on May 13, 2014 and will only show tv shows that have been edited since. + * + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getTvChanges(array $parameters = array(), array $headers = array()) + { + return $this->get('tv/changes', $parameters, $headers); + } } diff --git a/lib/Tmdb/Api/Lists.php b/lib/Tmdb/Api/Lists.php index a36889db..b1345623 100644 --- a/lib/Tmdb/Api/Lists.php +++ b/lib/Tmdb/Api/Lists.php @@ -22,9 +22,9 @@ class Lists extends AbstractApi /** * Get a list by id. * - * @param $list_id - * @param array $parameters - * @param array $headers + * @param string $list_id + * @param array $parameters + * @param array $headers * @return mixed */ public function getList($list_id, array $parameters = array(), array $headers = array()) diff --git a/lib/Tmdb/Api/Movies.php b/lib/Tmdb/Api/Movies.php index 35998601..fd76f65c 100644 --- a/lib/Tmdb/Api/Movies.php +++ b/lib/Tmdb/Api/Movies.php @@ -261,7 +261,8 @@ public function getTopRated(array $parameters = array(), array $headers = array( * * A valid session id is required. * - * @throws \Tmdb\Exception\NotImplementedException + * @param integer $id + * @return mixed */ public function getAccountStates($id) { @@ -273,7 +274,9 @@ public function getAccountStates($id) * * A valid session id or guest session id is required. * - * @throws \Tmdb\Exception\NotImplementedException + * @param integer $id + * @param double $rating + * @return mixed */ public function rateMovie($id, $rating) { diff --git a/lib/Tmdb/Api/People.php b/lib/Tmdb/Api/People.php index b9457cee..513a92bb 100644 --- a/lib/Tmdb/Api/People.php +++ b/lib/Tmdb/Api/People.php @@ -144,8 +144,6 @@ public function getExternalIds($person_id, array $parameters = array(), array $h * @param array $parameters * @param array $headers * @return mixed - * - * @todo Still does not contain the media and media_type properties, this will be worked on later on. */ public function getTaggedImages($person_id, array $parameters = array(), array $headers = array()) { diff --git a/lib/Tmdb/Api/Search.php b/lib/Tmdb/Api/Search.php index 8e5f1f1b..9e605d49 100644 --- a/lib/Tmdb/Api/Search.php +++ b/lib/Tmdb/Api/Search.php @@ -22,9 +22,9 @@ class Search extends AbstractApi /** * Search for movies by title. * - * @param $query - * @param array $parameters - * @param array $headers + * @param string $query + * @param array $parameters + * @param array $headers * @return mixed */ public function searchMovies($query, array $parameters = array(), array $headers = array()) @@ -37,9 +37,9 @@ public function searchMovies($query, array $parameters = array(), array $headers /** * Search for collections by name. * - * @param $query - * @param array $parameters - * @param array $headers + * @param string $query + * @param array $parameters + * @param array $headers * @return mixed */ public function searchCollection($query, array $parameters = array(), array $headers = array()) @@ -52,9 +52,9 @@ public function searchCollection($query, array $parameters = array(), array $hea /** * Search for TV shows by title. * - * @param $query - * @param array $parameters - * @param array $headers + * @param string $query + * @param array $parameters + * @param array $headers * @return mixed */ public function searchTv($query, array $parameters = array(), array $headers = array()) @@ -67,9 +67,9 @@ public function searchTv($query, array $parameters = array(), array $headers = a /** * Search for people by name. * - * @param $query - * @param array $parameters - * @param array $headers + * @param string $query + * @param array $parameters + * @param array $headers * @return mixed */ public function searchPersons($query, array $parameters = array(), array $headers = array()) @@ -82,9 +82,9 @@ public function searchPersons($query, array $parameters = array(), array $header /** * Search for lists by name and description. * - * @param $query - * @param array $parameters - * @param array $headers + * @param string $query + * @param array $parameters + * @param array $headers * @return mixed */ public function searchList($query, array $parameters = array(), array $headers = array()) @@ -112,9 +112,9 @@ public function searchCompany($query, array $parameters = array(), array $header /** * Search for companies by name. * - * @param $query - * @param array $parameters - * @param array $headers + * @param string $query + * @param array $parameters + * @param array $headers * @return mixed */ public function searchKeyword($query, array $parameters = array(), array $headers = array()) @@ -123,4 +123,22 @@ public function searchKeyword($query, array $parameters = array(), array $header 'query' => urlencode($query) ), $headers)); } + + /** + * Search the movie, tv show and person collections with a single query. + * + * Each item returned in the result array has a media_type field that maps to either movie, tv or person. + * Each mapped result is the same response you would get from each independent search. + * + * @param string $query + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function searchMulti($query, array $parameters = array(), array $headers = array()) + { + return $this->get('search/multi', array_merge($parameters, array( + 'query' => urlencode($query) + ), $headers)); + } } diff --git a/lib/Tmdb/Api/Tv.php b/lib/Tmdb/Api/Tv.php index af809291..8290d637 100644 --- a/lib/Tmdb/Api/Tv.php +++ b/lib/Tmdb/Api/Tv.php @@ -216,4 +216,32 @@ public function getSimilar($tvshow_id, array $parameters = array(), array $heade { return $this->get('tv/' . $tvshow_id . '/similar', $parameters, $headers); } + + /** + * This method lets users get the status of whether or not the TV show has been rated + * or added to their favourite or watch lists. + * + * A valid session id is required. + * + * @param integer $id + * @return mixed + */ + public function getAccountStates($id) + { + return $this->get('tv/' . $id . '/account_states'); + } + + /** + * This method lets users rate a TV show. + * + * A valid session id or guest session id is required. + * + * @param integer $id + * @param double $rating + * @return mixed + */ + public function rateTvShow($id, $rating) + { + return $this->postJson('tv/' . $id . '/rating', array('value' => (float) $rating)); + } } diff --git a/lib/Tmdb/Api/TvEpisode.php b/lib/Tmdb/Api/TvEpisode.php index 262f6007..fb27a400 100644 --- a/lib/Tmdb/Api/TvEpisode.php +++ b/lib/Tmdb/Api/TvEpisode.php @@ -196,4 +196,59 @@ public function getChanges( ); } + /** + * This method lets users get the status of whether or not the TV episode has been rated. + * + * A valid session id is required. + * + * @param $tvshow_id + * @param $season_number + * @param $episode_number + * + * @return mixed + */ + public function getAccountStates( + $tvshow_id, + $season_number, + $episode_number + ) { + return $this->get( + sprintf( + 'tv/%s/season/%s/episode/%s/account_states', + $tvshow_id, + $season_number, + $episode_number + ) + ); + } + + /** + * This method lets users rate a TV episode. + * + * A valid session id or guest session id is required. + * + * @param $tvshow_id + * @param $season_number + * @param $episode_number + * @param double $rating + * + * @return mixed + */ + public function rateTvEpisode( + $tvshow_id, + $season_number, + $episode_number, + $rating + ) { + return $this->postJson( + sprintf( + 'tv/%s/season/%s/episode/%s/rating', + $tvshow_id, + $season_number, + $episode_number + ), + array('value' => (float) $rating) + ); + } + } diff --git a/lib/Tmdb/ApiToken.php b/lib/Tmdb/ApiToken.php index c79e4760..8e93ab55 100644 --- a/lib/Tmdb/ApiToken.php +++ b/lib/Tmdb/ApiToken.php @@ -48,7 +48,7 @@ public function setToken($apiToken) } /** - * @return null + * @return string */ public function getToken() { diff --git a/lib/Tmdb/Factory/AbstractFactory.php b/lib/Tmdb/Factory/AbstractFactory.php index 169c4c73..fa21a6f0 100644 --- a/lib/Tmdb/Factory/AbstractFactory.php +++ b/lib/Tmdb/Factory/AbstractFactory.php @@ -15,7 +15,10 @@ use Tmdb\Common\ObjectHydrator; use Tmdb\Model\AbstractModel; use Tmdb\Model\Collection\ResultCollection; +use Tmdb\Model\Common\AccountStates; use Tmdb\Model\Common\GenericCollection; +use Tmdb\Model\Common\Rating; +use Tmdb\Model\Lists\Result; /** * Class AbstractFactory @@ -103,6 +106,76 @@ public function createResultCollection($data = array(), $method = 'create') return $collection; } + /** + * Create a generic collection of data and map it on the class by it's static parameter $properties + * + * @param array $data + * @param AbstractModel $class + * @param GenericCollection $collection + * @return GenericCollection + */ + protected function createCustomCollection($data = array(), $class, $collection) + { + if (is_object($class)) { + $class = get_class($class); + } + + if (null === $data) { + return $collection; + } + + foreach ($data as $item) { + $collection->add(null, $this->hydrate(new $class(), $item)); + } + + return $collection; + } + + /** + * Create rating + * + * @param array $data + * @return \Tmdb\Model\AbstractModel + */ + public function createRating(array $data = array()) + { + return $this->hydrate(new Rating(), $data); + } + + /** + * Create the account states + * + * @param array $data + * @return \Tmdb\Model\AbstractModel + */ + public function createAccountStates(array $data = array()) + { + $accountStates = new AccountStates(); + + if (array_key_exists('rated', $data)) { + if ($data['rated']) { + $rating = new Rating(); + + $accountStates->setRated($this->hydrate($rating, $data['rated'])); + } else { + $accountStates->setRated(false); + } + } + + return $this->hydrate($accountStates, $data); + } + + /** + * Create result + * + * @param array $data + * @return \Tmdb\Model\AbstractModel + */ + public function createResult(array $data = array()) + { + return $this->hydrate(new Result(), $data); + } + /** * Hydrate the object with data * diff --git a/lib/Tmdb/Factory/AccountFactory.php b/lib/Tmdb/Factory/AccountFactory.php index 074e4f12..3b9107cd 100644 --- a/lib/Tmdb/Factory/AccountFactory.php +++ b/lib/Tmdb/Factory/AccountFactory.php @@ -12,7 +12,6 @@ */ namespace Tmdb\Factory; -use Tmdb\Exception\NotImplementedException; use Tmdb\Model\Account; use Tmdb\Model\Lists\Result; @@ -108,7 +107,11 @@ public function createListItem(array $data = array()) */ public function createCollection(array $data = array()) { - throw new NotImplementedException('Not implemented'); + throw new \RuntimeException(sprintf( + 'Class "%s" does not support method "%s".', + __CLASS__, + __METHOD__ + )); } /** diff --git a/lib/Tmdb/Factory/AuthenticationFactory.php b/lib/Tmdb/Factory/AuthenticationFactory.php index f14f7ba0..81eefacd 100644 --- a/lib/Tmdb/Factory/AuthenticationFactory.php +++ b/lib/Tmdb/Factory/AuthenticationFactory.php @@ -12,7 +12,6 @@ */ namespace Tmdb\Factory; -use Tmdb\Exception\NotImplementedException; use Tmdb\GuestSessionToken; use Tmdb\RequestToken; use Tmdb\SessionToken; @@ -26,23 +25,31 @@ class AuthenticationFactory extends AbstractFactory /** * @param array $data * - * @throws NotImplementedException + * @throws \RuntimeException * @return void */ public function create(array $data = array()) { - throw new NotImplementedException(); + throw new \RuntimeException(sprintf( + 'Class "%s" does not support method "%s".', + __CLASS__, + __METHOD__ + )); } /** * @param array $data * - * @throws NotImplementedException + * @throws \RuntimeException * @return void */ public function createCollection(array $data = array()) { - throw new NotImplementedException(); + throw new \RuntimeException(sprintf( + 'Class "%s" does not support method "%s".', + __CLASS__, + __METHOD__ + )); } /** diff --git a/lib/Tmdb/Factory/Common/VideoFactory.php b/lib/Tmdb/Factory/Common/VideoFactory.php index 521dccaa..24098372 100644 --- a/lib/Tmdb/Factory/Common/VideoFactory.php +++ b/lib/Tmdb/Factory/Common/VideoFactory.php @@ -29,7 +29,7 @@ public function create(array $data = array()) { $videoType = $this->resolveVideoType($data); - return $this->hydrate($videoType, $data); + return (null === $videoType) ? null : $this->hydrate($videoType, $data); } /** diff --git a/lib/Tmdb/Factory/CreditsFactory.php b/lib/Tmdb/Factory/CreditsFactory.php index ac6c129d..0b08bb57 100644 --- a/lib/Tmdb/Factory/CreditsFactory.php +++ b/lib/Tmdb/Factory/CreditsFactory.php @@ -15,6 +15,7 @@ use Tmdb\Exception\NotImplementedException; use Tmdb\Model\Genre; use Tmdb\Model\Credits as Credits; +use Tmdb\Model\Person; /** * Class CreditsFactory @@ -71,9 +72,11 @@ public function create(array $data = array()) } if (array_key_exists('person', $data)) { - $credits->setPerson( - $this->getPeopleFactory()->create($data['person']) - ); + $person = $this->getPeopleFactory()->create($data['person']); + + if ($person instanceof Person) { + $credits->setPerson($person); + } } return $this->hydrate($credits, $data); diff --git a/lib/Tmdb/Factory/FindFactory.php b/lib/Tmdb/Factory/FindFactory.php index dd6fb3d9..59e37e82 100644 --- a/lib/Tmdb/Factory/FindFactory.php +++ b/lib/Tmdb/Factory/FindFactory.php @@ -12,7 +12,6 @@ */ namespace Tmdb\Factory; -use Tmdb\Exception\NotImplementedException; use Tmdb\Model\Find; /** @@ -73,7 +72,11 @@ public function create(array $data = array()) */ public function createCollection(array $data = array()) { - throw new NotImplementedException(sprintf('Method "%s" is not implemented.', __METHOD__)); + throw new \RuntimeException(sprintf( + 'Class "%s" does not support method "%s".', + __CLASS__, + __METHOD__ + )); } /** diff --git a/lib/Tmdb/Factory/ImageFactory.php b/lib/Tmdb/Factory/ImageFactory.php index 3d38d7fc..35a95db4 100644 --- a/lib/Tmdb/Factory/ImageFactory.php +++ b/lib/Tmdb/Factory/ImageFactory.php @@ -12,6 +12,7 @@ */ namespace Tmdb\Factory; +use Tmdb\Exception\RuntimeException; use Tmdb\Model\Collection\Images; use Tmdb\Model\Image; @@ -52,6 +53,56 @@ public function createFromPath($path, $key) ); } + /** + * Create an Media/Image type which is used in calls like person/tagged_images, which contains an getMedia() + * reference either referring to movies / tv shows etc. + * + * @param array $data + * @return Image + * + * @throws \RuntimeException + */ + public function createMediaImage(array $data = array()) + { + if (!array_key_exists('image_type', $data)) { + throw new \RuntimeException('Unable to detect the image type.'); + } + + $type = $this->resolveImageType($data['image_type']); + $image = $this->hydrate($type, $data); + + if (array_key_exists('media', $data) && array_key_exists('media_type', $data)) { + switch ($data['media_type']) { + case "movie": + $factory = new MovieFactory(); + break; + + case "tv": + $factory = new TvFactory(); + break; + + // I don't think this ever occurs, but just in case.. + case "person": + $factory = new PeopleFactory(); + break; + + default: + throw new RuntimeException(sprintf( + 'Unrecognized media_type "%s" for method "%s::%s".', + $data['media_type'], + __CLASS__, + __METHOD__ + )); + } + + $media = $factory->create($data['media']); + + $image->setMedia($media); + } + + return $this->hydrate($type, $data); + } + /** * Helper function to obtain a new object for an image type * diff --git a/lib/Tmdb/Factory/MovieFactory.php b/lib/Tmdb/Factory/MovieFactory.php index fcba1d7e..c4283267 100644 --- a/lib/Tmdb/Factory/MovieFactory.php +++ b/lib/Tmdb/Factory/MovieFactory.php @@ -19,10 +19,7 @@ use Tmdb\Factory\People\CrewFactory; use Tmdb\Model\Common\Country; use Tmdb\Model\Common\GenericCollection; -use Tmdb\Model\Common\Trailer\Youtube; use Tmdb\Model\Common\Translation; -use Tmdb\Model\Company; -use Tmdb\Model\Lists\Result; use Tmdb\Model\Movie; /** @@ -147,14 +144,6 @@ public function create(array $data = array()) $movie->setReleases($this->createGenericCollection($data['releases']['countries'], new Movie\Release())); } - /** - * @TODO actually implement more providers? - * ( Can't seem to find any quicktime related trailers anyways? ). For now KISS - */ - if (array_key_exists('trailers', $data) && array_key_exists('youtube', $data['trailers'])) { - $movie->setTrailers($this->createGenericCollection($data['trailers']['youtube'], new Youtube())); - } - if (array_key_exists('videos', $data)) { $movie->setVideos($this->getVideoFactory()->createCollection($data['videos'])); } @@ -217,47 +206,6 @@ public function createCollection(array $data = array()) return $collection; } - /** - * Create result - * - * @param array $data - * @return \Tmdb\Model\AbstractModel - */ - public function createResult(array $data = array()) - { - return $this->hydrate(new Result(), $data); - } - - /** - * Create rating - * - * @param array $data - * @return \Tmdb\Model\AbstractModel - */ - public function createRating(array $data = array()) - { - return $this->hydrate(new Movie\Rating(), $data); - } - - /** - * Create the account states - * - * @param array $data - * @return \Tmdb\Model\AbstractModel - */ - public function createAccountStates(array $data = array()) - { - $accountStates = new Movie\AccountStates(); - - if (array_key_exists('rated', $data)) { - $rating = new Movie\Rating(); - - $accountStates->setRated($this->hydrate($rating, $data['rated'])); - } - - return $this->hydrate($accountStates, $data); - } - /** * @param \Tmdb\Factory\People\CastFactory $castFactory * @return $this diff --git a/lib/Tmdb/Factory/PeopleFactory.php b/lib/Tmdb/Factory/PeopleFactory.php index f4db86bc..1fba7a63 100644 --- a/lib/Tmdb/Factory/PeopleFactory.php +++ b/lib/Tmdb/Factory/PeopleFactory.php @@ -45,7 +45,7 @@ public function __construct() * @param array $data * @param Person\AbstractMember|null $person * - * @return Person|CrewMember|CastMember + * @return Person */ public function create(array $data = array(), $person = null) { @@ -91,7 +91,8 @@ public function create(array $data = array(), $person = null) if (array_key_exists('tagged_images', $data)) { $person->setTaggedImages( $this->getImageFactory()->createResultCollection( - $data['tagged_images'] + $data['tagged_images'], + 'createMediaImage' ) ); } @@ -115,9 +116,10 @@ protected function applyCredits(array $data, Person $person) $method = $hydrator->camelize(sprintf('get_%s', $type)); if (array_key_exists('cast', $data[$type])) { - $cast = $this->createGenericCollection( + $cast = $this->createCustomCollection( $data[$type]['cast'], - new Person\MovieCredit() + new Person\MovieCredit(), + new People\Cast() ); foreach ($cast as $member) { @@ -128,9 +130,10 @@ protected function applyCredits(array $data, Person $person) } if (array_key_exists('crew', $data[$type])) { - $crew = $this->createGenericCollection( + $crew = $this->createCustomCollection( $data[$type]['crew'], - new Person\MovieCredit() + new Person\MovieCredit(), + new People\Crew() ); foreach ($crew as $member) { diff --git a/lib/Tmdb/Factory/TvFactory.php b/lib/Tmdb/Factory/TvFactory.php index 6afee4de..78e13a88 100644 --- a/lib/Tmdb/Factory/TvFactory.php +++ b/lib/Tmdb/Factory/TvFactory.php @@ -16,7 +16,9 @@ use Tmdb\Factory\Common\VideoFactory; use Tmdb\Factory\People\CastFactory; use Tmdb\Factory\People\CrewFactory; +use Tmdb\Model\Common\Country; use Tmdb\Model\Common\GenericCollection; +use Tmdb\Model\Common\SpokenLanguage; use Tmdb\Model\Common\Translation; use Tmdb\Model\Person\CastMember; use Tmdb\Model\Person\CrewMember; @@ -194,6 +196,45 @@ public function create(array $data = array()) $tvShow->setSimilar($this->createResultCollection($data['similar'])); } + if (array_key_exists('languages', $data)) { + $collection = new GenericCollection(); + + foreach ($data['languages'] as $iso6391) { + $object = new SpokenLanguage(); + $object->setIso6391($iso6391); + + $collection->add(null, $object); + } + + $tvShow->setLanguages($collection); + } + + if (array_key_exists('origin_country', $data)) { + $collection = new GenericCollection(); + + foreach ($data['origin_country'] as $iso31661) { + $object = new Country(); + $object->setIso31661($iso31661); + + $collection->add(null, $object); + } + + $tvShow->setOriginCountry($collection); + } + + if (array_key_exists('created_by', $data)) { + $collection = new GenericCollection(); + $factory = new PeopleFactory(); + + foreach ($data['created_by'] as $castMember) { + $object = $factory->create($castMember, new CastMember()); + + $collection->add(null, $object); + } + + $tvShow->setCreatedBy($collection); + } + return $this->hydrate($tvShow, $data); } diff --git a/lib/Tmdb/HttpClient/HttpClient.php b/lib/Tmdb/HttpClient/HttpClient.php index 6b1c8049..0ef1ef8e 100644 --- a/lib/Tmdb/HttpClient/HttpClient.php +++ b/lib/Tmdb/HttpClient/HttpClient.php @@ -13,7 +13,7 @@ namespace Tmdb\HttpClient; use Guzzle\Http\ClientInterface; -use Guzzle\Http\Message\Request; +use Guzzle\Http\Exception\ClientErrorResponseException; use Guzzle\Http\Message\RequestInterface; use Guzzle\Http\Message\Response; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -52,7 +52,7 @@ class HttpClient implements HttpClientInterface private $lastResponse; /** - * @var Request + * @var RequestInterface */ private $lastRequest; @@ -186,7 +186,7 @@ public function request(RequestInterface $request) try { $response = $request->send(); - } catch (\Exception $e) { + } catch (ClientErrorResponseException $e) { $error = $e->getResponse()->json(); throw new TmdbApiException($error['status_message'], $error['status_code']); } diff --git a/lib/Tmdb/HttpClient/HttpClientInterface.php b/lib/Tmdb/HttpClient/HttpClientInterface.php index a88d89f8..d264d4fb 100644 --- a/lib/Tmdb/HttpClient/HttpClientInterface.php +++ b/lib/Tmdb/HttpClient/HttpClientInterface.php @@ -48,10 +48,10 @@ public function post($path, $postBody, array $parameters = array(), array $heade /** * Compose a POST request but json_encode the body * - * @param string $path Request path - * @param array $postBody The post BODY - * @param array $parameters POST Parameters - * @param array $headers Reconfigure the request headers for this call only + * @param string $path Request path + * @param string|null $postBody The post BODY + * @param array $parameters POST Parameters + * @param array $headers Reconfigure the request headers for this call only * * @return Response Data */ @@ -101,8 +101,20 @@ public function delete($path, $body = null, array $parameters = array(), array $ */ public function request(RequestInterface $request); + /** + * @return string|null + */ public function getBaseUrl(); + + /** + * @param string $url + * + * @return \Guzzle\Http\ClientInterface + */ public function setBaseUrl($url); + /** + * @return void + */ public function setSessionToken(SessionToken $sessionToken); } diff --git a/lib/Tmdb/HttpClient/Plugin/SessionTokenPlugin.php b/lib/Tmdb/HttpClient/Plugin/SessionTokenPlugin.php index 6a84979d..785d1d6e 100644 --- a/lib/Tmdb/HttpClient/Plugin/SessionTokenPlugin.php +++ b/lib/Tmdb/HttpClient/Plugin/SessionTokenPlugin.php @@ -24,7 +24,7 @@ class SessionTokenPlugin implements EventSubscriberInterface { /** - * @var \Tmdb\ApiToken + * @var \Tmdb\SessionToken */ private $token; diff --git a/lib/Tmdb/Model/Collection/CreditsCollection.php b/lib/Tmdb/Model/Collection/CreditsCollection.php index 69d71747..6899a136 100644 --- a/lib/Tmdb/Model/Collection/CreditsCollection.php +++ b/lib/Tmdb/Model/Collection/CreditsCollection.php @@ -14,7 +14,6 @@ use Tmdb\Model\Collection\People\Cast; use Tmdb\Model\Collection\People\Crew; -use Tmdb\Model\Common\GenericCollection; /** * Class CreditsCollection @@ -42,10 +41,10 @@ public function __construct() } /** - * @param Cast|GenericCollection $cast + * @param Cast $cast * @return $this */ - public function setCast(GenericCollection $cast) + public function setCast(Cast $cast) { $this->cast = $cast; @@ -61,10 +60,10 @@ public function getCast() } /** - * @param Crew|GenericCollection $crew + * @param Crew $crew * @return $this */ - public function setCrew(GenericCollection $crew) + public function setCrew(Crew $crew) { $this->crew = $crew; diff --git a/lib/Tmdb/Model/Collection/Images.php b/lib/Tmdb/Model/Collection/Images.php index 7163afde..5377d011 100644 --- a/lib/Tmdb/Model/Collection/Images.php +++ b/lib/Tmdb/Model/Collection/Images.php @@ -36,7 +36,7 @@ public function getImages() * Retrieve a image from the collection * * @param $id - * @return null + * @return GenericCollection */ public function getImage($id) { diff --git a/lib/Tmdb/Model/Collection/People/PersonInterface.php b/lib/Tmdb/Model/Collection/People/PersonInterface.php index 3d3e0ad7..7dbdcf2c 100644 --- a/lib/Tmdb/Model/Collection/People/PersonInterface.php +++ b/lib/Tmdb/Model/Collection/People/PersonInterface.php @@ -18,6 +18,9 @@ */ interface PersonInterface { + /** + * @return string + */ public function getName(); /** diff --git a/lib/Tmdb/Model/Movie/AccountStates.php b/lib/Tmdb/Model/Common/AccountStates.php similarity index 91% rename from lib/Tmdb/Model/Movie/AccountStates.php rename to lib/Tmdb/Model/Common/AccountStates.php index 6d64bcc9..23d9dfff 100644 --- a/lib/Tmdb/Model/Movie/AccountStates.php +++ b/lib/Tmdb/Model/Common/AccountStates.php @@ -10,13 +10,13 @@ * @copyright (c) 2013, Michael Roterman * @version 0.0.1 */ -namespace Tmdb\Model\Movie; +namespace Tmdb\Model\Common; use Tmdb\Model\AbstractModel; /** * Class AccountStates - * @package Tmdb\Model\Movie + * @package Tmdb\Model\Common */ class AccountStates extends AbstractModel { @@ -46,6 +46,14 @@ class AccountStates extends AbstractModel 'watchlist', ); + /** + * Constructor + */ + public function __construct() + { + $this->rated = new Rating(); + } + /** * @param boolean $favorite * @return $this diff --git a/lib/Tmdb/Model/Movie/Rating.php b/lib/Tmdb/Model/Common/Rating.php similarity index 96% rename from lib/Tmdb/Model/Movie/Rating.php rename to lib/Tmdb/Model/Common/Rating.php index 71af8de6..46eaf002 100644 --- a/lib/Tmdb/Model/Movie/Rating.php +++ b/lib/Tmdb/Model/Common/Rating.php @@ -10,7 +10,7 @@ * @copyright (c) 2013, Michael Roterman * @version 0.0.1 */ -namespace Tmdb\Model\Movie; +namespace Tmdb\Model\Common; use Tmdb\Model\AbstractModel; diff --git a/lib/Tmdb/Model/Image.php b/lib/Tmdb/Model/Image.php index d0416080..5c1abd6f 100644 --- a/lib/Tmdb/Model/Image.php +++ b/lib/Tmdb/Model/Image.php @@ -34,6 +34,7 @@ class Image extends AbstractModel implements ImageFilter, LanguageFilter private $aspectRatio; private $voteAverage; private $voteCount; + private $media; protected $id; protected $type; @@ -202,6 +203,25 @@ public function getWidth() return $this->width; } + /** + * @param mixed $media + * @return $this + */ + public function setMedia($media) + { + $this->media = $media; + + return $this; + } + + /** + * @return mixed + */ + public function getMedia() + { + return $this->media; + } + /** * Return the file path when casted to string * diff --git a/lib/Tmdb/Model/Movie.php b/lib/Tmdb/Model/Movie.php index 8e7e4f9c..563d8ed3 100644 --- a/lib/Tmdb/Model/Movie.php +++ b/lib/Tmdb/Model/Movie.php @@ -18,7 +18,6 @@ use Tmdb\Model\Collection\CreditsCollection; use Tmdb\Model\Collection\Genres; use Tmdb\Model\Collection\Images; -use Tmdb\Model\Common\Country; use Tmdb\Model\Common\SpokenLanguage; use Tmdb\Model\Common\Translation; use Tmdb\Model\Movie\AlternativeTitle; @@ -46,9 +45,9 @@ class Movie extends AbstractModel private $backdrop; /** - * @var Collection + * @var GenericCollection */ - private $belongsToCollection = null; + private $belongsToCollection; /** * @var int @@ -101,12 +100,12 @@ class Movie extends AbstractModel private $posterPath; /** - * @var Collection + * @var GenericCollection */ private $productionCompanies; /** - * @var Collection + * @var GenericCollection */ private $productionCountries; @@ -126,7 +125,7 @@ class Movie extends AbstractModel private $runtime; /** - * @var Collection + * @var GenericCollection */ private $spokenLanguages; @@ -156,19 +155,19 @@ class Movie extends AbstractModel private $voteCount; /** - * @var Collection + * @var GenericCollection */ protected $alternativeTitles; /** - * @var Collection + * @var GenericCollection */ protected $changes; /** * Credits * - * @var Credits + * @var CreditsCollection */ protected $credits; @@ -180,32 +179,27 @@ class Movie extends AbstractModel protected $images; /** - * @var Collection + * @var GenericCollection */ protected $keywords; /** - * @var Collection + * @var GenericCollection */ protected $lists; /** - * @var Collection + * @var GenericCollection */ protected $releases; /** - * @var Collection + * @var GenericCollection */ protected $similar; /** - * @var Collection - */ - protected $trailers; - - /** - * @var Collection + * @var GenericCollection */ protected $translations; @@ -267,7 +261,6 @@ public function __construct() $this->lists = new GenericCollection(); $this->releases = new GenericCollection(); $this->similar = new GenericCollection(); - $this->trailers = new GenericCollection(); $this->translations = new GenericCollection(); $this->videos = new Videos(); } @@ -292,7 +285,7 @@ public function getAdult() } /** - * @param mixed $backdropPath + * @param string $backdropPath * @return $this */ public function setBackdropPath($backdropPath) @@ -303,7 +296,7 @@ public function setBackdropPath($backdropPath) } /** - * @return mixed + * @return string */ public function getBackdropPath() { @@ -322,7 +315,7 @@ public function setBelongsToCollection($belongsToCollection) } /** - * @return Collection|null + * @return GenericCollection */ public function getBelongsToCollection() { @@ -342,6 +335,7 @@ public function setChanges(GenericCollection $changes) /** * @return mixed + * @return GenericCollection */ public function getChanges() { @@ -360,7 +354,7 @@ public function setGenres(Genres $genres) } /** - * @return Genre[] + * @return Genres */ public function getGenres() { @@ -368,7 +362,7 @@ public function getGenres() } /** - * @param mixed $homepage + * @param string $homepage * @return $this */ public function setHomepage($homepage) @@ -379,7 +373,7 @@ public function setHomepage($homepage) } /** - * @return mixed + * @return string */ public function getHomepage() { @@ -425,7 +419,7 @@ public function getImages() } /** - * @param mixed $imdbId + * @param string $imdbId * @return $this */ public function setImdbId($imdbId) @@ -436,7 +430,7 @@ public function setImdbId($imdbId) } /** - * @return mixed + * @return string */ public function getImdbId() { @@ -444,7 +438,7 @@ public function getImdbId() } /** - * @param mixed $originalTitle + * @param string $originalTitle * @return $this */ public function setOriginalTitle($originalTitle) @@ -455,7 +449,7 @@ public function setOriginalTitle($originalTitle) } /** - * @return mixed + * @return string */ public function getOriginalTitle() { @@ -463,7 +457,7 @@ public function getOriginalTitle() } /** - * @param mixed $overview + * @param string $overview * @return $this */ public function setOverview($overview) @@ -474,7 +468,7 @@ public function setOverview($overview) } /** - * @return mixed + * @return string */ public function getOverview() { @@ -501,7 +495,7 @@ public function getPopularity() } /** - * @param mixed $posterPath + * @param string $posterPath * @return $this */ public function setPosterPath($posterPath) @@ -512,7 +506,7 @@ public function setPosterPath($posterPath) } /** - * @return mixed + * @return string */ public function getPosterPath() { @@ -550,7 +544,7 @@ public function setProductionCountries(GenericCollection $productionCountries) } /** - * @return Country + * @return GenericCollection */ public function getProductionCountries() { @@ -638,7 +632,7 @@ public function getSpokenLanguages() } /** - * @param mixed $status + * @param string $status * @return $this */ public function setStatus($status) @@ -649,7 +643,7 @@ public function setStatus($status) } /** - * @return mixed + * @return string */ public function getStatus() { @@ -657,7 +651,7 @@ public function getStatus() } /** - * @param mixed $tagline + * @param string $tagline * @return $this */ public function setTagline($tagline) @@ -668,7 +662,7 @@ public function setTagline($tagline) } /** - * @return mixed + * @return string */ public function getTagline() { @@ -676,7 +670,7 @@ public function getTagline() } /** - * @param mixed $title + * @param string $title * @return $this */ public function setTitle($title) @@ -687,7 +681,7 @@ public function setTitle($title) } /** - * @return mixed + * @return string */ public function getTitle() { @@ -874,25 +868,6 @@ public function getSimilarMovies() return $this->getSimilar(); } - /** - * @param GenericCollection $trailers - * @return $this - */ - public function setTrailers($trailers) - { - $this->trailers = $trailers; - - return $this; - } - - /** - * @return \Tmdb\Model\Common\Trailer\Youtube[] - */ - public function getTrailers() - { - return $this->trailers; - } - /** * @param GenericCollection $translations * @return $this diff --git a/lib/Tmdb/Model/Movie/QueryParameter/AppendToResponse.php b/lib/Tmdb/Model/Movie/QueryParameter/AppendToResponse.php index baeeeab5..a459302a 100644 --- a/lib/Tmdb/Model/Movie/QueryParameter/AppendToResponse.php +++ b/lib/Tmdb/Model/Movie/QueryParameter/AppendToResponse.php @@ -25,9 +25,8 @@ final class AppendToResponse extends BaseAppendToResponse const IMAGES = 'images'; const KEYWORDS = 'keywords'; const RELEASES = 'releases'; - const TRAILERS = 'trailers'; const TRANSLATIONS = 'translations'; - const SIMILAR_MOVIES = 'similar'; + const SIMILAR = 'similar'; const REVIEWS = 'reviews'; const LISTS = 'lists'; const CHANGES = 'changes'; diff --git a/lib/Tmdb/Model/Network.php b/lib/Tmdb/Model/Network.php index d71d64a9..4391032c 100644 --- a/lib/Tmdb/Model/Network.php +++ b/lib/Tmdb/Model/Network.php @@ -60,7 +60,7 @@ public function getId() } /** - * @param mixed $name + * @param string $name * @return $this */ public function setName($name) @@ -71,7 +71,7 @@ public function setName($name) } /** - * @return mixed + * @return string */ public function getName() { diff --git a/lib/Tmdb/Model/Person.php b/lib/Tmdb/Model/Person.php index b1bbd9e4..3dcc4d96 100644 --- a/lib/Tmdb/Model/Person.php +++ b/lib/Tmdb/Model/Person.php @@ -79,12 +79,6 @@ class Person extends AbstractModel implements PersonInterface */ private $profileImage; - /** - * @var Collection\CreditsCollection - * @deprecated - */ - protected $credits; - /** * @var CreditsCollection\MovieCredits */ @@ -142,7 +136,6 @@ class Person extends AbstractModel implements PersonInterface */ public function __construct() { - $this->credits = new CreditsCollection(); $this->movieCredits = new CreditsCollection\MovieCredits(); $this->tvCredits = new CreditsCollection\TvCredits(); $this->combinedCredits = new CreditsCollection\CombinedCredits(); @@ -152,7 +145,7 @@ public function __construct() } /** - * @param mixed $adult + * @param boolean $adult * @return $this */ public function setAdult($adult) @@ -163,7 +156,7 @@ public function setAdult($adult) } /** - * @return mixed + * @return boolean */ public function getAdult() { @@ -171,7 +164,7 @@ public function getAdult() } /** - * @param mixed $alsoKnownAs + * @param array $alsoKnownAs * @return $this */ public function setAlsoKnownAs($alsoKnownAs) @@ -190,7 +183,7 @@ public function getAlsoKnownAs() } /** - * @param mixed $biography + * @param string $biography * @return $this */ public function setBiography($biography) @@ -201,7 +194,7 @@ public function setBiography($biography) } /** - * @return mixed + * @return string */ public function getBiography() { @@ -224,7 +217,7 @@ public function setBirthday($birthday) } /** - * @return mixed + * @return \DateTime */ public function getBirthday() { @@ -232,10 +225,10 @@ public function getBirthday() } /** - * @param mixed $changes + * @param GenericCollection $changes * @return $this */ - public function setChanges($changes) + public function setChanges(GenericCollection $changes) { $this->changes = $changes; @@ -243,32 +236,13 @@ public function setChanges($changes) } /** - * @return mixed + * @return GenericCollection */ public function getChanges() { return $this->changes; } - /** - * @param mixed $credits - * @return $this - */ - public function setCredits($credits) - { - $this->credits = $credits; - - return $this; - } - - /** - * @return mixed - */ - public function getCredits() - { - return $this->credits; - } - /** * @param mixed $deathday * @return $this @@ -297,7 +271,7 @@ public function getDeathday() } /** - * @param mixed $homepage + * @param string $homepage * @return $this */ public function setHomepage($homepage) @@ -308,7 +282,7 @@ public function setHomepage($homepage) } /** - * @return mixed + * @return string */ public function getHomepage() { @@ -354,7 +328,7 @@ public function getImages() } /** - * @param mixed $name + * @param string $name * @return $this */ public function setName($name) @@ -365,7 +339,7 @@ public function setName($name) } /** - * @return mixed + * @return string */ public function getName() { @@ -373,7 +347,7 @@ public function getName() } /** - * @param mixed $placeOfBirth + * @param string $placeOfBirth * @return $this */ public function setPlaceOfBirth($placeOfBirth) @@ -384,7 +358,7 @@ public function setPlaceOfBirth($placeOfBirth) } /** - * @return mixed + * @return string */ public function getPlaceOfBirth() { @@ -392,7 +366,7 @@ public function getPlaceOfBirth() } /** - * @param mixed $profilePath + * @param string $profilePath * @return $this */ public function setProfilePath($profilePath) @@ -403,7 +377,7 @@ public function setProfilePath($profilePath) } /** - * @return mixed + * @return string */ public function getProfilePath() { @@ -506,7 +480,7 @@ public function getExternalIds() } /** - * @param mixed $taggedImages + * @param GenericCollection $taggedImages * @return $this */ public function setTaggedImages($taggedImages) @@ -517,7 +491,7 @@ public function setTaggedImages($taggedImages) } /** - * @return mixed + * @return GenericCollection */ public function getTaggedImages() { diff --git a/lib/Tmdb/Model/Person/AbstractMember.php b/lib/Tmdb/Model/Person/AbstractMember.php index a4c79282..5bb1176c 100644 --- a/lib/Tmdb/Model/Person/AbstractMember.php +++ b/lib/Tmdb/Model/Person/AbstractMember.php @@ -67,7 +67,7 @@ public function getId() } /** - * @param mixed $name + * @param string $name * @return $this */ public function setName($name) @@ -78,7 +78,7 @@ public function setName($name) } /** - * @return mixed + * @return string */ public function getName() { @@ -86,7 +86,7 @@ public function getName() } /** - * @param mixed $profilePath + * @param string $profilePath * @return $this */ public function setProfilePath($profilePath) @@ -97,7 +97,7 @@ public function setProfilePath($profilePath) } /** - * @return mixed + * @return string */ public function getProfilePath() { @@ -116,7 +116,7 @@ public function setProfileImage($profile = null) } /** - * @return Image\ProfileImage|null + * @return Image\ProfileImage */ public function getProfileImage() { diff --git a/lib/Tmdb/Model/Person/CastMember.php b/lib/Tmdb/Model/Person/CastMember.php index adca6dfe..9468f38d 100644 --- a/lib/Tmdb/Model/Person/CastMember.php +++ b/lib/Tmdb/Model/Person/CastMember.php @@ -51,7 +51,7 @@ class CastMember extends AbstractMember implements PersonInterface ); /** - * @param mixed $character + * @param string $character * @return $this */ public function setCharacter($character) @@ -62,7 +62,7 @@ public function setCharacter($character) } /** - * @return mixed + * @return string */ public function getCharacter() { diff --git a/lib/Tmdb/Model/Person/CrewMember.php b/lib/Tmdb/Model/Person/CrewMember.php index 9f5277fb..0b3c00f2 100644 --- a/lib/Tmdb/Model/Person/CrewMember.php +++ b/lib/Tmdb/Model/Person/CrewMember.php @@ -45,7 +45,7 @@ class CrewMember extends AbstractMember implements PersonInterface ); /** - * @param mixed $department + * @param string $department * @return $this */ public function setDepartment($department) @@ -56,7 +56,7 @@ public function setDepartment($department) } /** - * @return mixed + * @return string */ public function getDepartment() { @@ -64,7 +64,7 @@ public function getDepartment() } /** - * @param mixed $job + * @param string $job * @return $this */ public function setJob($job) @@ -75,7 +75,7 @@ public function setJob($job) } /** - * @return mixed + * @return string */ public function getJob() { diff --git a/lib/Tmdb/Model/Search/SearchQuery.php b/lib/Tmdb/Model/Search/SearchQuery.php index 1dcb94ce..c822e22f 100644 --- a/lib/Tmdb/Model/Search/SearchQuery.php +++ b/lib/Tmdb/Model/Search/SearchQuery.php @@ -20,10 +20,18 @@ */ class SearchQuery extends QueryParametersCollection { + /** + * Constructor + */ + public function __construct() + { + $this->page(1); + } + /** * CGI escaped string * - * @param string + * @param string $query * @return $this */ public function query($query) @@ -36,7 +44,7 @@ public function query($query) /** * Minimum 1, maximum 1000. * - * @param int + * @param int $page * @return $this */ public function page($page) diff --git a/lib/Tmdb/Model/Timezone/CountryTimezone.php b/lib/Tmdb/Model/Timezone/CountryTimezone.php index f02a3335..7d53d06d 100644 --- a/lib/Tmdb/Model/Timezone/CountryTimezone.php +++ b/lib/Tmdb/Model/Timezone/CountryTimezone.php @@ -14,7 +14,6 @@ use Tmdb\Model\AbstractModel; use Tmdb\Model\Collection\Timezones; -use Tmdb\Model\Common\GenericCollection; /** * Class Timezone @@ -34,7 +33,7 @@ class CountryTimezone extends AbstractModel public function __construct() { - $this->timezones = new GenericCollection(); + $this->timezones = new Timezones(); } /** @@ -79,7 +78,7 @@ public function getIso31661() * Verify if a country supports a certain timezone * * @param $timezone - * @return mixed + * @return boolean */ public function supports($timezone) { diff --git a/lib/Tmdb/Model/Tv.php b/lib/Tmdb/Model/Tv.php index 8087ee5f..4b7db5b6 100644 --- a/lib/Tmdb/Model/Tv.php +++ b/lib/Tmdb/Model/Tv.php @@ -28,12 +28,12 @@ class Tv extends AbstractModel { /** - * @var Image + * @var string */ private $backdropPath; /** - * @var Collection + * @var Common\GenericCollection */ private $createdBy = null; @@ -85,7 +85,7 @@ class Tv extends AbstractModel private $name; /** - * @var Network[] + * @var GenericCollection|Network[] */ private $networks; @@ -105,7 +105,7 @@ class Tv extends AbstractModel private $originalName; /** - * @var Collection + * @var Common\GenericCollection */ private $originCountry; @@ -120,12 +120,12 @@ class Tv extends AbstractModel private $popularity; /** - * @var Image + * @var string */ private $posterPath; /** - * @var Collection + * @var Common\GenericCollection */ private $seasons; @@ -147,7 +147,7 @@ class Tv extends AbstractModel /** * Credits * - * @var Credits + * @var CreditsCollection */ protected $credits; @@ -166,7 +166,7 @@ class Tv extends AbstractModel protected $images; /** - * @var Collection + * @var Common\GenericCollection */ protected $translations; @@ -209,19 +209,16 @@ class Tv extends AbstractModel */ public static $properties = array( 'backdrop_path', - 'created_by', 'episode_run_time', 'first_air_date', 'homepage', 'id', 'in_production', - 'languages', 'last_air_date', 'name', 'number_of_episodes', 'number_of_seasons', 'original_name', - 'origin_country', 'overview', 'popularity', 'poster_path', @@ -237,10 +234,7 @@ class Tv extends AbstractModel */ public function __construct() { - $this->createdBy = new Images(); - $this->episodeRunTime = new GenericCollection(); $this->genres = new Genres(); - $this->languages = new GenericCollection(); $this->networks = new GenericCollection(); $this->originCountry = new GenericCollection(); $this->seasons = new GenericCollection(); @@ -286,7 +280,7 @@ public function setCreatedBy($createdBy) } /** - * @return \Tmdb\Model\Common\Collection + * @return GenericCollection */ public function getCreatedBy() { @@ -541,7 +535,7 @@ public function setOriginCountry($originCountry) } /** - * @return \Tmdb\Model\Common\Collection + * @return GenericCollection */ public function getOriginCountry() { @@ -636,7 +630,7 @@ public function setSeasons($seasons) } /** - * @return \Tmdb\Model\Common\Collection + * @return GenericCollection */ public function getSeasons() { @@ -712,7 +706,7 @@ public function setTranslations($translations) } /** - * @return \Tmdb\Model\Common\Collection + * @return GenericCollection */ public function getTranslations() { diff --git a/lib/Tmdb/Model/Tv/Episode.php b/lib/Tmdb/Model/Tv/Episode.php index 84a7ebac..2efaec8b 100644 --- a/lib/Tmdb/Model/Tv/Episode.php +++ b/lib/Tmdb/Model/Tv/Episode.php @@ -18,7 +18,6 @@ use Tmdb\Model\Collection\Images; use Tmdb\Model\Collection\Videos; use Tmdb\Model\Common\ExternalIds; -use Tmdb\Model\Common\Video; use Tmdb\Model\Image\StillImage; /** @@ -80,7 +79,7 @@ class Episode extends AbstractModel /** * Credits * - * @var Credits + * @var CreditsCollection */ protected $credits; @@ -424,7 +423,7 @@ public function setVideos($videos) } /** - * @return Videos|Video[] + * @return Videos */ public function getVideos() { diff --git a/lib/Tmdb/Model/Tv/Season.php b/lib/Tmdb/Model/Tv/Season.php index 5d3b11a8..9df86f18 100644 --- a/lib/Tmdb/Model/Tv/Season.php +++ b/lib/Tmdb/Model/Tv/Season.php @@ -19,7 +19,6 @@ use Tmdb\Model\Collection\Videos; use Tmdb\Model\Common\ExternalIds; use Tmdb\Model\Common\GenericCollection; -use Tmdb\Model\Common\Video; use Tmdb\Model\Image\PosterImage; /** @@ -34,7 +33,7 @@ class Season extends AbstractModel private $airDate; /** - * @var Episode[] + * @var GenericCollection|Episode[] */ private $episodes; @@ -66,7 +65,7 @@ class Season extends AbstractModel /** * Credits * - * @var Credits + * @var CreditsCollection */ protected $credits; @@ -224,7 +223,7 @@ public function getOverview() } /** - * @param \Tmdb\Model\Tv\Image $posterPath + * @param string $posterPath * @return $this */ public function setPosterPath($posterPath) @@ -235,7 +234,7 @@ public function setPosterPath($posterPath) } /** - * @return \Tmdb\Model\Tv\Image + * @return string */ public function getPosterPath() { @@ -349,7 +348,7 @@ public function setVideos($videos) } /** - * @return Videos|Video[] + * @return Videos */ public function getVideos() { diff --git a/lib/Tmdb/Repository/AccountRepository.php b/lib/Tmdb/Repository/AccountRepository.php index ae895f67..d3c6798a 100644 --- a/lib/Tmdb/Repository/AccountRepository.php +++ b/lib/Tmdb/Repository/AccountRepository.php @@ -28,7 +28,7 @@ class AccountRepository extends AbstractRepository * Get the basic information for an account. * You will need to have a valid session id. * - * @return null|\Tmdb\Model\AbstractModel + * @return \Tmdb\Model\Account */ public function getAccount() { @@ -85,10 +85,10 @@ public function getFavoriteTvShows($accountId, array $parameters = array(), arra /** * Add or remove a movie to an accounts favorite list. * - * @param string $accountId - * @param int|Movie|Tv $media - * @param boolean $isFavorite - * @return ResultCollection + * @param string $accountId + * @param int|Movie|Tv $media + * @param boolean $isFavorite + * @return \Tmdb\Model\Lists\Result */ public function favorite($accountId, $media, $isFavorite = true) { diff --git a/lib/Tmdb/Repository/AuthenticationRepository.php b/lib/Tmdb/Repository/AuthenticationRepository.php index 43819581..266f8ee5 100644 --- a/lib/Tmdb/Repository/AuthenticationRepository.php +++ b/lib/Tmdb/Repository/AuthenticationRepository.php @@ -43,8 +43,8 @@ public function getRequestToken() * This method is used to generate a session id for user based authentication. * A session id is required in order to use any of the write methods. * - * @param RequestToken $requestToken - * @return RequestToken + * @param RequestToken $requestToken + * @return \Tmdb\SessionToken */ public function getSessionToken(RequestToken $requestToken) { @@ -61,7 +61,7 @@ public function getSessionToken(RequestToken $requestToken) * @param string $username * @param string $password * @throws UnauthorizedRequestTokenException - * @return mixed + * @return RequestToken */ public function validateRequestTokenWithLogin(RequestToken $requestToken, $username, $password) { @@ -82,7 +82,7 @@ public function validateRequestTokenWithLogin(RequestToken $requestToken, $usern * @param string $username * @param string $password * @throws UnauthorizedRequestTokenException - * @return mixed + * @return \Tmdb\SessionToken */ public function getSessionTokenWithLogin(RequestToken $requestToken, $username, $password) { @@ -108,7 +108,7 @@ public function getSessionTokenWithLogin(RequestToken $requestToken, $username, * If a guest session is not used for the first time within 24 hours, * it will be automatically discarded. * - * @return RequestToken + * @return \Tmdb\GuestSessionToken */ public function getGuestSessionToken() { diff --git a/lib/Tmdb/Repository/CertificationRepository.php b/lib/Tmdb/Repository/CertificationRepository.php index 8738535f..80f185c8 100644 --- a/lib/Tmdb/Repository/CertificationRepository.php +++ b/lib/Tmdb/Repository/CertificationRepository.php @@ -29,7 +29,7 @@ class CertificationRepository extends AbstractRepository * * @param $parameters * @param $headers - * @return null|\Tmdb\Model\AbstractModel + * @return \Tmdb\Model\Common\GenericCollection */ public function getMovieList(array $parameters = array(), array $headers = array()) { diff --git a/lib/Tmdb/Repository/ChangesRepository.php b/lib/Tmdb/Repository/ChangesRepository.php index d873ff4f..516d0480 100644 --- a/lib/Tmdb/Repository/ChangesRepository.php +++ b/lib/Tmdb/Repository/ChangesRepository.php @@ -65,6 +65,28 @@ public function getPeopleChanges(ChangesQuery $query, array $headers = array()) return $this->getFactory()->createResultCollection($data); } + /** + * Get a list of tv show ids that have been edited. + * + * By default we show the last 24 hours and only 100 items per page. + * The maximum number of days that can be returned in a single request is 14. + * + * You can then use the tv changes API to get the actual data that has been changed. + * + * Please note that the change log system to support this was changed + * on May 13, 2014 and will only show tv shows that have been edited since. + * + * @param ChangesQuery $query + * @param array $headers + * @return \Tmdb\Model\Common\GenericCollection + */ + public function getTvChanges(ChangesQuery $query, array $headers = array()) + { + $data = $this->getApi()->getTvChanges($query->toArray(), $headers); + + return $this->getFactory()->createResultCollection($data); + } + /** * Return the related API class * diff --git a/lib/Tmdb/Repository/CompanyRepository.php b/lib/Tmdb/Repository/CompanyRepository.php index a7538250..2f650137 100644 --- a/lib/Tmdb/Repository/CompanyRepository.php +++ b/lib/Tmdb/Repository/CompanyRepository.php @@ -15,9 +15,7 @@ use Tmdb\Factory\CompanyFactory; use Tmdb\Factory\MovieFactory; use Tmdb\Model\Collection\ResultCollection; -use Tmdb\Model\Common\GenericCollection; use Tmdb\Model\Company; -use Tmdb\Model\Movie; /** * Class CompanyRepository @@ -44,10 +42,10 @@ public function load($id, array $parameters = array(), array $headers = array()) /** * Get the list of movies associated with a particular company. * - * @param integer $id - * @param array $parameters - * @param array $headers - * @return GenericCollection|Movie[] + * @param integer $id + * @param array $parameters + * @param array $headers + * @return ResultCollection */ public function getMovies($id, array $parameters = array(), array $headers = array()) { @@ -86,7 +84,7 @@ public function getMovieFactory() * Create an collection of an array * * @param $data - * @return Movie[] + * @return ResultCollection */ public function createMovieCollection($data) { diff --git a/lib/Tmdb/Repository/CreditsRepository.php b/lib/Tmdb/Repository/CreditsRepository.php index 63c79688..e68c4e3e 100644 --- a/lib/Tmdb/Repository/CreditsRepository.php +++ b/lib/Tmdb/Repository/CreditsRepository.php @@ -12,9 +12,7 @@ */ namespace Tmdb\Repository; -use Tmdb\Factory\CompanyFactory; use Tmdb\Factory\CreditsFactory; -use Tmdb\Model\Company; /** * Class CreditsRepository @@ -49,7 +47,7 @@ public function getApi() } /** - * @return CompanyFactory + * @return CreditsFactory */ public function getFactory() { diff --git a/lib/Tmdb/Repository/DiscoverRepository.php b/lib/Tmdb/Repository/DiscoverRepository.php index 6d7ec6c6..f9804677 100644 --- a/lib/Tmdb/Repository/DiscoverRepository.php +++ b/lib/Tmdb/Repository/DiscoverRepository.php @@ -16,10 +16,8 @@ use Tmdb\Exception\RuntimeException; use Tmdb\Factory\MovieFactory; use Tmdb\Factory\TvFactory; -use Tmdb\Model\Movie; use Tmdb\Model\Query\Discover\DiscoverMoviesQuery; use Tmdb\Model\Query\Discover\DiscoverTvQuery; -use Tmdb\Model\Tv; /** * Class DiscoverRepository @@ -56,10 +54,9 @@ public function discoverMovies(DiscoverMoviesQuery $query, array $headers = arra * Discover TV shows by different types of data like average rating, * number of votes, genres, the network they aired on and air dates. * - * @param DiscoverTvQuery $query - * @param array $headers + * @param DiscoverTvQuery $query + * @param array $headers * @return Tv[] - * @return \Tmdb\Model\Common\GenericCollection */ public function discoverTv(DiscoverTvQuery $query, array $headers = array()) { diff --git a/lib/Tmdb/Repository/GenreRepository.php b/lib/Tmdb/Repository/GenreRepository.php index 96e171a2..04b9196c 100644 --- a/lib/Tmdb/Repository/GenreRepository.php +++ b/lib/Tmdb/Repository/GenreRepository.php @@ -56,8 +56,8 @@ public function loadCollection(array $parameters = array(), array $headers = arr * * @param $id * @param array $parameters - * @param array $headers * @return Genre[] + * @param array $headers */ public function getMovies($id, array $parameters = array(), array $headers = array()) { @@ -71,7 +71,7 @@ public function getMovies($id, array $parameters = array(), array $headers = arr * Create an collection of an array * * @param $data - * @return GenericCollection|Genre[] + * @return \Tmdb\Model\Collection\Genres */ private function createCollection($data) { diff --git a/lib/Tmdb/Repository/MovieRepository.php b/lib/Tmdb/Repository/MovieRepository.php index 88e6da27..7c67f018 100644 --- a/lib/Tmdb/Repository/MovieRepository.php +++ b/lib/Tmdb/Repository/MovieRepository.php @@ -69,9 +69,9 @@ public function load($id, array $parameters = array(), array $headers = array()) AppendToResponse::LISTS, AppendToResponse::RELEASES, AppendToResponse::REVIEWS, - AppendToResponse::SIMILAR_MOVIES, - AppendToResponse::TRAILERS, + AppendToResponse::SIMILAR, AppendToResponse::TRANSLATIONS, + AppendToResponse::VIDEOS, )) ); } @@ -161,22 +161,6 @@ public function getReleases($id, array $parameters = array(), array $headers = a return $movie->getReleases(); } - /** - * Get the trailers for a specific movie id. - * - * @param $id - * @param $parameters - * @param $headers - * @return null|\Tmdb\Model\AbstractModel - */ - public function getTrailers($id, array $parameters = array(), array $headers = array()) - { - $data = $this->getApi()->getTrailers($id, $this->parseQueryParameters($parameters), $headers); - $movie = $this->getFactory()->create(array('trailers' => $data)); - - return $movie->getTrailers(); - } - /** * Get the translations for a specific movie id. * @@ -425,7 +409,7 @@ private function createCollection($data) } /** - * @param mixed $alternativeTitleFactory + * @param AlternativeTitleFactory $alternativeTitleFactory * @return $this */ public function setAlternativeTitleFactory($alternativeTitleFactory) @@ -436,7 +420,7 @@ public function setAlternativeTitleFactory($alternativeTitleFactory) } /** - * @return mixed + * @return AlternativeTitleFactory */ public function getAlternativeTitleFactory() { @@ -444,7 +428,7 @@ public function getAlternativeTitleFactory() } /** - * @param mixed $imageFactory + * @param ImageFactory $imageFactory * @return $this */ public function setImageFactory($imageFactory) @@ -455,7 +439,7 @@ public function setImageFactory($imageFactory) } /** - * @return mixed + * @return ImageFactory */ public function getImageFactory() { @@ -463,7 +447,7 @@ public function getImageFactory() } /** - * @param mixed $peopleFactory + * @param PeopleFactory $peopleFactory * @return $this */ public function setPeopleFactory($peopleFactory) @@ -474,7 +458,7 @@ public function setPeopleFactory($peopleFactory) } /** - * @return mixed + * @return PeopleFactory */ public function getPeopleFactory() { diff --git a/lib/Tmdb/Repository/PeopleRepository.php b/lib/Tmdb/Repository/PeopleRepository.php index 15b24dfa..0f7b7add 100644 --- a/lib/Tmdb/Repository/PeopleRepository.php +++ b/lib/Tmdb/Repository/PeopleRepository.php @@ -12,6 +12,7 @@ */ namespace Tmdb\Repository; +use Tmdb\Factory\ImageFactory; use Tmdb\Factory\PeopleFactory; use Tmdb\Model\Person; use Tmdb\Model\Person\QueryParameter\AppendToResponse; @@ -61,7 +62,7 @@ public function load($id, array $parameters = array(), array $headers = array()) * @param $id * @param $parameters * @param $headers - * @return null|\Tmdb\Model\AbstractModel + * @return \Tmdb\Model\Collection\CreditsCollection\MovieCredits */ public function getMovieCredits($id, array $parameters = array(), array $headers = array()) { @@ -82,7 +83,7 @@ public function getMovieCredits($id, array $parameters = array(), array $headers * @param $id * @param $parameters * @param $headers - * @return null|\Tmdb\Model\AbstractModel + * @return \Tmdb\Model\Collection\CreditsCollection\TvCredits */ public function getTvCredits($id, array $parameters = array(), array $headers = array()) { @@ -103,7 +104,7 @@ public function getTvCredits($id, array $parameters = array(), array $headers = * @param $id * @param $parameters * @param $headers - * @return null|\Tmdb\Model\AbstractModel + * @return \Tmdb\Model\Collection\CreditsCollection\CombinedCredits */ public function getCombinedCredits($id, array $parameters = array(), array $headers = array()) { @@ -117,7 +118,7 @@ public function getCombinedCredits($id, array $parameters = array(), array $head * Get the external ids for a specific person id. * * @param $id - * @return null|\Tmdb\Model\AbstractModel + * @return \Tmdb\Model\Common\ExternalIds */ public function getExternalIds($id) { @@ -131,7 +132,7 @@ public function getExternalIds($id) * Get the images for a specific person id. * * @param $id - * @return null|\Tmdb\Model\AbstractModel + * @return \Tmdb\Model\Collection\Images */ public function getImages($id) { @@ -151,9 +152,9 @@ public function getImages($id) * The language is present on fields that are translatable. * * @param $id - * @param array $parameters - * @param array $headers - * @return null|\Tmdb\Model\AbstractModel + * @param array $parameters + * @param array $headers + * @return \Tmdb\Model\Common\GenericCollection */ public function getChanges($id, array $parameters = array(), array $headers = array()) { @@ -173,16 +174,17 @@ public function getChanges($id, array $parameters = array(), array $headers = ar * The language is present on fields that are translatable. * * @param $id - * @param array $parameters - * @param array $headers - * @return null|\Tmdb\Model\AbstractModel + * @param array $parameters + * @param array $headers + * @return \Tmdb\Model\Collection\ResultCollection */ public function getTaggedImages($id, array $parameters = array(), array $headers = array()) { - $data = $this->getApi()->getTaggedImages($id, $this->parseQueryParameters($parameters), $headers); - $person = $this->getFactory()->create(array('tagged_images' => $data)); + $data = $this->getApi()->getTaggedImages($id, $this->parseQueryParameters($parameters), $headers); - return $person->getTaggedImages(); + $factory = new ImageFactory(); + + return $factory->createResultCollection($data, 'createMediaImage'); } /** @@ -190,9 +192,9 @@ public function getTaggedImages($id, array $parameters = array(), array $headers * * This list refreshes every day. * - * @param array $parameters - * @param array $headers - * @return null|\Tmdb\Model\AbstractModel + * @param array $parameters + * @param array $headers + * @return \Tmdb\Model\Collection\ResultCollection */ public function getPopular(array $parameters = array(), array $headers = array()) { @@ -204,7 +206,7 @@ public function getPopular(array $parameters = array(), array $headers = array() /** * Get the latest person id. * - * @return null|\Tmdb\Model\AbstractModel + * @return Person */ public function getLatest() { diff --git a/lib/Tmdb/Repository/SearchRepository.php b/lib/Tmdb/Repository/SearchRepository.php index 3f7d71cd..d17bd1b7 100644 --- a/lib/Tmdb/Repository/SearchRepository.php +++ b/lib/Tmdb/Repository/SearchRepository.php @@ -22,7 +22,6 @@ use Tmdb\Factory\PeopleFactory; use Tmdb\Factory\TvFactory; use Tmdb\Model\Collection\ResultCollection; -use Tmdb\Model\Collection; use Tmdb\Model\Company; use Tmdb\Model\Keyword; use Tmdb\Model\Movie; @@ -111,7 +110,7 @@ public function searchMovie($query, MovieSearchQuery $parameters, array $headers * @param CollectionSearchQuery $parameters * @param array $headers * - * @return ResultCollection|Collection[] + * @return ResultCollection[] */ public function searchCollection($query, CollectionSearchQuery $parameters, array $headers = array()) { @@ -190,6 +189,73 @@ public function searchKeyword($query, KeywordSearchQuery $parameters, array $hea return $this->getKeywordFactory()->createResultCollection($data); } + /** + * @param string $query + * @param KeywordSearchQuery $parameters + * @param array $headers + * + * @return ResultCollection|Keyword[] + */ + public function searchMulti($query, KeywordSearchQuery $parameters, array $headers = array()) + { + $data = $this->getApi()->searchMulti($query, $this->getParameters($parameters), $headers); + $collection = new ResultCollection(); + + if (null === $data) { + return $collection; + } + + if (array_key_exists('page', $data)) { + $collection->setPage($data['page']); + } + + if (array_key_exists('total_pages', $data)) { + $collection->setTotalPages($data['total_pages']); + } + + if (array_key_exists('total_results', $data)) { + $collection->setTotalResults($data['total_results']); + } + + if (array_key_exists('results', $data)) { + foreach ($data['results'] as $item) { + if ($item) { + $collection->add(null, $this->processSearchMultiItem($item)); + } + } + } + + return $collection; + } + + /** + * Process multi search items + * + * @param array $item + * @return bool|Movie|Person|Person\CastMember|Person\CrewMember|Tv + * @throws \RuntimeException + */ + private function processSearchMultiItem(array $item) + { + if (array_key_exists('media_type', $item)) { + switch ($item['media_type']) { + case 'movie': + return $this->getMovieFactory()->create($item); + case 'tv': + return $this->getTvFactory()->create($item); + case 'person': + return $this->getPeopleFactory()->create($item); + default: + throw new \RuntimeException(sprintf( + 'Could not process media_type "%s" in multi search, type unknown.', + $item['media_type'] + )); + } + } + + return false; + } + /** * Convert parameters back to an array * diff --git a/lib/Tmdb/Repository/TvEpisodeRepository.php b/lib/Tmdb/Repository/TvEpisodeRepository.php index d639b0e0..086b4d21 100644 --- a/lib/Tmdb/Repository/TvEpisodeRepository.php +++ b/lib/Tmdb/Repository/TvEpisodeRepository.php @@ -15,7 +15,9 @@ use Tmdb\Exception\RuntimeException; use Tmdb\Factory\TvEpisodeFactory; use Tmdb\Model\Collection\Videos; +use Tmdb\Model\Common\AccountStates; use Tmdb\Model\Common\Video; +use Tmdb\Model\Lists\Result; use Tmdb\Model\Tv\Episode\QueryParameter\AppendToResponse; use Tmdb\Model\Tv; use Tmdb\Model\Tv\Season; @@ -232,6 +234,66 @@ public function getVideos($tvShow, $season, $episode, array $parameters = array( return $episode->getVideos(); } + /** + * This method lets users get the status of whether or not the TV show has been rated + * or added to their favourite or watch lists. + * + * A valid session id is required. + * + * @param mixed $tvShow + * @param mixed $season + * @param mixed $episode + * @return AccountStates + */ + public function getAccountStates($tvShow, $season, $episode) + { + if ($tvShow instanceof Tv) { + $tvShow = $tvShow->getId(); + } + + if ($season instanceof Season) { + $season = $season->getId(); + } + + if ($episode instanceof Tv\Episode) { + $episode = $episode->getId(); + } + + return $this->getFactory()->createAccountStates( + $this->getApi()->getAccountStates($tvShow, $season, $episode) + ); + } + + /** + * This method lets users rate a TV show. + * + * A valid session id or guest session id is required. + * + * @param mixed $tvShow + * @param mixed $season + * @param mixed $episode + * @param double $rating + * @return Result + */ + public function rate($tvShow, $season, $episode, $rating) + { + if ($tvShow instanceof Tv) { + $tvShow = $tvShow->getId(); + } + + if ($season instanceof Season) { + $season = $season->getId(); + } + + if ($episode instanceof Tv\Episode) { + $episode = $episode->getId(); + } + + return $this->getFactory()->createResult( + $this->getApi()->rateTvEpisode($tvShow, $season, $episode, $rating) + ); + } + /** * Return the Seasons API Class * diff --git a/lib/Tmdb/Repository/TvRepository.php b/lib/Tmdb/Repository/TvRepository.php index a11dc3da..d20b68c6 100644 --- a/lib/Tmdb/Repository/TvRepository.php +++ b/lib/Tmdb/Repository/TvRepository.php @@ -14,7 +14,9 @@ use Tmdb\Factory\TvFactory; use Tmdb\Model\Collection\Videos; +use Tmdb\Model\Common\AccountStates; use Tmdb\Model\Common\Video; +use Tmdb\Model\Lists\Result; use Tmdb\Model\Tv; use Tmdb\Model\Tv\QueryParameter\AppendToResponse; @@ -232,4 +234,36 @@ public function getLatest(array $options = array()) $this->getApi()->getLatest($options) ); } + + /** + * This method lets users get the status of whether or not the TV show has been rated + * or added to their favourite or watch lists. + * + * A valid session id is required. + * + * @param integer $id + * @return AccountStates + */ + public function getAccountStates($id) + { + return $this->getFactory()->createAccountStates( + $this->getApi()->getAccountStates($id) + ); + } + + /** + * This method lets users rate a TV show. + * + * A valid session id or guest session id is required. + * + * @param integer $id + * @param float $rating + * @return Result + */ + public function rate($id, $rating) + { + return $this->getFactory()->createResult( + $this->getApi()->rateTvShow($id, $rating) + ); + } } diff --git a/lib/Tmdb/Repository/TvSeasonRepository.php b/lib/Tmdb/Repository/TvSeasonRepository.php index 7937ea95..4ecd3936 100644 --- a/lib/Tmdb/Repository/TvSeasonRepository.php +++ b/lib/Tmdb/Repository/TvSeasonRepository.php @@ -14,7 +14,6 @@ use Tmdb\Exception\RuntimeException; use Tmdb\Factory\TvSeasonFactory; - use Tmdb\Model\Collection\Videos; use Tmdb\Model\Common\Video; use \Tmdb\Model\Tv\Season\QueryParameter\AppendToResponse; diff --git a/lib/Tmdb/RequestToken.php b/lib/Tmdb/RequestToken.php index f791a8a0..025041d7 100644 --- a/lib/Tmdb/RequestToken.php +++ b/lib/Tmdb/RequestToken.php @@ -59,7 +59,7 @@ public function setToken($token) } /** - * @return null + * @return string */ public function getToken() { @@ -67,7 +67,7 @@ public function getToken() } /** - * @param mixed $expiresAt + * @param \DateTime $expiresAt * @return $this */ public function setExpiresAt($expiresAt) @@ -82,7 +82,7 @@ public function setExpiresAt($expiresAt) } /** - * @return mixed + * @return \DateTime */ public function getExpiresAt() { diff --git a/lib/Tmdb/SessionToken.php b/lib/Tmdb/SessionToken.php index 093e0132..8cc5ee10 100644 --- a/lib/Tmdb/SessionToken.php +++ b/lib/Tmdb/SessionToken.php @@ -29,7 +29,7 @@ class SessionToken private $expiresAt; /** - * @var bool + * @var boolean */ private $success; @@ -55,7 +55,7 @@ public function setToken($sessionToken) } /** - * @return null + * @return string */ public function getToken() { @@ -86,7 +86,7 @@ public function getExpiresAt() } /** - * @param mixed $success + * @param boolean $success * @return $this */ public function setSuccess($success) @@ -97,7 +97,7 @@ public function setSuccess($success) } /** - * @return mixed + * @return boolean */ public function getSuccess() { diff --git a/test/Tmdb/Tests/Api/ChangesTest.php b/test/Tmdb/Tests/Api/ChangesTest.php index 7535bc2b..60db22f2 100644 --- a/test/Tmdb/Tests/Api/ChangesTest.php +++ b/test/Tmdb/Tests/Api/ChangesTest.php @@ -40,6 +40,19 @@ public function shouldGetPersonChanges() $api->getPersonChanges(); } + /** + * @test + */ + public function shouldGetTvChanges() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('tv/changes'); + + $api->getTvChanges(); + } + protected function getApiClass() { return 'Tmdb\Api\Changes'; diff --git a/test/Tmdb/Tests/Api/SearchTest.php b/test/Tmdb/Tests/Api/SearchTest.php index 278a4a3f..cf6f8cce 100644 --- a/test/Tmdb/Tests/Api/SearchTest.php +++ b/test/Tmdb/Tests/Api/SearchTest.php @@ -113,6 +113,19 @@ public function shouldSearchKeyword() $api->searchKeyword(self::QUERY_KEYWORD); } + /** + * @test + */ + public function shouldSearchMulti() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('search/multi', array('query' => urlencode(self::QUERY_KEYWORD))); + + $api->searchMulti(self::QUERY_KEYWORD); + } + protected function getApiClass() { return 'Tmdb\Api\Search'; diff --git a/test/Tmdb/Tests/Factory/AuthenticationFactoryTest.php b/test/Tmdb/Tests/Factory/AuthenticationFactoryTest.php index 839775e0..48acfbe4 100644 --- a/test/Tmdb/Tests/Factory/AuthenticationFactoryTest.php +++ b/test/Tmdb/Tests/Factory/AuthenticationFactoryTest.php @@ -68,7 +68,7 @@ public function shouldCreateGuestSessionToken() /** * @test - * @expectedException \Tmdb\Exception\NotImplementedException + * @expectedException \RuntimeException */ public function shouldThrowExceptionForCreate() { @@ -82,7 +82,7 @@ public function shouldThrowExceptionForCreate() /** * @test - * @expectedException \Tmdb\Exception\NotImplementedException + * @expectedException \RuntimeException */ public function shouldThrowExceptionForCreateCollection() { diff --git a/test/Tmdb/Tests/Factory/FindFactoryTest.php b/test/Tmdb/Tests/Factory/FindFactoryTest.php index b044f799..4bb4f970 100644 --- a/test/Tmdb/Tests/Factory/FindFactoryTest.php +++ b/test/Tmdb/Tests/Factory/FindFactoryTest.php @@ -67,7 +67,7 @@ public function shouldBeAbleToSetFactories() /** * @test - * @expectedException Tmdb\Exception\NotImplementedException + * @expectedException \RuntimeException */ public function shouldThrowExceptionForCreateCollection() { diff --git a/test/Tmdb/Tests/Factory/MovieFactoryTest.php b/test/Tmdb/Tests/Factory/MovieFactoryTest.php index 4380696e..01dc88f5 100644 --- a/test/Tmdb/Tests/Factory/MovieFactoryTest.php +++ b/test/Tmdb/Tests/Factory/MovieFactoryTest.php @@ -103,7 +103,7 @@ public function shouldBeFunctional() $this->assertInstanceOf('Tmdb\Model\Common\GenericCollection', $this->movie->getLists()); $this->assertInstanceOf('Tmdb\Model\Common\GenericCollection', $this->movie->getReleases()); $this->assertInstanceOf('Tmdb\Model\Common\GenericCollection', $this->movie->getSimilar()); - $this->assertInstanceOf('Tmdb\Model\Common\GenericCollection', $this->movie->getTrailers()); + $this->assertInstanceOf('Tmdb\Model\Collection\Videos', $this->movie->getVideos()); } /** diff --git a/test/Tmdb/Tests/Model/MovieTest.php b/test/Tmdb/Tests/Model/MovieTest.php index 65f7c7f6..7f6befbd 100644 --- a/test/Tmdb/Tests/Model/MovieTest.php +++ b/test/Tmdb/Tests/Model/MovieTest.php @@ -41,7 +41,6 @@ public function shouldConstructMovie() 'getLists' => 'Tmdb\Model\Common\GenericCollection', 'getReleases' => 'Tmdb\Model\Common\GenericCollection', 'getSimilar' => 'Tmdb\Model\Common\GenericCollection', - 'getTrailers' => 'Tmdb\Model\Common\GenericCollection', 'getTranslations' => 'Tmdb\Model\Common\GenericCollection', 'getVideos' => 'Tmdb\Model\Collection\Videos', ) diff --git a/test/Tmdb/Tests/Model/PersonTest.php b/test/Tmdb/Tests/Model/PersonTest.php index 0032f117..cfc1872d 100644 --- a/test/Tmdb/Tests/Model/PersonTest.php +++ b/test/Tmdb/Tests/Model/PersonTest.php @@ -27,7 +27,6 @@ public function shouldConstructPersons() $this->assertInstancesOf( $person, array( - 'getCredits' => 'Tmdb\Model\Collection\CreditsCollection', 'getImages' => 'Tmdb\Model\Collection\Images', 'getChanges' => 'Tmdb\Model\Common\GenericCollection', 'getCombinedCredits' => 'Tmdb\Model\Collection\CreditsCollection\CombinedCredits', @@ -65,14 +64,12 @@ public function shouldAllowOverridingDefaultCollectionObjects() $className = get_class($class); $movie->setChanges($class); - $movie->setCredits($class); $this->assertInstancesOf( $movie, array( /** Constructor */ - 'getChanges' => $className, - 'getCredits' => $className + 'getChanges' => $className ) ); } diff --git a/test/Tmdb/Tests/Model/TvTest.php b/test/Tmdb/Tests/Model/TvTest.php index d44c82ab..62660eb7 100644 --- a/test/Tmdb/Tests/Model/TvTest.php +++ b/test/Tmdb/Tests/Model/TvTest.php @@ -26,10 +26,10 @@ public function shouldConstructMovie() $this->assertInstancesOf( $tv, array( - 'getCreatedBy' => 'Tmdb\Model\Collection\Images', - 'getEpisodeRuntime' => 'Tmdb\Model\Common\GenericCollection', +// 'getCreatedBy' => 'Tmdb\Model\Collection\Images', +// 'getEpisodeRuntime' => 'Tmdb\Model\Common\GenericCollection', 'getGenres' => 'Tmdb\Model\Collection\Genres', - 'getLanguages' => 'Tmdb\Model\Common\GenericCollection', +// 'getLanguages' => 'Tmdb\Model\Common\GenericCollection', 'getNetworks' => 'Tmdb\Model\Common\GenericCollection', 'getOriginCountry' => 'Tmdb\Model\Common\GenericCollection', 'getSeasons' => 'Tmdb\Model\Common\GenericCollection', diff --git a/test/Tmdb/Tests/Repository/ChangesRepositoryTest.php b/test/Tmdb/Tests/Repository/ChangesRepositoryTest.php index 9dce2e27..bac50347 100644 --- a/test/Tmdb/Tests/Repository/ChangesRepositoryTest.php +++ b/test/Tmdb/Tests/Repository/ChangesRepositoryTest.php @@ -40,6 +40,18 @@ public function shouldGetPeopleChanges() $repository->getPeopleChanges($query); } + /** + * @test + */ + public function shouldGetTvChanges() + { + $repository = $this->getRepositoryWithMockedHttpClient(); + + $query = new ChangesQuery(); + + $repository->getTvChanges($query); + } + protected function getApiClass() { return 'Tmdb\Api\Changes'; diff --git a/test/Tmdb/Tests/Repository/MovieRepositoryTest.php b/test/Tmdb/Tests/Repository/MovieRepositoryTest.php index 885a528d..91dc045a 100644 --- a/test/Tmdb/Tests/Repository/MovieRepositoryTest.php +++ b/test/Tmdb/Tests/Repository/MovieRepositoryTest.php @@ -78,16 +78,6 @@ public function shouldGetReleases() $repository->getReleases(self::MOVIE_ID); } - /** - * @test - */ - public function shouldGetTrailers() - { - $repository = $this->getRepositoryWithMockedHttpClient(); - - $repository->getTrailers(self::MOVIE_ID); - } - /** * @test */ diff --git a/test/Tmdb/Tests/Repository/SearchRepositoryTest.php b/test/Tmdb/Tests/Repository/SearchRepositoryTest.php index 4bf137f3..31b9f3d5 100644 --- a/test/Tmdb/Tests/Repository/SearchRepositoryTest.php +++ b/test/Tmdb/Tests/Repository/SearchRepositoryTest.php @@ -114,6 +114,19 @@ public function shouldSearchKeyword() $repository->searchKeyword('alien', new KeywordSearchQuery()); } + /** + * @test + */ + public function shouldSearchMulti() + { + /** + * @var SearchRepository $repository + */ + $repository = $this->getRepositoryWithMockedHttpClient(); + + $repository->searchKeyword('jack', new KeywordSearchQuery()); + } + /** * @test * @expectedException Tmdb\Exception\NotImplementedException