Skip to content

Commit

Permalink
Fix bug in the account_states returned value and fixing some issues w…
Browse files Browse the repository at this point in the history
…ith the account related functions for tv episodes.
  • Loading branch information
wtfzdotnet committed Jul 13, 2014
1 parent b18e1fe commit cd587ec
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 17 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion examples/tv/api/episode/account_states.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
2 changes: 1 addition & 1 deletion examples/tv/api/episode/rate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
2 changes: 1 addition & 1 deletion examples/tv/model/episode/rate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
8 changes: 4 additions & 4 deletions lib/Tmdb/Api/TvEpisode.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public function getAccountStates(
*
* @return mixed
*/
public function rate(
public function rateTvEpisode(
$tvshow_id,
$season_number,
$episode_number,
Expand All @@ -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)
);
}

Expand Down
8 changes: 6 additions & 2 deletions lib/Tmdb/Factory/AbstractFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
42 changes: 35 additions & 7 deletions lib/Tmdb/Repository/TvEpisodeRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}

Expand All @@ -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)
);
}

Expand Down

0 comments on commit cd587ec

Please sign in to comment.