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/tv/api/episode/account_states.php b/examples/tv/api/episode/account_states.php index f34fc976..3fac86b5 100644 --- a/examples/tv/api/episode/account_states.php +++ b/examples/tv/api/episode/account_states.php @@ -19,6 +19,6 @@ $sessionToken = new \Tmdb\SessionToken(TMDB_SESSION_TOKEN); $client->setSessionToken($sessionToken); -$result = $client->getTvApi()->getAccountStates(1396, 1, 1); +$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 index d626ae46..6f4e40aa 100644 --- a/examples/tv/api/episode/rate.php +++ b/examples/tv/api/episode/rate.php @@ -20,6 +20,6 @@ $sessionToken = new \Tmdb\SessionToken(TMDB_SESSION_TOKEN); $client->setSessionToken($sessionToken); -$result = $client->getTvApi()->rateTvShow(1396, 1, 1, 9.5); +$result = $client->getTvEpisodeApi()->rateTvEpisode(1396, 1, 1, 9.5); var_dump($result); diff --git a/examples/tv/model/episode/rate.php b/examples/tv/model/episode/rate.php index cb7685f1..2b55f280 100644 --- a/examples/tv/model/episode/rate.php +++ b/examples/tv/model/episode/rate.php @@ -21,6 +21,6 @@ $client->setSessionToken($sessionToken); $repository = new \Tmdb\Repository\TvEpisodeRepository($client); -$rate = $repository->rate(1396, 1, 9.5); +$rate = $repository->rate(1396, 1, 1, 9.5); var_dump($rate); diff --git a/lib/Tmdb/Api/TvEpisode.php b/lib/Tmdb/Api/TvEpisode.php index 3951e531..fb27a400 100644 --- a/lib/Tmdb/Api/TvEpisode.php +++ b/lib/Tmdb/Api/TvEpisode.php @@ -234,7 +234,7 @@ public function getAccountStates( * * @return mixed */ - public function rate( + public function rateTvEpisode( $tvshow_id, $season_number, $episode_number, @@ -245,9 +245,9 @@ public function rate( 'tv/%s/season/%s/episode/%s/rating', $tvshow_id, $season_number, - $episode_number, - array('value' => (float) $rating) - ) + $episode_number + ), + array('value' => (float) $rating) ); } diff --git a/lib/Tmdb/Factory/AbstractFactory.php b/lib/Tmdb/Factory/AbstractFactory.php index dc8c4fe6..fa21a6f0 100644 --- a/lib/Tmdb/Factory/AbstractFactory.php +++ b/lib/Tmdb/Factory/AbstractFactory.php @@ -153,9 +153,13 @@ public function createAccountStates(array $data = array()) $accountStates = new AccountStates(); if (array_key_exists('rated', $data)) { - $rating = new Rating(); + if ($data['rated']) { + $rating = new Rating(); - $accountStates->setRated($this->hydrate($rating, $data['rated'])); + $accountStates->setRated($this->hydrate($rating, $data['rated'])); + } else { + $accountStates->setRated(false); + } } return $this->hydrate($accountStates, $data); diff --git a/lib/Tmdb/Repository/TvEpisodeRepository.php b/lib/Tmdb/Repository/TvEpisodeRepository.php index e74ae19b..086b4d21 100644 --- a/lib/Tmdb/Repository/TvEpisodeRepository.php +++ b/lib/Tmdb/Repository/TvEpisodeRepository.php @@ -240,13 +240,27 @@ public function getVideos($tvShow, $season, $episode, array $parameters = array( * * A valid session id is required. * - * @param integer $id + * @param mixed $tvShow + * @param mixed $season + * @param mixed $episode * @return AccountStates */ - public function getAccountStates($id) + 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($id) + $this->getApi()->getAccountStates($tvShow, $season, $episode) ); } @@ -255,14 +269,28 @@ public function getAccountStates($id) * * A valid session id or guest session id is required. * - * @param integer $id - * @param float $rating + * @param mixed $tvShow + * @param mixed $season + * @param mixed $episode + * @param double $rating * @return Result */ - public function rate($id, $rating) + 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($id, $rating) + $this->getApi()->rateTvEpisode($tvShow, $season, $episode, $rating) ); }