forked from php-tmdb/api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented first citizen for GuestSession's, fixes php-tmdb#20
- Loading branch information
1 parent
d458133
commit 78864fd
Showing
15 changed files
with
356 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
/** | ||
* This file is part of the Tmdb PHP API created by Michael Roterman. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @package Tmdb | ||
* @author Michael Roterman <[email protected]> | ||
* @copyright (c) 2013, Michael Roterman | ||
* @version 0.0.1 | ||
*/ | ||
require_once '../../../vendor/autoload.php'; | ||
require_once '../../../apikey.php'; | ||
|
||
$token = new \Tmdb\ApiToken(TMDB_API_KEY); | ||
$client = new \Tmdb\Client($token); | ||
|
||
$sessionToken = new \Tmdb\GuestSessionToken(TMDB_GUEST_SESSION_TOKEN); | ||
$client->setSessionToken($sessionToken); | ||
|
||
$rated_movies = $client->getGuestSessionApi()->getRatedMovies(); | ||
|
||
var_dump($rated_movies); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
/** | ||
* This file is part of the Tmdb PHP API created by Michael Roterman. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @package Tmdb | ||
* @author Michael Roterman <[email protected]> | ||
* @copyright (c) 2013, Michael Roterman | ||
* @version 0.0.1 | ||
*/ | ||
require_once '../../../vendor/autoload.php'; | ||
require_once '../../../apikey.php'; | ||
|
||
$token = new \Tmdb\ApiToken(TMDB_API_KEY); | ||
$client = new \Tmdb\Client($token); | ||
|
||
$guestSessionToken = new \Tmdb\GuestSessionToken(TMDB_GUEST_SESSION_TOKEN); | ||
$client->setSessionToken($guestSessionToken); | ||
|
||
/** | ||
* @var \Tmdb\Repository\GuestSessionRepository $guestSessionRepository | ||
*/ | ||
$guestSessionRepository = new \Tmdb\Repository\GuestSessionRepository($client); | ||
$lists = $guestSessionRepository->getRatedMovies(); | ||
|
||
var_dump($lists); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
/** | ||
* This file is part of the Tmdb PHP API created by Michael Roterman. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @package Tmdb | ||
* @author Michael Roterman <[email protected]> | ||
* @copyright (c) 2013, Michael Roterman | ||
* @version 0.0.1 | ||
*/ | ||
namespace Tmdb\Api; | ||
use Tmdb\Exception\MissingSessionTokenException; | ||
use Tmdb\SessionToken; | ||
|
||
/** | ||
* Class GuestSession | ||
* @package Tmdb\Api | ||
* @see http://docs.themoviedb.apiary.io/#guestsessions | ||
*/ | ||
class GuestSession extends AbstractApi | ||
{ | ||
/** | ||
* Get a list of rated movies for a specific guest session id. | ||
* | ||
* @param array $parameters | ||
* @param array $headers | ||
* @throws MissingSessionTokenException when the guest session token was not set on the client. | ||
* @return mixed | ||
*/ | ||
public function getRatedMovies(array $parameters = array(), array $headers = array()) | ||
{ | ||
$sessionToken = $this->client->getSessionToken(); | ||
|
||
if (!$sessionToken instanceof SessionToken) { | ||
throw new MissingSessionTokenException('The guest session token was not set on the client.'); | ||
} | ||
|
||
return $this->get('guest_session/' . $sessionToken->getToken() . '/rated_movies', $parameters, $headers); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
/** | ||
* This file is part of the Tmdb PHP API created by Michael Roterman. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @package Tmdb | ||
* @author Michael Roterman <[email protected]> | ||
* @copyright (c) 2013, Michael Roterman | ||
* @version 0.0.1 | ||
*/ | ||
namespace Tmdb\Exception; | ||
|
||
/** | ||
* Class MissingSessionTokenException | ||
* @package Tmdb\Exception | ||
*/ | ||
class MissingSessionTokenException extends \RuntimeException | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
/** | ||
* This file is part of the Tmdb PHP API created by Michael Roterman. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @package Tmdb | ||
* @author Michael Roterman <[email protected]> | ||
* @copyright (c) 2013, Michael Roterman | ||
* @version 0.0.1 | ||
*/ | ||
namespace Tmdb\Factory; | ||
|
||
/** | ||
* Currently a place-holder for future expansions | ||
* | ||
* Class GuestSessionFactory | ||
* @package Tmdb\Factory | ||
*/ | ||
class GuestSessionFactory extends AbstractFactory | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function create(array $data = array()) | ||
{ | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function createCollection(array $data = array()) | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
/** | ||
* This file is part of the Tmdb PHP API created by Michael Roterman. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @package Tmdb | ||
* @author Michael Roterman <[email protected]> | ||
* @copyright (c) 2013, Michael Roterman | ||
* @version 0.0.1 | ||
*/ | ||
namespace Tmdb; | ||
|
||
/** | ||
* Class GuestSessionToken | ||
* @package Tmdb | ||
*/ | ||
class GuestSessionToken extends SessionToken | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
/** | ||
* This file is part of the Tmdb PHP API created by Michael Roterman. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @package Tmdb | ||
* @author Michael Roterman <[email protected]> | ||
* @copyright (c) 2013, Michael Roterman | ||
* @version 0.0.1 | ||
*/ | ||
namespace Tmdb\Repository; | ||
|
||
use Tmdb\Factory\GuestSessionFactory; | ||
use Tmdb\Factory\MovieFactory; | ||
use Tmdb\Model\Collection\ResultCollection; | ||
use Tmdb\Model\Movie; | ||
|
||
/** | ||
* Class GuestSessionRepository | ||
* @package Tmdb\Repository | ||
* @see http://docs.themoviedb.apiary.io/#guestsessions | ||
*/ | ||
class GuestSessionRepository extends AbstractRepository | ||
{ | ||
/** | ||
* Get the list of top rated movies. | ||
* | ||
* By default, this list will only include movies that have 10 or more votes. | ||
* This list refreshes every day. | ||
* | ||
* @param array $options | ||
* @return ResultCollection|Movie[] | ||
*/ | ||
public function getRatedMovies(array $options = array()) | ||
{ | ||
return $this->getMovieFactory()->createResultCollection( | ||
$this->getApi()->getRatedMovies($options) | ||
); | ||
} | ||
|
||
/** | ||
* Return the Movies API Class | ||
* | ||
* @return \Tmdb\Api\GuestSession | ||
*/ | ||
public function getApi() | ||
{ | ||
return $this->getClient()->getGuestSessionApi(); | ||
} | ||
|
||
/** | ||
* Return the Guest Session Factory | ||
* | ||
* @return GuestSessionFactory | ||
*/ | ||
public function getFactory() | ||
{ | ||
return new GuestSessionFactory(); | ||
} | ||
|
||
/** | ||
* @return MovieFactory | ||
*/ | ||
public function getMovieFactory() | ||
{ | ||
return new MovieFactory(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
/** | ||
* This file is part of the Tmdb PHP API created by Michael Roterman. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @package Tmdb | ||
* @author Michael Roterman <[email protected]> | ||
* @copyright (c) 2013, Michael Roterman | ||
* @version 0.0.1 | ||
*/ | ||
namespace Tmdb\Tests\Api; | ||
|
||
use Tmdb\GuestSessionToken; | ||
|
||
class GuestSessionTest extends TestCase | ||
{ | ||
/** | ||
* @test | ||
* @expectedException Tmdb\Exception\MissingSessionTokenException | ||
*/ | ||
public function shouldThrowExceptionGettingRatedMoviesWithNoSessionToken() | ||
{ | ||
$api = $this->getApiMock(); | ||
$api->getRatedMovies(); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldGetRatedMovies() | ||
{ | ||
$sessionToken = new GuestSessionToken('xyz'); | ||
$api = $this->getApiMock(array(), array(), $sessionToken); | ||
|
||
$api->expects($this->once()) | ||
->method('get') | ||
->with('guest_session/xyz/rated_movies'); | ||
|
||
$api->getRatedMovies(); | ||
} | ||
|
||
protected function getApiClass() | ||
{ | ||
return 'Tmdb\Api\GuestSession'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.