From 41524a55b81180eb029ec51e5054429877a4e859 Mon Sep 17 00:00:00 2001 From: Michael Roterman Date: Mon, 24 Feb 2014 23:13:27 +0100 Subject: [PATCH 01/16] Adding SessionToken and implementing it into the Client --- lib/Tmdb/ApiToken.php | 4 +- lib/Tmdb/Client.php | 25 +++++++++++ lib/Tmdb/HttpClient/Plugin/ApiTokenPlugin.php | 2 +- lib/Tmdb/SessionToken.php | 45 +++++++++++++++++++ test/Tmdb/Tests/ApiTokenTest.php | 6 ++- test/Tmdb/Tests/ClientTest.php | 20 ++++++++- test/Tmdb/Tests/SessionTokenTest.php | 27 +++++++++++ 7 files changed, 123 insertions(+), 6 deletions(-) create mode 100644 lib/Tmdb/SessionToken.php create mode 100644 test/Tmdb/Tests/SessionTokenTest.php diff --git a/lib/Tmdb/ApiToken.php b/lib/Tmdb/ApiToken.php index 9a3343f1..8ab89bc2 100644 --- a/lib/Tmdb/ApiToken.php +++ b/lib/Tmdb/ApiToken.php @@ -29,7 +29,7 @@ public function __construct($api_token = null) * @param null $apiToken * @return $this */ - public function setApiToken($apiToken) + public function setToken($apiToken) { $this->apiToken = $apiToken; return $this; @@ -38,7 +38,7 @@ public function setApiToken($apiToken) /** * @return null */ - public function getApiToken() + public function getToken() { return $this->apiToken; } diff --git a/lib/Tmdb/Client.php b/lib/Tmdb/Client.php index c1900373..5f5498ae 100644 --- a/lib/Tmdb/Client.php +++ b/lib/Tmdb/Client.php @@ -48,6 +48,13 @@ class Client { */ private $token; + /** + * Stores API user session token + * + * @var SessionToken + */ + private $sessionToken; + /** * Whether the request is supposed to use a secure schema * @@ -322,4 +329,22 @@ public function getSecure() { return $this->secure; } + + /** + * @param SessionToken $sessionToken + * @return $this + */ + public function setSessionToken($sessionToken) + { + $this->sessionToken = $sessionToken; + return $this; + } + + /** + * @return SessionToken + */ + public function getSessionToken() + { + return $this->sessionToken; + } } diff --git a/lib/Tmdb/HttpClient/Plugin/ApiTokenPlugin.php b/lib/Tmdb/HttpClient/Plugin/ApiTokenPlugin.php index dad5e992..7a3a5bff 100644 --- a/lib/Tmdb/HttpClient/Plugin/ApiTokenPlugin.php +++ b/lib/Tmdb/HttpClient/Plugin/ApiTokenPlugin.php @@ -37,7 +37,7 @@ public function onBeforeSend(Event $event) { $url = $event['request']->getUrl(true); - $url->getQuery()->set('api_key', $this->token->getApiToken()); + $url->getQuery()->set('api_key', $this->token->getToken()); $event['request']->setUrl($url); } diff --git a/lib/Tmdb/SessionToken.php b/lib/Tmdb/SessionToken.php new file mode 100644 index 00000000..19283f00 --- /dev/null +++ b/lib/Tmdb/SessionToken.php @@ -0,0 +1,45 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb; + +class SessionToken { + private $sessionToken = null; + + /** + * Token bag + * + * @param $session_token + */ + public function __construct($session_token = null) + { + $this->sessionToken = $session_token; + } + + /** + * @param null $sessionToken + * @return $this + */ + public function setToken($sessionToken) + { + $this->sessionToken = $sessionToken; + return $this; + } + + /** + * @return null + */ + public function getToken() + { + return $this->sessionToken; + } +} diff --git a/test/Tmdb/Tests/ApiTokenTest.php b/test/Tmdb/Tests/ApiTokenTest.php index afa4fbe0..f1fc46d6 100644 --- a/test/Tmdb/Tests/ApiTokenTest.php +++ b/test/Tmdb/Tests/ApiTokenTest.php @@ -12,14 +12,16 @@ */ class ApiTokenTest extends \PHPUnit_Framework_TestCase { + const API_TOKEN = 'abcdefg'; + /** * @test */ public function testSetGet() { $token = new \Tmdb\ApiToken(); - $token->setApiToken('abcdefg'); + $token->setToken(self::API_TOKEN); - $this->assertEquals('abcdefg', $token->getApiToken()); + $this->assertEquals(self::API_TOKEN, $token->getToken()); } } diff --git a/test/Tmdb/Tests/ClientTest.php b/test/Tmdb/Tests/ClientTest.php index 3065d6a2..c81c7a45 100644 --- a/test/Tmdb/Tests/ClientTest.php +++ b/test/Tmdb/Tests/ClientTest.php @@ -12,12 +12,21 @@ */ class ClientTest extends \Tmdb\Tests\TestCase { + const API_TOKEN = 'abcdef'; + const SESSION_TOKEN = '80b2bf99520cd795ff54e31af97917bc9e3a7c8c'; + + /** + * @var Tmdb\Client + */ private $client = null; public function setUp() { - $token = new \Tmdb\ApiToken('abcdef'); + $token = new \Tmdb\ApiToken(self::API_TOKEN); + $sessionToken = new \Tmdb\SessionToken(self::SESSION_TOKEN); + $client = new \Tmdb\Client($token); + $client->setSessionToken($sessionToken); $this->client = $client; } @@ -30,6 +39,15 @@ public function shouldNotHaveToPassHttpClientToConstructor() $this->assertInstanceOf('Tmdb\HttpClient\HttpClient', $this->client->getHttpClient()); } + /** + * @test + */ + public function shouldContainSessionToken() + { + $this->assertInstanceOf('Tmdb\SessionToken', $this->client->getSessionToken()); + $this->assertEquals(self::SESSION_TOKEN, $this->client->getSessionToken()->getToken()); + } + /** * @test */ diff --git a/test/Tmdb/Tests/SessionTokenTest.php b/test/Tmdb/Tests/SessionTokenTest.php new file mode 100644 index 00000000..1822902f --- /dev/null +++ b/test/Tmdb/Tests/SessionTokenTest.php @@ -0,0 +1,27 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +class SessionTokenTest extends \PHPUnit_Framework_TestCase +{ + const SESSION_TOKEN = '80b2bf99520cd795ff54e31af97917bc9e3a7c8c'; + + /** + * @test + */ + public function testSetGet() + { + $token = new \Tmdb\SessionToken(); + $token->setToken(self::SESSION_TOKEN); + + $this->assertEquals(self::SESSION_TOKEN, $token->getToken()); + } +} From a8c2cc4678c16e2cf4e6c56aa7a28ca4a9a117b4 Mon Sep 17 00:00:00 2001 From: Michael Roterman Date: Mon, 24 Feb 2014 23:38:51 +0100 Subject: [PATCH 02/16] Added RequestToken in the API and preparing modelling. --- examples/authentication/api/get.php | 21 ++++++ lib/Tmdb/Api/Authentication.php | 18 ++++- lib/Tmdb/Client.php | 2 +- lib/Tmdb/RequestToken.php | 79 ++++++++++++++++++++++ test/Tmdb/Tests/Api/AuthenticationTest.php | 1 - test/Tmdb/Tests/RequestTokenTest.php | 29 ++++++++ 6 files changed, 145 insertions(+), 5 deletions(-) create mode 100644 examples/authentication/api/get.php create mode 100644 lib/Tmdb/RequestToken.php create mode 100644 test/Tmdb/Tests/RequestTokenTest.php diff --git a/examples/authentication/api/get.php b/examples/authentication/api/get.php new file mode 100644 index 00000000..5f9ec2fe --- /dev/null +++ b/examples/authentication/api/get.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); + +$requestToken = $client->getAuthenticationApi()->getNewToken(); + +var_dump($requestToken); \ No newline at end of file diff --git a/lib/Tmdb/Api/Authentication.php b/lib/Tmdb/Api/Authentication.php index 3552404e..34a3625f 100644 --- a/lib/Tmdb/Api/Authentication.php +++ b/lib/Tmdb/Api/Authentication.php @@ -12,11 +12,14 @@ */ namespace Tmdb\Api; +use Tmdb\Client; use Tmdb\Exception\NotImplementedException; class Authentication extends AbstractApi { + const REQUEST_TOKEN_URI = 'https://www.themoviedb.org/authenticate/%s'; + /** * This method is used to generate a valid request token for user based authentication. * A request token is required in order to request a session id. @@ -24,12 +27,21 @@ class Authentication * You can generate any number of request tokens but they will expire after 60 minutes. * As soon as a valid session id has been created the token will be destroyed. * - * @throws NotImplementedException + * @param array $parameters + * @param array $headers * @return mixed */ - public function getNewToken() + public function getNewToken($parameters = array(), $headers = array()) { - throw new NotImplementedException(__METHOD__ . ' has not been implemented yet.'); + return $this->get('authentication/token/new', $parameters, $headers); + } + + public function authenticateRequestToken($token) + { + header(sprintf( + 'Location: %s/%s', + sprintf(self::REQUEST_TOKEN_URI, $token) + )); } /** diff --git a/lib/Tmdb/Client.php b/lib/Tmdb/Client.php index 5f5498ae..f4bbc0f8 100644 --- a/lib/Tmdb/Client.php +++ b/lib/Tmdb/Client.php @@ -303,7 +303,7 @@ public function setHttpClient(HttpClientInterface $httpClient) * * @return string */ - private function getBaseUrl() + public function getBaseUrl() { return sprintf( '%s:%s', diff --git a/lib/Tmdb/RequestToken.php b/lib/Tmdb/RequestToken.php new file mode 100644 index 00000000..551ce954 --- /dev/null +++ b/lib/Tmdb/RequestToken.php @@ -0,0 +1,79 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb; + +class RequestToken { + /** + * The token for obtaining a session + * + * @var string + */ + private $token = null; + + /** + * Expiry date UTC + * + * @var + */ + private $expiresAt; + + /** + * Token bag + * + * @param $request_token + */ + public function __construct($request_token = null) + { + $this->token = $request_token; + } + + /** + * @param null $token + * @return $this + */ + public function setToken($token) + { + $this->token = $token; + return $this; + } + + /** + * @return null + */ + public function getToken() + { + return $this->token; + } + + /** + * @param mixed $expiresAt + * @return $this + */ + public function setExpiresAt($expiresAt) + { + if (!$expiresAt instanceof \DateTime) { + $expiresAt = new \DateTime($expiresAt); + } + + $this->expiresAt = $expiresAt; + return $this; + } + + /** + * @return mixed + */ + public function getExpiresAt() + { + return $this->expiresAt; + } +} diff --git a/test/Tmdb/Tests/Api/AuthenticationTest.php b/test/Tmdb/Tests/Api/AuthenticationTest.php index 49bb1ae2..62a87b9b 100644 --- a/test/Tmdb/Tests/Api/AuthenticationTest.php +++ b/test/Tmdb/Tests/Api/AuthenticationTest.php @@ -16,7 +16,6 @@ class AuthenticationTest extends TestCase { /** * @test - * @expectedException Tmdb\Exception\NotImplementedException */ public function shouldGetNewToken() { diff --git a/test/Tmdb/Tests/RequestTokenTest.php b/test/Tmdb/Tests/RequestTokenTest.php new file mode 100644 index 00000000..28187081 --- /dev/null +++ b/test/Tmdb/Tests/RequestTokenTest.php @@ -0,0 +1,29 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +class RequestTokenTest extends \PHPUnit_Framework_TestCase +{ + const REQUEST_TOKEN = '641bf16c663db167c6cffcdff41126039d4445bf'; + + /** + * @test + */ + public function testSetGet() + { + $token = new \Tmdb\RequestToken(); + $token->setToken(self::REQUEST_TOKEN); + $token->setExpiresAt('2012-02-09 19:50:25 UTC'); + + $this->assertEquals(self::REQUEST_TOKEN, $token->getToken()); + $this->assertInstanceOf('DateTime', $token->getExpiresAt()); + } +} From 2cdb1a797f6ae4e33b1dd1485f5121101312aa79 Mon Sep 17 00:00:00 2001 From: Michael Roterman Date: Tue, 25 Feb 2014 00:36:27 +0100 Subject: [PATCH 03/16] Worked up to acquiring sessions, implementation of account related functions to follow after we get the plugin done. --- .../authentication/api/authenticate-token.php | 21 ++++++++++++ examples/authentication/api/get-session.php | 23 +++++++++++++ .../api/{get.php => get-token.php} | 0 lib/Tmdb/Api/Authentication.php | 33 +++++++++++++------ .../UnauthorizedRequestTokenException.php | 17 ++++++++++ 5 files changed, 84 insertions(+), 10 deletions(-) create mode 100644 examples/authentication/api/authenticate-token.php create mode 100644 examples/authentication/api/get-session.php rename examples/authentication/api/{get.php => get-token.php} (100%) create mode 100644 lib/Tmdb/Exception/UnauthorizedRequestTokenException.php diff --git a/examples/authentication/api/authenticate-token.php b/examples/authentication/api/authenticate-token.php new file mode 100644 index 00000000..6e37987d --- /dev/null +++ b/examples/authentication/api/authenticate-token.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); + +$requestToken = new \Tmdb\RequestToken(TMDB_REQUEST_TOKEN); + +$client->getAuthenticationApi()->authenticateRequestToken($requestToken->getToken()); \ No newline at end of file diff --git a/examples/authentication/api/get-session.php b/examples/authentication/api/get-session.php new file mode 100644 index 00000000..534ab100 --- /dev/null +++ b/examples/authentication/api/get-session.php @@ -0,0 +1,23 @@ + + * @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); + +$requestToken = new \Tmdb\RequestToken(TMDB_REQUEST_TOKEN); + +$sessionToken = $client->getAuthenticationApi()->getNewSession($requestToken->getToken()); + +var_dump($sessionToken); \ No newline at end of file diff --git a/examples/authentication/api/get.php b/examples/authentication/api/get-token.php similarity index 100% rename from examples/authentication/api/get.php rename to examples/authentication/api/get-token.php diff --git a/lib/Tmdb/Api/Authentication.php b/lib/Tmdb/Api/Authentication.php index 34a3625f..d6738de0 100644 --- a/lib/Tmdb/Api/Authentication.php +++ b/lib/Tmdb/Api/Authentication.php @@ -12,13 +12,14 @@ */ namespace Tmdb\Api; -use Tmdb\Client; +use Symfony\Component\Yaml\Exception\RuntimeException; use Tmdb\Exception\NotImplementedException; +use Tmdb\Exception\UnauthorizedRequestTokenException; class Authentication extends AbstractApi { - const REQUEST_TOKEN_URI = 'https://www.themoviedb.org/authenticate/%s'; + const REQUEST_TOKEN_URI = 'https://www.themoviedb.org/authenticate'; /** * This method is used to generate a valid request token for user based authentication. @@ -27,20 +28,24 @@ class Authentication * You can generate any number of request tokens but they will expire after 60 minutes. * As soon as a valid session id has been created the token will be destroyed. * - * @param array $parameters - * @param array $headers * @return mixed */ - public function getNewToken($parameters = array(), $headers = array()) + public function getNewToken() { - return $this->get('authentication/token/new', $parameters, $headers); + return $this->get('authentication/token/new'); } + /** + * Redirect the user to authenticate the request token + * + * @param $token + */ public function authenticateRequestToken($token) { header(sprintf( 'Location: %s/%s', - sprintf(self::REQUEST_TOKEN_URI, $token) + self::REQUEST_TOKEN_URI, + $token )); } @@ -48,12 +53,20 @@ public function authenticateRequestToken($token) * 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. * - * @throws NotImplementedException + * @param string $requestToken + * @throws UnauthorizedRequestTokenException * @return mixed */ - public function getNewSession() + public function getNewSession($requestToken) { - throw new NotImplementedException(__METHOD__ . ' has not been implemented yet.'); + try { + return $this->get('authentication/session/new', array('request_token' => $requestToken)); + } + catch(\Exception $e) { + if ($e->getCode() == 401) { + throw new UnauthorizedRequestTokenException("The request token has not been validated yet."); + } + } } /** diff --git a/lib/Tmdb/Exception/UnauthorizedRequestTokenException.php b/lib/Tmdb/Exception/UnauthorizedRequestTokenException.php new file mode 100644 index 00000000..056557f4 --- /dev/null +++ b/lib/Tmdb/Exception/UnauthorizedRequestTokenException.php @@ -0,0 +1,17 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Exception; + +class UnauthorizedRequestTokenException extends \RuntimeException { + +} From b8f2174349d2d947df01b9e5d3f9c6d76a2638a0 Mon Sep 17 00:00:00 2001 From: Michael Roterman Date: Tue, 25 Feb 2014 00:54:43 +0100 Subject: [PATCH 04/16] Adding guest_session --- .../authentication/api/get-guest-session.php | 21 +++++++++++++++++++ lib/Tmdb/Api/Authentication.php | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 examples/authentication/api/get-guest-session.php diff --git a/examples/authentication/api/get-guest-session.php b/examples/authentication/api/get-guest-session.php new file mode 100644 index 00000000..8712ffb5 --- /dev/null +++ b/examples/authentication/api/get-guest-session.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); + +$sessionToken = $client->getAuthenticationApi()->getNewGuestSession(); + +var_dump($sessionToken); \ No newline at end of file diff --git a/lib/Tmdb/Api/Authentication.php b/lib/Tmdb/Api/Authentication.php index d6738de0..94ac0cb5 100644 --- a/lib/Tmdb/Api/Authentication.php +++ b/lib/Tmdb/Api/Authentication.php @@ -85,6 +85,6 @@ public function getNewSession($requestToken) */ public function getNewGuestSession() { - throw new NotImplementedException(__METHOD__ . ' has not been implemented yet.'); + return $this->get('authentication/guest_session/new'); } } From 401550ba389b588f53f2bfa6bdd42fd0b03cb782 Mon Sep 17 00:00:00 2001 From: Michael Roterman Date: Tue, 25 Feb 2014 01:03:05 +0100 Subject: [PATCH 05/16] First working version of communication with account --- examples/account/api/account.php | 24 ++++++++++ lib/Tmdb/Api/Account.php | 7 +-- lib/Tmdb/Client.php | 6 +++ .../HttpClient/Plugin/SessionTokenPlugin.php | 44 +++++++++++++++++++ 4 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 examples/account/api/account.php create mode 100644 lib/Tmdb/HttpClient/Plugin/SessionTokenPlugin.php diff --git a/examples/account/api/account.php b/examples/account/api/account.php new file mode 100644 index 00000000..fe1fd5a8 --- /dev/null +++ b/examples/account/api/account.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); + +$account = $client->getAccountApi()->getAccount(); + +var_dump($account); \ No newline at end of file diff --git a/lib/Tmdb/Api/Account.php b/lib/Tmdb/Api/Account.php index 350f3a5b..a325495a 100644 --- a/lib/Tmdb/Api/Account.php +++ b/lib/Tmdb/Api/Account.php @@ -20,12 +20,13 @@ class Account /** * Get the basic information for an account. You will need to have a valid session id. * - * @throws NotImplementedException + * @param array $parameters + * @param array $headers * @return mixed */ - public function getAccount() + public function getAccount(array $parameters = array(), array $headers = array()) { - throw new NotImplementedException(__METHOD__ . ' has not been implemented yet.'); + return $this->get('account', $parameters, $headers); } /** diff --git a/lib/Tmdb/Client.php b/lib/Tmdb/Client.php index f4bbc0f8..7d425c09 100644 --- a/lib/Tmdb/Client.php +++ b/lib/Tmdb/Client.php @@ -19,6 +19,7 @@ use Tmdb\ApiToken as Token; use Tmdb\HttpClient\Plugin\AcceptJsonHeaderPlugin; use Tmdb\HttpClient\Plugin\ApiTokenPlugin; +use Tmdb\HttpClient\Plugin\SessionTokenPlugin; /** * Simple wrapper for the Tmdb API @@ -336,6 +337,11 @@ public function getSecure() */ public function setSessionToken($sessionToken) { + if ($this->httpClient->getClient() instanceof \Guzzle\Common\HasDispatcherInterface) { + $sessionTokenPlugin = new SessionTokenPlugin($sessionToken); + $this->httpClient->getClient()->addSubscriber($sessionTokenPlugin); + } + $this->sessionToken = $sessionToken; return $this; } diff --git a/lib/Tmdb/HttpClient/Plugin/SessionTokenPlugin.php b/lib/Tmdb/HttpClient/Plugin/SessionTokenPlugin.php new file mode 100644 index 00000000..0d95fe3a --- /dev/null +++ b/lib/Tmdb/HttpClient/Plugin/SessionTokenPlugin.php @@ -0,0 +1,44 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\HttpClient\Plugin; + +use Guzzle\Common\Event; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Tmdb\SessionToken; + +class SessionTokenPlugin implements EventSubscriberInterface +{ + /** + * @var \Tmdb\ApiToken + */ + private $token; + + public function __construct(SessionToken $token) + { + $this->token = $token; + } + + public static function getSubscribedEvents() + { + return array('request.before_send' => 'onBeforeSend'); + } + + public function onBeforeSend(Event $event) + { + $url = $event['request']->getUrl(true); + + $url->getQuery()->set('session_id', $this->token->getToken()); + + $event['request']->setUrl($url); + } +} From b1fdc7dd3f119586501c84fbee38d4b9111b99d8 Mon Sep 17 00:00:00 2001 From: Michael Roterman Date: Tue, 25 Feb 2014 01:05:35 +0100 Subject: [PATCH 06/16] Getting green --- test/Tmdb/Tests/Api/AccountTest.php | 1 - test/Tmdb/Tests/Api/AuthenticationTest.php | 2 - .../Plugin/SessionTokenPluginTest.php | 40 +++++++++++++++++++ 3 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 test/Tmdb/Tests/HttpClient/Plugin/SessionTokenPluginTest.php diff --git a/test/Tmdb/Tests/Api/AccountTest.php b/test/Tmdb/Tests/Api/AccountTest.php index 09b607b5..8149f8c3 100644 --- a/test/Tmdb/Tests/Api/AccountTest.php +++ b/test/Tmdb/Tests/Api/AccountTest.php @@ -16,7 +16,6 @@ class AccountTest extends TestCase { /** * @test - * @expectedException Tmdb\Exception\NotImplementedException */ public function shouldGetAccount() { diff --git a/test/Tmdb/Tests/Api/AuthenticationTest.php b/test/Tmdb/Tests/Api/AuthenticationTest.php index 62a87b9b..89d0c31b 100644 --- a/test/Tmdb/Tests/Api/AuthenticationTest.php +++ b/test/Tmdb/Tests/Api/AuthenticationTest.php @@ -25,7 +25,6 @@ public function shouldGetNewToken() /** * @test - * @expectedException Tmdb\Exception\NotImplementedException */ public function shouldGetNewSession() { @@ -35,7 +34,6 @@ public function shouldGetNewSession() /** * @test - * @expectedException Tmdb\Exception\NotImplementedException */ public function shouldGetNewGuestSession() { diff --git a/test/Tmdb/Tests/HttpClient/Plugin/SessionTokenPluginTest.php b/test/Tmdb/Tests/HttpClient/Plugin/SessionTokenPluginTest.php new file mode 100644 index 00000000..47175065 --- /dev/null +++ b/test/Tmdb/Tests/HttpClient/Plugin/SessionTokenPluginTest.php @@ -0,0 +1,40 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Tests\HttpClient\Plugin; + +use Guzzle\Common\Event; +use Guzzle\Http\Message\Request; +use Tmdb\HttpClient\Plugin\SessionTokenPlugin; +use Tmdb\SessionToken; +use Tmdb\Tests\TestCase; + +class SessionTokenPluginTest extends TestCase +{ + /** + * @test + */ + public function shouldAddToken() + { + $token = new SessionToken('abcdef'); + $request = new Request('GET', '/'); + + $event = new Event(); + $event['request'] = $request; + + $plugin = new SessionTokenPlugin($token); + + $plugin->onBeforeSend($event); + + $this->assertEquals('/?session_id=abcdef', $event['request']->getUrl()); + } +} \ No newline at end of file From f64a18a24c52dc8832406c03e94d1c1138ef3f37 Mon Sep 17 00:00:00 2001 From: Michael Roterman Date: Tue, 25 Feb 2014 01:17:09 +0100 Subject: [PATCH 07/16] Implementing lists --- examples/account/api/lists.php | 24 ++++++++++++++++++++++++ lib/Tmdb/Api/Account.php | 8 +++++--- 2 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 examples/account/api/lists.php diff --git a/examples/account/api/lists.php b/examples/account/api/lists.php new file mode 100644 index 00000000..318fcbcf --- /dev/null +++ b/examples/account/api/lists.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); + +$lists = $client->getAccountApi()->getLists(TMDB_ACCOUNT_ID); + +var_dump($lists); \ No newline at end of file diff --git a/lib/Tmdb/Api/Account.php b/lib/Tmdb/Api/Account.php index a325495a..bd34ba1b 100644 --- a/lib/Tmdb/Api/Account.php +++ b/lib/Tmdb/Api/Account.php @@ -32,12 +32,14 @@ public function getAccount(array $parameters = array(), array $headers = array() /** * Get the lists that you have created and marked as a favorite. * - * @throws NotImplementedException + * @param integer $id + * @param array $parameters + * @param array $headers * @return mixed */ - public function getLists() + public function getLists($id, array $parameters = array(), array $headers = array()) { - throw new NotImplementedException(__METHOD__ . ' has not been implemented yet.'); + return $this->get('account/' . $id . '/lists', $parameters, $headers); } /** From 6ff4e31d5210111cb49951e9f3d781952cdd2b1b Mon Sep 17 00:00:00 2001 From: Michael Roterman Date: Tue, 25 Feb 2014 21:15:48 +0100 Subject: [PATCH 08/16] Implemented functions into the Account API, just adding movies to a watchlist or favoriting them does not function, need to get back at this later. --- examples/account/api/favorite.php | 24 ++++++++++ examples/account/api/favorite_movies.php | 24 ++++++++++ examples/account/api/rated_movies.php | 24 ++++++++++ examples/account/api/watchlist.php | 24 ++++++++++ examples/account/api/watchlist_movies.php | 24 ++++++++++ lib/Tmdb/Api/Account.php | 54 +++++++++++++++-------- 6 files changed, 156 insertions(+), 18 deletions(-) create mode 100644 examples/account/api/favorite.php create mode 100644 examples/account/api/favorite_movies.php create mode 100644 examples/account/api/rated_movies.php create mode 100644 examples/account/api/watchlist.php create mode 100644 examples/account/api/watchlist_movies.php diff --git a/examples/account/api/favorite.php b/examples/account/api/favorite.php new file mode 100644 index 00000000..ad3219bb --- /dev/null +++ b/examples/account/api/favorite.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); + +$favorite = $client->getAccountApi()->favorite(TMDB_ACCOUNT_ID, 97020, true); + +var_dump($favorite); \ No newline at end of file diff --git a/examples/account/api/favorite_movies.php b/examples/account/api/favorite_movies.php new file mode 100644 index 00000000..6b38f291 --- /dev/null +++ b/examples/account/api/favorite_movies.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); + +$favorite_movies = $client->getAccountApi()->getFavoriteMovies(TMDB_ACCOUNT_ID); + +var_dump($favorite_movies); \ No newline at end of file diff --git a/examples/account/api/rated_movies.php b/examples/account/api/rated_movies.php new file mode 100644 index 00000000..6c33811b --- /dev/null +++ b/examples/account/api/rated_movies.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); + +$rated_movies = $client->getAccountApi()->getRatedMovies(TMDB_ACCOUNT_ID); + +var_dump($rated_movies); \ No newline at end of file diff --git a/examples/account/api/watchlist.php b/examples/account/api/watchlist.php new file mode 100644 index 00000000..aa7da6b8 --- /dev/null +++ b/examples/account/api/watchlist.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); + +$watchlist = $client->getAccountApi()->watchlist(TMDB_ACCOUNT_ID, 97020, true); + +var_dump($watchlist); \ No newline at end of file diff --git a/examples/account/api/watchlist_movies.php b/examples/account/api/watchlist_movies.php new file mode 100644 index 00000000..d4ec787c --- /dev/null +++ b/examples/account/api/watchlist_movies.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); + +$watchlist_movies = $client->getAccountApi()->getMovieWatchlist(TMDB_ACCOUNT_ID); + +var_dump($watchlist_movies); \ No newline at end of file diff --git a/lib/Tmdb/Api/Account.php b/lib/Tmdb/Api/Account.php index bd34ba1b..54f15023 100644 --- a/lib/Tmdb/Api/Account.php +++ b/lib/Tmdb/Api/Account.php @@ -32,68 +32,86 @@ public function getAccount(array $parameters = array(), array $headers = array() /** * Get the lists that you have created and marked as a favorite. * - * @param integer $id + * @param integer $accountId * @param array $parameters * @param array $headers * @return mixed */ - public function getLists($id, array $parameters = array(), array $headers = array()) + public function getLists($accountId, array $parameters = array(), array $headers = array()) { - return $this->get('account/' . $id . '/lists', $parameters, $headers); + return $this->get('account/' . $accountId . '/lists', $parameters, $headers); } /** * Get the list of favorite movies for an account. * - * @throws NotImplementedException + * @param integer $accountId + * @param array $parameters + * @param array $headers * @return mixed */ - public function getFavoriteMovies() + public function getFavoriteMovies($accountId, array $parameters = array(), array $headers = array()) { - throw new NotImplementedException(__METHOD__ . ' has not been implemented yet.'); + return $this->get('account/' . $accountId . '/favorite_movies', $parameters, $headers); } /** * Add or remove a movie to an accounts favorite list. * - * @throws NotImplementedException + * @param integer $accountId + * @param integer $movieId + * @param boolean $isFavorite * @return mixed + * @todo refuses to function? review */ - public function favorite() + public function favorite($accountId, $movieId, $isFavorite = true) { - throw new NotImplementedException(__METHOD__ . ' has not been implemented yet.'); + return $this->post('account/' . $accountId . '/favorite', json_encode(array( + 'movie_id' => $movieId, + 'favorite' => $isFavorite + ))); } /** * Get the list of rated movies (and associated rating) for an account. * - * @throws NotImplementedException + * @param integer $accountId + * @param array $parameters + * @param array $headers * @return mixed */ - public function getRatedMovies() + public function getRatedMovies($accountId, array $parameters = array(), array $headers = array()) { - throw new NotImplementedException(__METHOD__ . ' has not been implemented yet.'); + return $this->get('account/' . $accountId . '/rated_movies', $parameters, $headers); } /** * Get the list of movies on an accounts watchlist. * - * @throws NotImplementedException + * @param integer $accountId + * @param array $parameters + * @param array $headers * @return mixed */ - public function getMovieWatchlist() + public function getMovieWatchlist($accountId, array $parameters = array(), array $headers = array()) { - throw new NotImplementedException(__METHOD__ . ' has not been implemented yet.'); + return $this->get('account/' . $accountId . '/movie_watchlist', $parameters, $headers); } /** * Add or remove a movie to an accounts watch list. * - * @throws NotImplementedException + * @param integer $accountId + * @param integer $movieId + * @param boolean $isOnWatchlist * @return mixed + * @todo refuses to function? review */ - public function watchlist() + public function watchlist($accountId, $movieId, $isOnWatchlist = true) { - throw new NotImplementedException(__METHOD__ . ' has not been implemented yet.'); + return $this->post('account/' . $accountId . '/movie_watchlist', json_encode(array( + 'movie_id' => $movieId, + 'movie_watchlist' => $isOnWatchlist + ))); } } From 2a161701bb3c04947f6a78af63ba9d90e215eee9 Mon Sep 17 00:00:00 2001 From: Michael Roterman Date: Tue, 25 Feb 2014 21:33:37 +0100 Subject: [PATCH 09/16] Implementing more account related functionality --- examples/movies/api/account_states.php | 24 ++++++++++++++++++++++++ examples/movies/api/images.php | 2 +- examples/movies/api/movie_rating.php | 24 ++++++++++++++++++++++++ lib/Tmdb/Api/Movies.php | 16 ++++++++++------ test/Tmdb/Tests/Api/AccountTest.php | 10 ++-------- test/Tmdb/Tests/Api/MoviesTest.php | 4 +--- 6 files changed, 62 insertions(+), 18 deletions(-) create mode 100644 examples/movies/api/account_states.php create mode 100644 examples/movies/api/movie_rating.php diff --git a/examples/movies/api/account_states.php b/examples/movies/api/account_states.php new file mode 100644 index 00000000..2d7b3b4f --- /dev/null +++ b/examples/movies/api/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); + +$accountStates = $client->getMoviesApi()->getAccountStates(550, true); + +var_dump($accountStates); \ No newline at end of file diff --git a/examples/movies/api/images.php b/examples/movies/api/images.php index eb2d240d..30d9c029 100644 --- a/examples/movies/api/images.php +++ b/examples/movies/api/images.php @@ -10,7 +10,7 @@ * @copyright (c) 2013, Michael Roterman * @version 0.0.1 */ -require_once('vendor/autoload.php'); +require_once('../../../vendor/autoload.php'); require_once('../../../apikey.php'); $token = new \Tmdb\ApiToken(TMDB_API_KEY); diff --git a/examples/movies/api/movie_rating.php b/examples/movies/api/movie_rating.php new file mode 100644 index 00000000..0699d95d --- /dev/null +++ b/examples/movies/api/movie_rating.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); + +$rating = $client->getMoviesApi()->rateMovie(550, 8.5); + +var_dump($rating); \ No newline at end of file diff --git a/lib/Tmdb/Api/Movies.php b/lib/Tmdb/Api/Movies.php index d1d3c9a9..c1e90fab 100644 --- a/lib/Tmdb/Api/Movies.php +++ b/lib/Tmdb/Api/Movies.php @@ -234,22 +234,26 @@ public function getTopRated(array $parameters = array(), array $headers = array( } /** - * This method lets users get the status of whether or not the movie has been rated or added to their favourite or watch lists. A valid session id is required. + * This method lets users get the status of whether or not the movie has been rated or added to their favourite or watch lists. + * + * A valid session id is required. * * @throws \Tmdb\Exception\NotImplementedException */ - public function getAccountStates() + public function getAccountStates($id) { - throw new NotImplementedException('TMDB account sessions have not been implemented yet!'); + return $this->get('movie/' . $id . '/account_states'); } /** - * TThis method lets users rate a movie. A valid session id or guest session id is required. + * TThis method lets users rate a movie. + * + * A valid session id or guest session id is required. * * @throws \Tmdb\Exception\NotImplementedException */ - public function rateMovie() + public function rateMovie($id, $rating) { - throw new NotImplementedException('TMDB account sessions have not been implemented yet!'); + return $this->post('movie/' . $id . '/rating', json_encode(array('value' => (float) $rating))); } } diff --git a/test/Tmdb/Tests/Api/AccountTest.php b/test/Tmdb/Tests/Api/AccountTest.php index 8149f8c3..06276ecc 100644 --- a/test/Tmdb/Tests/Api/AccountTest.php +++ b/test/Tmdb/Tests/Api/AccountTest.php @@ -25,7 +25,6 @@ public function shouldGetAccount() /** * @test - * @expectedException Tmdb\Exception\NotImplementedException */ public function shouldGetLists() { @@ -35,7 +34,6 @@ public function shouldGetLists() /** * @test - * @expectedException Tmdb\Exception\NotImplementedException */ public function shouldGetFavoriteMovies() { @@ -45,17 +43,15 @@ public function shouldGetFavoriteMovies() /** * @test - * @expectedException Tmdb\Exception\NotImplementedException */ public function shouldFavorite() { $api = $this->getApiMock(); - $api->favorite('account_id'); + $api->favorite('account_id', true); } /** * @test - * @expectedException Tmdb\Exception\NotImplementedException */ public function shouldGetRatedMovies() { @@ -65,7 +61,6 @@ public function shouldGetRatedMovies() /** * @test - * @expectedException Tmdb\Exception\NotImplementedException */ public function shouldGetMovieWatchlist() { @@ -75,12 +70,11 @@ public function shouldGetMovieWatchlist() /** * @test - * @expectedException Tmdb\Exception\NotImplementedException */ public function shouldWatchlist() { $api = $this->getApiMock(); - $api->watchlist('account_id'); + $api->watchlist('account_id', true); } protected function getApiClass() { diff --git a/test/Tmdb/Tests/Api/MoviesTest.php b/test/Tmdb/Tests/Api/MoviesTest.php index 04c343b2..d2e674f6 100644 --- a/test/Tmdb/Tests/Api/MoviesTest.php +++ b/test/Tmdb/Tests/Api/MoviesTest.php @@ -239,7 +239,6 @@ public function shouldGetTopRated() /** * @test - * @expectedException Tmdb\Exception\NotImplementedException */ public function shouldGetAccountStates() { @@ -249,12 +248,11 @@ public function shouldGetAccountStates() /** * @test - * @expectedException Tmdb\Exception\NotImplementedException */ public function shouldRateMovie() { $api = $this->getApiMock(); - $api->rateMovie(self::MOVIE_ID); + $api->rateMovie(self::MOVIE_ID, 7.5); } protected function getApiClass() { From 5e0541dc8ba99602f9d49399517a0302832d5aff Mon Sep 17 00:00:00 2001 From: Michael Roterman Date: Tue, 25 Feb 2014 22:43:02 +0100 Subject: [PATCH 10/16] Implementing remaining methods --- lib/Tmdb/Api/AbstractApi.php | 22 ++++++++++++++++ lib/Tmdb/Api/Account.php | 12 +++------ lib/Tmdb/Api/Authentication.php | 1 - lib/Tmdb/Api/Lists.php | 29 ++++++++++++--------- lib/Tmdb/Api/Movies.php | 2 +- lib/Tmdb/HttpClient/HttpClient.php | 12 +++++++++ lib/Tmdb/HttpClient/HttpClientInterface.php | 12 +++++++++ 7 files changed, 68 insertions(+), 22 deletions(-) diff --git a/lib/Tmdb/Api/AbstractApi.php b/lib/Tmdb/Api/AbstractApi.php index 6a8682a1..9dcfd9ff 100644 --- a/lib/Tmdb/Api/AbstractApi.php +++ b/lib/Tmdb/Api/AbstractApi.php @@ -87,6 +87,28 @@ public function post($path, $postBody = null, array $parameters = array(), $head return $response->json(); } + /** + * Send a POST request but json_encode the post body in the request + * + * @param $path + * @param null $postBody + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function postJson($path, $postBody = null, array $parameters = array(), $headers = array()) + { + /** + * @var Response $response + */ + if (is_array($postBody)) { + $postBody = json_encode($postBody); + } + + $response = $this->client->getHttpClient()->postJson($path, $postBody, $parameters, $headers); + return $response->json(); + } + /** * Send a PUT request * diff --git a/lib/Tmdb/Api/Account.php b/lib/Tmdb/Api/Account.php index 54f15023..086076c1 100644 --- a/lib/Tmdb/Api/Account.php +++ b/lib/Tmdb/Api/Account.php @@ -12,8 +12,6 @@ */ namespace Tmdb\Api; -use Tmdb\Exception\NotImplementedException; - class Account extends AbstractApi { @@ -62,14 +60,13 @@ public function getFavoriteMovies($accountId, array $parameters = array(), array * @param integer $movieId * @param boolean $isFavorite * @return mixed - * @todo refuses to function? review */ public function favorite($accountId, $movieId, $isFavorite = true) { - return $this->post('account/' . $accountId . '/favorite', json_encode(array( + return $this->postJson('account/' . $accountId . '/favorite', array( 'movie_id' => $movieId, 'favorite' => $isFavorite - ))); + )); } /** @@ -105,13 +102,12 @@ public function getMovieWatchlist($accountId, array $parameters = array(), array * @param integer $movieId * @param boolean $isOnWatchlist * @return mixed - * @todo refuses to function? review */ public function watchlist($accountId, $movieId, $isOnWatchlist = true) { - return $this->post('account/' . $accountId . '/movie_watchlist', json_encode(array( + return $this->postJson('account/' . $accountId . '/movie_watchlist', array( 'movie_id' => $movieId, 'movie_watchlist' => $isOnWatchlist - ))); + )); } } diff --git a/lib/Tmdb/Api/Authentication.php b/lib/Tmdb/Api/Authentication.php index 94ac0cb5..95162e27 100644 --- a/lib/Tmdb/Api/Authentication.php +++ b/lib/Tmdb/Api/Authentication.php @@ -80,7 +80,6 @@ public function getNewSession($requestToken) * * If a guest session is not used for the first time within 24 hours, it will be automatically discarded. * - * @throws NotImplementedException * @return mixed */ public function getNewGuestSession() diff --git a/lib/Tmdb/Api/Lists.php b/lib/Tmdb/Api/Lists.php index b9d0db54..e4f81817 100644 --- a/lib/Tmdb/Api/Lists.php +++ b/lib/Tmdb/Api/Lists.php @@ -33,12 +33,15 @@ public function getList($list_id, array $parameters = array(), array $headers = /** * This method lets users create a new list. A valid session id is required. * - * @throws NotImplementedException + * @param string $name + * @param string $description + * @param array $parameters + * @param array $headers * @return mixed */ - public function createList() + public function createList($name, $description, array $parameters = array(), array $headers = array()) { - throw new NotImplementedException(__METHOD__ . ' has not been implemented yet.'); + return $this->postJson('list', array('name' => $name, 'description' => $description), $parameters, $headers); } /** @@ -57,33 +60,35 @@ public function getItemStatus($list_id, array $parameters = array(), array $head /** * Get the cast information for a specific list id. * - * @throws NotImplementedException + * @param integer $id + * @param string $mediaId * @return mixed */ - public function addMediaToList() + public function addMediaToList($id, $mediaId) { - throw new NotImplementedException(__METHOD__ . ' has not been implemented yet.'); + return $this->postJson('list/' . $id . '/add_item', array('media_id' => $mediaId)); } /** * Get the images (posters and backdrops) for a specific list id. * - * @throws NotImplementedException + * @param integer $id + * @param string $mediaId * @return mixed */ - public function removeMediaFromList() + public function removeMediaFromList($id, $mediaId) { - throw new NotImplementedException(__METHOD__ . ' has not been implemented yet.'); + return $this->postJson('list/' . $id . '/remove_item', array('media_id' => $mediaId)); } /** * Get the plot keywords for a specific list id. * - * @throws NotImplementedException + * @param integer $id * @return mixed */ - public function deleteList() + public function deleteList($id) { - throw new NotImplementedException(__METHOD__ . ' has not been implemented yet.'); + return $this->delete('list/' . $id); } } diff --git a/lib/Tmdb/Api/Movies.php b/lib/Tmdb/Api/Movies.php index c1e90fab..cb7667c2 100644 --- a/lib/Tmdb/Api/Movies.php +++ b/lib/Tmdb/Api/Movies.php @@ -254,6 +254,6 @@ public function getAccountStates($id) */ public function rateMovie($id, $rating) { - return $this->post('movie/' . $id . '/rating', json_encode(array('value' => (float) $rating))); + return $this->postJson('movie/' . $id . '/rating', array('value' => (float) $rating)); } } diff --git a/lib/Tmdb/HttpClient/HttpClient.php b/lib/Tmdb/HttpClient/HttpClient.php index 5eab9c77..66009723 100644 --- a/lib/Tmdb/HttpClient/HttpClient.php +++ b/lib/Tmdb/HttpClient/HttpClient.php @@ -110,6 +110,18 @@ public function post($path, $postBody, array $parameters = array(), array $heade ); } + /** + * {@inheritDoc} + */ + public function postJson($path, $postBody, array $parameters = array(), array $headers = array()) + { + $parameters = $this->buildQueryParameters($parameters); + $request = $this->client->post($path, $headers, null, $parameters); + $request->setBody($postBody, 'application/json'); + + return $this->request($request); + } + /** * {@inheritDoc} */ diff --git a/lib/Tmdb/HttpClient/HttpClientInterface.php b/lib/Tmdb/HttpClient/HttpClientInterface.php index f844d1f0..7b8b6e9b 100644 --- a/lib/Tmdb/HttpClient/HttpClientInterface.php +++ b/lib/Tmdb/HttpClient/HttpClientInterface.php @@ -41,6 +41,18 @@ public function get($path, array $parameters = array(), array $headers = array() */ public function post($path, $postBody, array $parameters = array(), array $headers = array()); + /** + * 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 + * + * @return Response Data + */ + public function postJson($path, $postBody, array $parameters = array(), array $headers = array()); + /** * Compose a PATCH request * From dbfbe85d0ff27ca24fe907124de102a04e54d271 Mon Sep 17 00:00:00 2001 From: Michael Roterman Date: Tue, 25 Feb 2014 23:13:22 +0100 Subject: [PATCH 11/16] Implementing account related Lists methods --- examples/lists/api/add.php | 24 ++++++++++++++++++++++++ examples/lists/api/item_status.php | 24 ++++++++++++++++++++++++ examples/lists/api/list_create.php | 24 ++++++++++++++++++++++++ examples/lists/api/list_delete.php | 24 ++++++++++++++++++++++++ examples/lists/api/remove.php | 24 ++++++++++++++++++++++++ lib/Tmdb/Api/Lists.php | 19 +++++++++++-------- 6 files changed, 131 insertions(+), 8 deletions(-) create mode 100644 examples/lists/api/add.php create mode 100644 examples/lists/api/item_status.php create mode 100644 examples/lists/api/list_create.php create mode 100644 examples/lists/api/list_delete.php create mode 100644 examples/lists/api/remove.php diff --git a/examples/lists/api/add.php b/examples/lists/api/add.php new file mode 100644 index 00000000..99da6017 --- /dev/null +++ b/examples/lists/api/add.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); + +$add = $client->getListsApi()->addMediaToList(TMDB_LIST_ID, 49047); + +var_dump($add); \ No newline at end of file diff --git a/examples/lists/api/item_status.php b/examples/lists/api/item_status.php new file mode 100644 index 00000000..947af66e --- /dev/null +++ b/examples/lists/api/item_status.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); + +$remove = $client->getListsApi()->getItemStatus(TMDB_LIST_ID, 49047); + +var_dump($remove); \ No newline at end of file diff --git a/examples/lists/api/list_create.php b/examples/lists/api/list_create.php new file mode 100644 index 00000000..fb09fbed --- /dev/null +++ b/examples/lists/api/list_create.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); + +$create = $client->getListsApi()->createList('test', 'test description'); + +var_dump($create); \ No newline at end of file diff --git a/examples/lists/api/list_delete.php b/examples/lists/api/list_delete.php new file mode 100644 index 00000000..7e658876 --- /dev/null +++ b/examples/lists/api/list_delete.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); + +$create = $client->getListsApi()->deleteList(TMDB_LIST_ID); + +var_dump($create); \ No newline at end of file diff --git a/examples/lists/api/remove.php b/examples/lists/api/remove.php new file mode 100644 index 00000000..1e2e5cc1 --- /dev/null +++ b/examples/lists/api/remove.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); + +$remove = $client->getListsApi()->removeMediaFromList(TMDB_LIST_ID, 49047); + +var_dump($remove); \ No newline at end of file diff --git a/lib/Tmdb/Api/Lists.php b/lib/Tmdb/Api/Lists.php index e4f81817..2c44b732 100644 --- a/lib/Tmdb/Api/Lists.php +++ b/lib/Tmdb/Api/Lists.php @@ -12,8 +12,6 @@ */ namespace Tmdb\Api; -use Tmdb\Exception\NotImplementedException; - class Lists extends AbstractApi { @@ -47,20 +45,25 @@ public function createList($name, $description, array $parameters = array(), arr /** * Check to see if a movie ID is already added to a list. * - * @param $list_id + * @param string $id + * @param int $movieId * @param array $parameters * @param array $headers * @return mixed */ - public function getItemStatus($list_id, array $parameters = array(), array $headers = array()) + public function getItemStatus($id, $movieId, array $parameters = array(), array $headers = array()) { - return $this->get('list/' . $list_id . '/item_status', $parameters, $headers); + return $this->get( + 'list/' . $id . '/item_status', + array_merge($parameters, array('movie_id' => $movieId)), + $headers + ); } /** * Get the cast information for a specific list id. * - * @param integer $id + * @param string $id * @param string $mediaId * @return mixed */ @@ -72,7 +75,7 @@ public function addMediaToList($id, $mediaId) /** * Get the images (posters and backdrops) for a specific list id. * - * @param integer $id + * @param string $id * @param string $mediaId * @return mixed */ @@ -84,7 +87,7 @@ public function removeMediaFromList($id, $mediaId) /** * Get the plot keywords for a specific list id. * - * @param integer $id + * @param string $id * @return mixed */ public function deleteList($id) From 382b694fd397cbe37eb640e8c5184de929ac30d6 Mon Sep 17 00:00:00 2001 From: Michael Roterman Date: Tue, 25 Feb 2014 23:20:17 +0100 Subject: [PATCH 12/16] Fixing unit tests --- test/Tmdb/Tests/Api/ListsTest.php | 10 +++------- test/Tmdb/Tests/Api/TestCase.php | 2 +- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/test/Tmdb/Tests/Api/ListsTest.php b/test/Tmdb/Tests/Api/ListsTest.php index 270fc5d2..030b940b 100644 --- a/test/Tmdb/Tests/Api/ListsTest.php +++ b/test/Tmdb/Tests/Api/ListsTest.php @@ -31,7 +31,6 @@ public function shouldGetList() /** * @test - * @expectedException Tmdb\Exception\NotImplementedException */ public function shouldCreateList() { @@ -49,32 +48,29 @@ public function shouldGetItemStatus() ->method('get') ->with('list/' . self::LIST_ID . '/item_status'); - $api->getItemStatus(self::LIST_ID); + $api->getItemStatus(self::LIST_ID, 150); } /** * @test - * @expectedException Tmdb\Exception\NotImplementedException */ public function shouldAddMediaToList() { $api = $this->getApiMock(); - $api->addMediaToList(self::LIST_ID, 'media_id'); + $api->addMediaToList(self::LIST_ID, 150); } /** * @test - * @expectedException Tmdb\Exception\NotImplementedException */ public function shouldRemoveMediaFromList() { $api = $this->getApiMock(); - $api->removeMediaFromList(self::LIST_ID, 'media_id'); + $api->removeMediaFromList(self::LIST_ID, 150); } /** * @test - * @expectedException Tmdb\Exception\NotImplementedException */ public function shouldDeleteList() { diff --git a/test/Tmdb/Tests/Api/TestCase.php b/test/Tmdb/Tests/Api/TestCase.php index 2173bc8f..57c4403d 100644 --- a/test/Tmdb/Tests/Api/TestCase.php +++ b/test/Tmdb/Tests/Api/TestCase.php @@ -33,7 +33,7 @@ protected function getApiMock(array $methods = array()) return $this->getMockBuilder($this->getApiClass()) ->setMethods( array_merge( - array('get', 'post', 'postRaw', 'head', 'patch', 'delete', 'put'), + array('get', 'post', 'postJson', 'postRaw', 'head', 'patch', 'delete', 'put'), $methods ) ) From d958f28b6a13f03da7f5bf884e3c24acfc83f0fe Mon Sep 17 00:00:00 2001 From: Michael Roterman Date: Wed, 26 Feb 2014 00:31:40 +0100 Subject: [PATCH 13/16] Implementing Lists API into the modelled sections --- examples/lists/model/add.php | 25 ++++++ examples/lists/model/create_list.php | 25 ++++++ examples/lists/model/remove.php | 25 ++++++ lib/Tmdb/Api/Lists.php | 6 +- lib/Tmdb/Factory/ListFactory.php | 22 ++++- lib/Tmdb/Model/Lists/Result.php | 71 ++++++++++++++++ lib/Tmdb/Model/Lists/ResultWithListId.php | 47 +++++++++++ lib/Tmdb/Repository/ListRepository.php | 72 +++++++++++++++-- test/Tmdb/Tests/Factory/ListFactoryTest.php | 80 +++++++++++++++++++ .../Tests/Repository/ListRepositoryTest.php | 47 ++++++++++- test/Tmdb/Tests/Resources/lists/add.json | 4 + .../Tests/Resources/lists/item_status.json | 4 + .../Tests/Resources/lists/list_create.json | 5 ++ .../Tests/Resources/lists/list_delete.json | 4 + test/Tmdb/Tests/Resources/lists/remove.json | 4 + 15 files changed, 427 insertions(+), 14 deletions(-) create mode 100644 examples/lists/model/add.php create mode 100644 examples/lists/model/create_list.php create mode 100644 examples/lists/model/remove.php create mode 100644 lib/Tmdb/Model/Lists/Result.php create mode 100644 lib/Tmdb/Model/Lists/ResultWithListId.php create mode 100644 test/Tmdb/Tests/Resources/lists/add.json create mode 100644 test/Tmdb/Tests/Resources/lists/item_status.json create mode 100644 test/Tmdb/Tests/Resources/lists/list_create.json create mode 100644 test/Tmdb/Tests/Resources/lists/list_delete.json create mode 100644 test/Tmdb/Tests/Resources/lists/remove.json diff --git a/examples/lists/model/add.php b/examples/lists/model/add.php new file mode 100644 index 00000000..93f6e8c8 --- /dev/null +++ b/examples/lists/model/add.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\ListRepository($client); +$result = $repository->add(TMDB_LIST_ID, 150); + +var_dump($result); \ No newline at end of file diff --git a/examples/lists/model/create_list.php b/examples/lists/model/create_list.php new file mode 100644 index 00000000..de82a8ef --- /dev/null +++ b/examples/lists/model/create_list.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\ListRepository($client); +$result = $repository->createList('php-tmdb-api', 'just a test'); + +var_dump($result); \ No newline at end of file diff --git a/examples/lists/model/remove.php b/examples/lists/model/remove.php new file mode 100644 index 00000000..6ecaa480 --- /dev/null +++ b/examples/lists/model/remove.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\ListRepository($client); +$result = $repository->remove(TMDB_LIST_ID, 150); + +var_dump($result); \ No newline at end of file diff --git a/lib/Tmdb/Api/Lists.php b/lib/Tmdb/Api/Lists.php index 2c44b732..84f2ef4a 100644 --- a/lib/Tmdb/Api/Lists.php +++ b/lib/Tmdb/Api/Lists.php @@ -61,7 +61,7 @@ public function getItemStatus($id, $movieId, array $parameters = array(), array } /** - * Get the cast information for a specific list id. + * This method lets users add new movies to a list that they created. A valid session id is required. * * @param string $id * @param string $mediaId @@ -73,7 +73,7 @@ public function addMediaToList($id, $mediaId) } /** - * Get the images (posters and backdrops) for a specific list id. + * This method lets users delete movies from a list that they created. A valid session id is required. * * @param string $id * @param string $mediaId @@ -85,7 +85,7 @@ public function removeMediaFromList($id, $mediaId) } /** - * Get the plot keywords for a specific list id. + * This method lets users delete a list that they created. A valid session id is required. * * @param string $id * @return mixed diff --git a/lib/Tmdb/Factory/ListFactory.php b/lib/Tmdb/Factory/ListFactory.php index ee691bc2..0f98e3ec 100644 --- a/lib/Tmdb/Factory/ListFactory.php +++ b/lib/Tmdb/Factory/ListFactory.php @@ -63,13 +63,33 @@ public function create(array $data = array()) /** * @param array $data * - * @return Movie + * @return Lists\ItemStatus */ public function createItemStatus(array $data = array()) { return $this->hydrate(new Lists\ItemStatus(), $data); } + /** + * @param array $data + * + * @return Lists\Result + */ + public function createResult(array $data = array()) + { + return $this->hydrate(new Lists\Result(), $data); + } + + /** + * @param array $data + * + * @return Lists\ResultWithListId + */ + public function createResultWithListId(array $data = array()) + { + return $this->hydrate(new Lists\ResultWithListId(), $data); + } + /** * {@inheritdoc} */ diff --git a/lib/Tmdb/Model/Lists/Result.php b/lib/Tmdb/Model/Lists/Result.php new file mode 100644 index 00000000..261c2377 --- /dev/null +++ b/lib/Tmdb/Model/Lists/Result.php @@ -0,0 +1,71 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Lists; + +use Tmdb\Model\AbstractModel; + +class Result extends AbstractModel { + /** + * @var int + */ + private $statusCode; + + /** + * @var string + */ + private $statusMessage; + + /** + * @var array + */ + public static $_properties = array( + 'status_code', + 'status_message' + ); + + /** + * @param int $statusCode + * @return $this + */ + public function setStatusCode($statusCode) + { + $this->statusCode = $statusCode; + return $this; + } + + /** + * @return int + */ + public function getStatusCode() + { + return $this->statusCode; + } + + /** + * @param string $statusMessage + * @return $this + */ + public function setStatusMessage($statusMessage) + { + $this->statusMessage = $statusMessage; + return $this; + } + + /** + * @return string + */ + public function getStatusMessage() + { + return $this->statusMessage; + } +} diff --git a/lib/Tmdb/Model/Lists/ResultWithListId.php b/lib/Tmdb/Model/Lists/ResultWithListId.php new file mode 100644 index 00000000..a526babf --- /dev/null +++ b/lib/Tmdb/Model/Lists/ResultWithListId.php @@ -0,0 +1,47 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Lists; + +class ResultWithListId extends Result { + /** + * @var string + */ + private $listId; + + /** + * @var array + */ + public static $_properties = array( + 'status_code', + 'status_message', + 'list_id' + ); + + /** + * @param string $listId + * @return $this + */ + public function setListId($listId) + { + $this->listId = $listId; + return $this; + } + + /** + * @return string + */ + public function getListId() + { + return $this->listId; + } +} diff --git a/lib/Tmdb/Repository/ListRepository.php b/lib/Tmdb/Repository/ListRepository.php index 3d70cb69..88c8b995 100644 --- a/lib/Tmdb/Repository/ListRepository.php +++ b/lib/Tmdb/Repository/ListRepository.php @@ -13,8 +13,8 @@ namespace Tmdb\Repository; use Tmdb\Factory\ListFactory; -use Tmdb\Model\Collection\Jobs; -use Tmdb\Model\Job; +use Tmdb\Model\Lists\ItemStatus; +use Tmdb\Model\Lists; class ListRepository extends AbstractRepository { /** @@ -23,7 +23,7 @@ class ListRepository extends AbstractRepository { * @param string $id * @param array $parameters * @param array $headers - * @return Job + * @return Lists */ public function load($id, array $parameters = array(), array $headers = array()) { return $this->getFactory()->create( @@ -34,15 +34,73 @@ public function load($id, array $parameters = array(), array $headers = array()) /** * Check to see if a movie ID is already added to a list. * - * @param int $id + * @param string $id + * @param int $mediaId * @param array $parameters * @param array $headers - * @return Jobs|Job[] + * @return ItemStatus */ - public function getItemStatus($id, array $parameters = array(), array $headers = array()) + public function getItemStatus($id, $mediaId, array $parameters = array(), array $headers = array()) { return $this->getFactory()->createItemStatus( - $this->getApi()->getItemStatus($id, $parameters, $headers) + $this->getApi()->getItemStatus($id, $mediaId, $parameters, $headers) + ); + } + + /** + * This method lets users create a new list. A valid session id is required. + * + * @param string $name + * @param string $description + * @param array $parameters + * @param array $headers + * @return string The list id + */ + public function createList($name, $description = null, array $parameters = array(), array $headers = array()) + { + return $this->getFactory()->createResultWithListId( + $this->getApi()->createList($name, $description, $parameters, $headers) + ); + } + + /** + * This method lets users add new movies to a list that they created. A valid session id is required. + * + * @param string $id + * @param int $mediaId + * @return ItemStatus + */ + public function add($id, $mediaId) + { + return $this->getFactory()->createResult( + $this->getApi()->addMediaToList($id, $mediaId) + ); + } + + /** + * This method lets users delete movies from a list that they created. A valid session id is required. + * + * @param string $id + * @param int $mediaId + * @return ItemStatus + */ + public function remove($id, $mediaId) + { + return $this->getFactory()->createResult( + $this->getApi()->removeMediaFromList($id, $mediaId) + ); + } + + /** + * This method lets users delete a list that they created. A valid session id is required. + * + * @param string $id + * @return ItemStatus + */ + public function deleteList($id) + { + return $this->getFactory()->createResult( + $this->getApi()->deleteList($id) ); } diff --git a/test/Tmdb/Tests/Factory/ListFactoryTest.php b/test/Tmdb/Tests/Factory/ListFactoryTest.php index 4f3929d7..fa0a75d6 100644 --- a/test/Tmdb/Tests/Factory/ListFactoryTest.php +++ b/test/Tmdb/Tests/Factory/ListFactoryTest.php @@ -73,7 +73,87 @@ public function shouldBeFunctional() $this->assertEquals('Best Picture Winners - The Academy Awards', $this->lists->getName()); $this->assertEquals('/efBm2Nm2v5kQnO0w3hYcW6hVsJU.jpg', $this->lists->getPosterPath()); $this->assertInstanceOf('Tmdb\Model\Image\PosterImage', $this->lists->getPosterImage()); + } + + /** + * @test + */ + public function shouldGetItemStatus() + { + /** + * @var ListFactory $factory + */ + $factory = $this->getFactory(); + + $result = $factory->createItemStatus($this->loadByFile('lists/item_status.json')); + + $this->assertEquals('509ec17b19c2950a0600050d', $result->getId()); + $this->assertEquals(true, $result->getItemPresent()); + } + + /** + * @test + */ + public function shouldCreateList() + { + /** + * @var ListFactory $factory + */ + $factory = $this->getFactory(); + + $result = $factory->createResultWithListId($this->loadByFile('lists/list_create.json')); + + $this->assertEquals(1, $result->getStatusCode()); + $this->assertEquals('Success', $result->getStatusMessage()); + $this->assertEquals('50941077760ee35e1500000c', $result->getListId()); + } + + /** + * @test + */ + public function shouldAddItemToList() + { + /** + * @var ListFactory $factory + */ + $factory = $this->getFactory(); + + $result = $factory->createResult($this->loadByFile('lists/add.json')); + + $this->assertEquals(12, $result->getStatusCode()); + $this->assertEquals('The item/record was updated successfully', $result->getStatusMessage()); + } + + /** + * @test + */ + public function shouldRemoveItemFromList() + { + /** + * @var ListFactory $factory + */ + $factory = $this->getFactory(); + + $result = $factory->createResult($this->loadByFile('lists/remove.json')); + + $this->assertEquals(12, $result->getStatusCode()); + $this->assertEquals('The item/record was updated successfully', $result->getStatusMessage()); + } + + /** + * @test + */ + public function shouldRemoveList() + { + /** + * @var ListFactory $factory + */ + $factory = $this->getFactory(); + + $result = $factory->createResult($this->loadByFile('lists/list_delete.json')); + $this->assertEquals(13, $result->getStatusCode()); + $this->assertEquals('The item/record was deleted successfully', $result->getStatusMessage()); } protected function getFactoryClass() diff --git a/test/Tmdb/Tests/Repository/ListRepositoryTest.php b/test/Tmdb/Tests/Repository/ListRepositoryTest.php index 8c5f3d73..3c6a045d 100644 --- a/test/Tmdb/Tests/Repository/ListRepositoryTest.php +++ b/test/Tmdb/Tests/Repository/ListRepositoryTest.php @@ -14,7 +14,8 @@ class ListRepositoryTest extends TestCase { - const LIST_ID = '509ec17b19c2950a0600050d'; + const LIST_ID = '509ec17b19c2950a0600050d'; + const MOVIE_ID = 150; /** * @test @@ -29,11 +30,51 @@ public function shouldLoadList() /** * @test */ - public function shouldLoadListItem() + public function shouldGetItemStatus() { $repository = $this->getRepositoryWithMockedHttpClient(); - $repository->getItemStatus(self::LIST_ID); + $repository->getItemStatus(self::LIST_ID, self::MOVIE_ID); + } + + /** + * @test + */ + public function shouldCreateList() + { + $repository = $this->getRepositoryWithMockedHttpClient(); + + $repository->createList('list-name', 'list-description'); + } + + /** + * @test + */ + public function shouldAdd() + { + $repository = $this->getRepositoryWithMockedHttpClient(); + + $repository->add('list-id', 'movie-id'); + } + + /** + * @test + */ + public function shouldRemove() + { + $repository = $this->getRepositoryWithMockedHttpClient(); + + $repository->remove('list-id', 'movie-id'); + } + + /** + * @test + */ + public function shouldDeleteList() + { + $repository = $this->getRepositoryWithMockedHttpClient(); + + $repository->deleteList('list-id'); } protected function getApiClass() diff --git a/test/Tmdb/Tests/Resources/lists/add.json b/test/Tmdb/Tests/Resources/lists/add.json new file mode 100644 index 00000000..0738a914 --- /dev/null +++ b/test/Tmdb/Tests/Resources/lists/add.json @@ -0,0 +1,4 @@ +{ + "status_code": 12, + "status_message": "The item/record was updated successfully" +} \ No newline at end of file diff --git a/test/Tmdb/Tests/Resources/lists/item_status.json b/test/Tmdb/Tests/Resources/lists/item_status.json new file mode 100644 index 00000000..ec36d481 --- /dev/null +++ b/test/Tmdb/Tests/Resources/lists/item_status.json @@ -0,0 +1,4 @@ +{ + "id": "509ec17b19c2950a0600050d", + "item_present": true +} \ No newline at end of file diff --git a/test/Tmdb/Tests/Resources/lists/list_create.json b/test/Tmdb/Tests/Resources/lists/list_create.json new file mode 100644 index 00000000..32e64db8 --- /dev/null +++ b/test/Tmdb/Tests/Resources/lists/list_create.json @@ -0,0 +1,5 @@ +{ + "status_code": 1, + "status_message": "Success", + "list_id": "50941077760ee35e1500000c" +} \ No newline at end of file diff --git a/test/Tmdb/Tests/Resources/lists/list_delete.json b/test/Tmdb/Tests/Resources/lists/list_delete.json new file mode 100644 index 00000000..3702660e --- /dev/null +++ b/test/Tmdb/Tests/Resources/lists/list_delete.json @@ -0,0 +1,4 @@ +{ + "status_code": 13, + "status_message": "The item/record was deleted successfully" +} \ No newline at end of file diff --git a/test/Tmdb/Tests/Resources/lists/remove.json b/test/Tmdb/Tests/Resources/lists/remove.json new file mode 100644 index 00000000..0738a914 --- /dev/null +++ b/test/Tmdb/Tests/Resources/lists/remove.json @@ -0,0 +1,4 @@ +{ + "status_code": 12, + "status_message": "The item/record was updated successfully" +} \ No newline at end of file From 53f109ce7897cca75fb75f308501027243a04999 Mon Sep 17 00:00:00 2001 From: Michael Roterman Date: Wed, 26 Feb 2014 02:21:58 +0100 Subject: [PATCH 14/16] Adding account related methods --- examples/account/model/account.php | 26 ++ examples/account/model/favorite.php | 29 +++ examples/account/model/favorite_movies.php | 29 +++ examples/account/model/lists.php | 29 +++ examples/account/model/movie_watchlist.php | 29 +++ examples/account/model/rated_movies.php | 29 +++ examples/account/model/watchlist.php | 29 +++ examples/lists/model/get.php | 3 + examples/lists/model/item_status.php | 5 +- examples/movies/model/account_states.php | 25 ++ examples/movies/model/rate.php | 25 ++ lib/Tmdb/Factory/AccountFactory.php | 97 +++++++ lib/Tmdb/Factory/MovieFactory.php | 40 +++ lib/Tmdb/Model/Account.php | 167 ++++++++++++ lib/Tmdb/Model/Account/ListItem.php | 239 ++++++++++++++++++ lib/Tmdb/Model/Movie/AccountStates.php | 116 +++++++++ lib/Tmdb/Model/Movie/Rating.php | 45 ++++ lib/Tmdb/Repository/AccountRepository.php | 142 +++++++++++ lib/Tmdb/Repository/MovieRepository.php | 62 ++++- .../Tests/Repository/MovieRepositoryTest.php | 8 +- 20 files changed, 1159 insertions(+), 15 deletions(-) create mode 100644 examples/account/model/account.php create mode 100644 examples/account/model/favorite.php create mode 100644 examples/account/model/favorite_movies.php create mode 100644 examples/account/model/lists.php create mode 100644 examples/account/model/movie_watchlist.php create mode 100644 examples/account/model/rated_movies.php create mode 100644 examples/account/model/watchlist.php create mode 100644 examples/movies/model/account_states.php create mode 100644 examples/movies/model/rate.php create mode 100644 lib/Tmdb/Factory/AccountFactory.php create mode 100644 lib/Tmdb/Model/Account.php create mode 100644 lib/Tmdb/Model/Account/ListItem.php create mode 100644 lib/Tmdb/Model/Movie/AccountStates.php create mode 100644 lib/Tmdb/Model/Movie/Rating.php create mode 100644 lib/Tmdb/Repository/AccountRepository.php diff --git a/examples/account/model/account.php b/examples/account/model/account.php new file mode 100644 index 00000000..aa109d22 --- /dev/null +++ b/examples/account/model/account.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); + +$sessionToken = new \Tmdb\SessionToken(TMDB_SESSION_TOKEN); +$client->setSessionToken($sessionToken); + +$accountRepository = new \Tmdb\Repository\AccountRepository($client); +$account = $accountRepository->getAccount(); + +var_dump($account); + diff --git a/examples/account/model/favorite.php b/examples/account/model/favorite.php new file mode 100644 index 00000000..4d195cb4 --- /dev/null +++ b/examples/account/model/favorite.php @@ -0,0 +1,29 @@ + + * @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); + +/** + * @var \Tmdb\Repository\AccountRepository $accountRepository + */ +$accountRepository = new \Tmdb\Repository\AccountRepository($client); +$lists = $accountRepository->favorite(TMDB_ACCOUNT_ID, 150); + +var_dump($lists); + diff --git a/examples/account/model/favorite_movies.php b/examples/account/model/favorite_movies.php new file mode 100644 index 00000000..77b4d28c --- /dev/null +++ b/examples/account/model/favorite_movies.php @@ -0,0 +1,29 @@ + + * @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); + +/** + * @var \Tmdb\Repository\AccountRepository $accountRepository + */ +$accountRepository = new \Tmdb\Repository\AccountRepository($client); +$lists = $accountRepository->getFavoriteMovies(TMDB_ACCOUNT_ID); + +var_dump($lists); + diff --git a/examples/account/model/lists.php b/examples/account/model/lists.php new file mode 100644 index 00000000..6f8f6ca1 --- /dev/null +++ b/examples/account/model/lists.php @@ -0,0 +1,29 @@ + + * @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); + +/** + * @var \Tmdb\Repository\AccountRepository $accountRepository + */ +$accountRepository = new \Tmdb\Repository\AccountRepository($client); +$lists = $accountRepository->getLists(TMDB_ACCOUNT_ID); + +var_dump($lists); + diff --git a/examples/account/model/movie_watchlist.php b/examples/account/model/movie_watchlist.php new file mode 100644 index 00000000..18542f82 --- /dev/null +++ b/examples/account/model/movie_watchlist.php @@ -0,0 +1,29 @@ + + * @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); + +/** + * @var \Tmdb\Repository\AccountRepository $accountRepository + */ +$accountRepository = new \Tmdb\Repository\AccountRepository($client); +$lists = $accountRepository->getMovieWatchlist(TMDB_ACCOUNT_ID); + +var_dump($lists); + diff --git a/examples/account/model/rated_movies.php b/examples/account/model/rated_movies.php new file mode 100644 index 00000000..a1e0f957 --- /dev/null +++ b/examples/account/model/rated_movies.php @@ -0,0 +1,29 @@ + + * @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); + +/** + * @var \Tmdb\Repository\AccountRepository $accountRepository + */ +$accountRepository = new \Tmdb\Repository\AccountRepository($client); +$lists = $accountRepository->getRatedMovies(TMDB_ACCOUNT_ID); + +var_dump($lists); + diff --git a/examples/account/model/watchlist.php b/examples/account/model/watchlist.php new file mode 100644 index 00000000..00de319e --- /dev/null +++ b/examples/account/model/watchlist.php @@ -0,0 +1,29 @@ + + * @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); + +/** + * @var \Tmdb\Repository\AccountRepository $accountRepository + */ +$accountRepository = new \Tmdb\Repository\AccountRepository($client); +$lists = $accountRepository->watchlist(TMDB_ACCOUNT_ID, 49047); + +var_dump($lists); + diff --git a/examples/lists/model/get.php b/examples/lists/model/get.php index b864e16d..8107437c 100644 --- a/examples/lists/model/get.php +++ b/examples/lists/model/get.php @@ -16,6 +16,9 @@ $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\ListRepository($client); $list = $repository->load('509ec17b19c2950a0600050d'); diff --git a/examples/lists/model/item_status.php b/examples/lists/model/item_status.php index ab3e31b8..570aa4ac 100644 --- a/examples/lists/model/item_status.php +++ b/examples/lists/model/item_status.php @@ -16,7 +16,10 @@ $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\ListRepository($client); -$list = $repository->getItemStatus('509ec17b19c2950a0600050d'); +$list = $repository->getItemStatus('509ec17b19c2950a0600050d', 150); var_dump($list); \ No newline at end of file diff --git a/examples/movies/model/account_states.php b/examples/movies/model/account_states.php new file mode 100644 index 00000000..921e9712 --- /dev/null +++ b/examples/movies/model/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\MovieRepository($client); +$accountStates = $repository->getAccountStates(97020); + +var_dump($accountStates); \ No newline at end of file diff --git a/examples/movies/model/rate.php b/examples/movies/model/rate.php new file mode 100644 index 00000000..e24ed605 --- /dev/null +++ b/examples/movies/model/rate.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\MovieRepository($client); +$rate = $repository->rate(49047, 6.5); + +var_dump($rate); \ No newline at end of file diff --git a/lib/Tmdb/Factory/AccountFactory.php b/lib/Tmdb/Factory/AccountFactory.php new file mode 100644 index 00000000..3b1559f9 --- /dev/null +++ b/lib/Tmdb/Factory/AccountFactory.php @@ -0,0 +1,97 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Factory; + +use Tmdb\Exception\NotImplementedException; +use Tmdb\Model\Account; +use Tmdb\Model\Lists\Result; + +class AccountFactory extends AbstractFactory +{ + /** + * @var MovieFactory + */ + private $movieFactory; + + public function __construct() + { + $this->movieFactory = new MovieFactory(); + } + + /** + * @param array $data + * + * @return Account + */ + public function create(array $data = array()) + { + return $this->hydrate(new Account(), $data); + } + + /** + * @param array $data + * + * @return Result + */ + public function createStatusResult(array $data = array()) + { + return $this->hydrate(new Result(), $data); + } + + /** + * Create movie + * + * @param array $data + * @return \Tmdb\Model\Movie + */ + public function createMovie(array $data = array()) { + return $this->getMovieFactory()->create($data); + } + + /** + * Create list item + * + * @param array $data + * @return \Tmdb\Model\AbstractModel + */ + public function createListItem(array $data = array()) + { + return $this->hydrate(new Account\ListItem(), $data); + } + + /** + * {@inheritdoc} + */ + public function createCollection(array $data = array()) + { + throw new NotImplementedException('Not implemented'); + } + + /** + * @param \Tmdb\Factory\MovieFactory $movieFactory + * @return $this + */ + public function setMovieFactory($movieFactory) + { + $this->movieFactory = $movieFactory; + return $this; + } + + /** + * @return \Tmdb\Factory\MovieFactory + */ + public function getMovieFactory() + { + return $this->movieFactory; + } +} diff --git a/lib/Tmdb/Factory/MovieFactory.php b/lib/Tmdb/Factory/MovieFactory.php index 810503d3..505c6e97 100644 --- a/lib/Tmdb/Factory/MovieFactory.php +++ b/lib/Tmdb/Factory/MovieFactory.php @@ -20,6 +20,7 @@ use Tmdb\Model\Common\GenericCollection; use Tmdb\Model\Common\Trailer\Youtube; use Tmdb\Model\Common\Translation; +use Tmdb\Model\Lists\Result; use Tmdb\Model\Movie; class MovieFactory extends AbstractFactory { @@ -181,6 +182,45 @@ 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/Model/Account.php b/lib/Tmdb/Model/Account.php new file mode 100644 index 00000000..e7a9e17a --- /dev/null +++ b/lib/Tmdb/Model/Account.php @@ -0,0 +1,167 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model; + +class Account extends AbstractModel { + /** + * @var integer + */ + private $id; + + /** + * @var boolean + */ + private $includeAdult; + + /** + * @var string + */ + private $iso31661; + + /** + * @var string + */ + private $iso6391; + + /** + * @var string + */ + private $name; + + /** + * @var string + */ + private $username; + + /** + * @var array + */ + public static $_properties = array( + 'id', + 'include_adult', + 'iso_3166_1', + 'iso_639_1', + 'name', + 'username' + ); + + /** + * @param int $id + * @return $this + */ + public function setId($id) + { + $this->id = $id; + return $this; + } + + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @param boolean $includeAdult + * @return $this + */ + public function setIncludeAdult($includeAdult) + { + $this->includeAdult = $includeAdult; + return $this; + } + + /** + * @return boolean + */ + public function getIncludeAdult() + { + return $this->includeAdult; + } + + /** + * @param string $iso31661 + * @return $this + */ + public function setIso31661($iso31661) + { + $this->iso31661 = $iso31661; + return $this; + } + + /** + * @return string + */ + public function getIso31661() + { + return $this->iso31661; + } + + /** + * @param string $iso6391 + * @return $this + */ + public function setIso6391($iso6391) + { + $this->iso6391 = $iso6391; + return $this; + } + + /** + * @return string + */ + public function getIso6391() + { + return $this->iso6391; + } + + /** + * @param string $name + * @return $this + */ + public function setName($name) + { + $this->name = $name; + return $this; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param string $username + * @return $this + */ + public function setUsername($username) + { + $this->username = $username; + return $this; + } + + /** + * @return string + */ + public function getUsername() + { + return $this->username; + } + + +} diff --git a/lib/Tmdb/Model/Account/ListItem.php b/lib/Tmdb/Model/Account/ListItem.php new file mode 100644 index 00000000..3d3b8aa5 --- /dev/null +++ b/lib/Tmdb/Model/Account/ListItem.php @@ -0,0 +1,239 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Account; + +use Tmdb\Model\AbstractModel; +use Tmdb\Model\Image\PosterImage; + +class ListItem extends AbstractModel { + /** + * @var string + */ + private $id; + + /** + * @var string + */ + private $description; + + /** + * @var int + */ + private $favoriteCount; + + /** + * @var int + */ + private $itemCount; + + /** + * @var string + */ + private $iso6391; + + /** + * @var string + */ + private $listType; + + /** + * @var string + */ + private $name; + + /** + * @var string + */ + private $posterPath; + + /** + * @var PosterImage + */ + private $posterImage; + + /** + * @var array + */ + public static $_properties = array( + 'description', + 'favorite_count', + 'id', + 'item_count', + 'iso_639_1', + 'list_type', + 'name', + 'poster_path' + ); + + /** + * @param string $description + * @return $this + */ + public function setDescription($description) + { + $this->description = $description; + return $this; + } + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } + + /** + * @param int $favoriteCount + * @return $this + */ + public function setFavoriteCount($favoriteCount) + { + $this->favoriteCount = $favoriteCount; + return $this; + } + + /** + * @return int + */ + public function getFavoriteCount() + { + return $this->favoriteCount; + } + + /** + * @param string $id + * @return $this + */ + public function setId($id) + { + $this->id = $id; + return $this; + } + + /** + * @return string + */ + public function getId() + { + return $this->id; + } + + /** + * @param string $iso6391 + * @return $this + */ + public function setIso6391($iso6391) + { + $this->iso6391 = $iso6391; + return $this; + } + + /** + * @return string + */ + public function getIso6391() + { + return $this->iso6391; + } + + /** + * @param int $itemCount + * @return $this + */ + public function setItemCount($itemCount) + { + $this->itemCount = $itemCount; + return $this; + } + + /** + * @return int + */ + public function getItemCount() + { + return $this->itemCount; + } + + /** + * @param string $listType + * @return $this + */ + public function setListType($listType) + { + $this->listType = $listType; + return $this; + } + + /** + * @return string + */ + public function getListType() + { + return $this->listType; + } + + /** + * @param string $name + * @return $this + */ + public function setName($name) + { + $this->name = $name; + return $this; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param \Tmdb\Model\Image\PosterImage $posterImage + * @return $this + */ + public function setPosterImage($posterImage) + { + $this->posterImage = $posterImage; + return $this; + } + + /** + * @return \Tmdb\Model\Image\PosterImage + */ + public function getPosterImage() + { + return $this->posterImage; + } + + /** + * @param string $posterPath + * @return $this + */ + public function setPosterPath($posterPath) + { + $this->posterPath = $posterPath; + return $this; + } + + /** + * @return string + */ + public function getPosterPath() + { + return $this->posterPath; + } +} diff --git a/lib/Tmdb/Model/Movie/AccountStates.php b/lib/Tmdb/Model/Movie/AccountStates.php new file mode 100644 index 00000000..bae93379 --- /dev/null +++ b/lib/Tmdb/Model/Movie/AccountStates.php @@ -0,0 +1,116 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Movie; + +use Tmdb\Model\AbstractModel; + +class AccountStates extends AbstractModel { + + /** + * @var integer + */ + private $id; + + /** + * @var boolean + */ + private $favorite; + + /** + * @var Rating + */ + private $rated; + + /** + * @var boolean + */ + private $watchlist; + + public static $_properties = array( + 'id', + 'favorite', + 'watchlist', + ); + + /** + * @param boolean $favorite + * @return $this + */ + public function setFavorite($favorite) + { + $this->favorite = $favorite; + return $this; + } + + /** + * @return boolean + */ + public function getFavorite() + { + return $this->favorite; + } + + /** + * @param int $id + * @return $this + */ + public function setId($id) + { + $this->id = $id; + return $this; + } + + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @param \Tmdb\Model\Movie\Rating $rated + * @return $this + */ + public function setRated($rated) + { + $this->rated = $rated; + return $this; + } + + /** + * @return \Tmdb\Model\Movie\Rating + */ + public function getRated() + { + return $this->rated; + } + + /** + * @param boolean $watchlist + * @return $this + */ + public function setWatchlist($watchlist) + { + $this->watchlist = $watchlist; + return $this; + } + + /** + * @return boolean + */ + public function getWatchlist() + { + return $this->watchlist; + } +} diff --git a/lib/Tmdb/Model/Movie/Rating.php b/lib/Tmdb/Model/Movie/Rating.php new file mode 100644 index 00000000..41a09e02 --- /dev/null +++ b/lib/Tmdb/Model/Movie/Rating.php @@ -0,0 +1,45 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Movie; + +use Tmdb\Model\AbstractModel; + +class Rating extends AbstractModel { + + /** + * @var float + */ + private $value; + + public static $_properties = array( + 'value', + ); + + /** + * @param float $value + * @return $this + */ + public function setValue($value) + { + $this->value = $value; + return $this; + } + + /** + * @return float + */ + public function getValue() + { + return $this->value; + } +} diff --git a/lib/Tmdb/Repository/AccountRepository.php b/lib/Tmdb/Repository/AccountRepository.php new file mode 100644 index 00000000..f2e1f749 --- /dev/null +++ b/lib/Tmdb/Repository/AccountRepository.php @@ -0,0 +1,142 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Repository; + +use Tmdb\Factory\AccountFactory; +use Tmdb\Model\Collection\ResultCollection; +use Tmdb\Model\Movie; + +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 + */ + public function getAccount() + { + $data = $this->getApi()->getAccount(); + return $this->getFactory()->create($data); + } + + /** + * Get the lists that you have created and marked as a favorite. + * + * @param string $accountId + * @param array $parameters + * @param array $headers + * @return ResultCollection + */ + public function getLists($accountId, array $parameters = array(), array $headers = array()) + { + $data = $this->getApi()->getLists($accountId, $parameters, $headers); + return $this->getFactory()->createResultCollection($data, 'createListItem'); + } + + /** + * Get the list of favorite movies for an account. + * + * @param string $accountId + * @param array $parameters + * @param array $headers + * @return ResultCollection + */ + public function getFavoriteMovies($accountId, array $parameters = array(), array $headers = array()) + { + $data = $this->getApi()->getFavoriteMovies($accountId, $parameters, $headers); + return $this->getFactory()->createResultCollection($data, 'createMovie'); + } + + + /** + * Add or remove a movie to an accounts favorite list. + * + * @param string $accountId + * @param int|Movie $movie + * @param boolean $isFavorite + * @return ResultCollection + */ + public function favorite($accountId, $movie, $isFavorite = true) + { + if ($movie instanceof Movie) { + $movie = $movie->getId(); + } + + $data = $this->getApi()->favorite($accountId, $movie, $isFavorite); + return $this->getFactory()->createStatusResult($data); + } + + /** + * Get the list of rated movies (and associated rating) for an account. + * + * @param string $accountId + * @param array $parameters + * @param array $headers + * @return ResultCollection + */ + public function getRatedMovies($accountId, array $parameters = array(), array $headers = array()) + { + $data = $this->getApi()->getRatedMovies($accountId, $parameters, $headers); + return $this->getFactory()->createResultCollection($data, 'createMovie'); + } + + /** + * Get the list of movies on an accounts watchlist. + * + * @param string $accountId + * @param array $parameters + * @param array $headers + * @return ResultCollection + */ + public function getMovieWatchlist($accountId, array $parameters = array(), array $headers = array()) + { + $data = $this->getApi()->getMovieWatchlist($accountId, $parameters, $headers); + return $this->getFactory()->createResultCollection($data, 'createMovie'); + } + + /** + * Add or remove a movie to an accounts watch list. + * + * @param string $accountId + * @param int|Movie $movie + * @param boolean $isOnWatchlist + * @return ResultCollection + */ + public function watchlist($accountId, $movie, $isOnWatchlist = true) + { + if ($movie instanceof Movie) { + $movie = $movie->getId(); + } + + $data = $this->getApi()->watchlist($accountId, $movie, $isOnWatchlist); + return $this->getFactory()->createStatusResult($data); + } + + /** + * Return the Collection API Class + * + * @return \Tmdb\Api\Account + */ + public function getApi() + { + return $this->getClient()->getAccountApi(); + } + + /** + * @return AccountFactory + */ + public function getFactory() + { + return new AccountFactory(); + } +} diff --git a/lib/Tmdb/Repository/MovieRepository.php b/lib/Tmdb/Repository/MovieRepository.php index 2c288ed8..e8753ad9 100644 --- a/lib/Tmdb/Repository/MovieRepository.php +++ b/lib/Tmdb/Repository/MovieRepository.php @@ -23,6 +23,21 @@ class MovieRepository extends AbstractRepository { + /** + * @var ImageFactory + */ + private $imageFactory; + + /** + * @var AlternativeTitleFactory + */ + private $alternativeTitleFactory; + + /** + * @var PeopleFactory + */ + private $peopleFactory; + /** * Load a movie with the given identifier * @@ -307,6 +322,33 @@ public function getTopRated(array $options = array()) ); } + /** + * This method lets users get the status of whether or not the movie has been rated or added to their favourite or watch lists. A valid session id is required. + * + * @param integer $id + * @return Movie[] + */ + public function getAccountStates($id) + { + return $this->getFactory()->createAccountStates( + $this->getApi()->getAccountStates($id) + ); + } + + /** + * This method lets users rate a movie. A valid session id or guest session id is required. + * + * @param integer $id + * @param float $rating + * @return Movie[] + */ + public function rate($id, $rating) + { + return $this->getFactory()->createResult( + $this->getApi()->rateMovie($id, $rating) + ); + } + /** * Return the Movies API Class * @@ -338,39 +380,39 @@ private function createCollection($data){ } /** - * @param mixed $alternativeTitlesFactory + * @param mixed $alternativeTitleFactory * @return $this */ - public function setAlternativeTitlesFactory($alternativeTitlesFactory) + public function setAlternativeTitleFactory($alternativeTitleFactory) { - $this->alternativeTitlesFactory = $alternativeTitlesFactory; + $this->alternativeTitleFactory = $alternativeTitleFactory; return $this; } /** * @return mixed */ - public function getAlternativeTitlesFactory() + public function getAlternativeTitleFactory() { - return $this->alternativeTitlesFactory; + return $this->alternativeTitleFactory; } /** - * @param mixed $imagesFactory + * @param mixed $imageFactory * @return $this */ - public function setImagesFactory($imagesFactory) + public function setImageFactory($imageFactory) { - $this->imagesFactory = $imagesFactory; + $this->imageFactory = $imageFactory; return $this; } /** * @return mixed */ - public function getImagesFactory() + public function getImageFactory() { - return $this->imagesFactory; + return $this->imageFactory; } /** diff --git a/test/Tmdb/Tests/Repository/MovieRepositoryTest.php b/test/Tmdb/Tests/Repository/MovieRepositoryTest.php index a44bf7f8..33c66db1 100644 --- a/test/Tmdb/Tests/Repository/MovieRepositoryTest.php +++ b/test/Tmdb/Tests/Repository/MovieRepositoryTest.php @@ -200,12 +200,12 @@ public function shouldBeAbleToSetFactories() $repository = $this->getRepositoryWithMockedHttpClient(); $class = new \stdClass(); - $repository->setAlternativeTitlesFactory($class); - $repository->setImagesFactory($class); + $repository->setAlternativeTitleFactory($class); + $repository->setImageFactory($class); $repository->setPeopleFactory($class); - $this->assertInstanceOf('stdClass', $repository->getAlternativeTitlesFactory()); - $this->assertInstanceOf('stdClass', $repository->getImagesFactory()); + $this->assertInstanceOf('stdClass', $repository->getAlternativeTitleFactory()); + $this->assertInstanceOf('stdClass', $repository->getImageFactory()); $this->assertInstanceOf('stdClass', $repository->getPeopleFactory()); } From e62f084df0422a494d276fe254e7e5eb68784091 Mon Sep 17 00:00:00 2001 From: Michael Roterman Date: Wed, 26 Feb 2014 03:34:45 +0100 Subject: [PATCH 15/16] Adding the rest of Account related methods --- .../model/authenticate_request_token.php | 23 ++++ .../model/guest_session_token.php | 22 +++ .../authentication/model/request_token.php | 23 ++++ .../authentication/model/session_token.php | 25 ++++ lib/Tmdb/Factory/AuthenticationFactory.php | 113 ++++++++++++++++ .../Repository/AuthenticationRepository.php | 94 +++++++++++++ lib/Tmdb/RequestToken.php | 23 ++++ lib/Tmdb/SessionToken.php | 53 ++++++++ .../Repository/AccountRepositoryTest.php | 126 ++++++++++++++++++ .../AuthenticationRepositoryTest.php | 70 ++++++++++ test/Tmdb/Tests/RequestTokenTest.php | 2 + test/Tmdb/Tests/SessionTokenTest.php | 4 + 12 files changed, 578 insertions(+) create mode 100644 examples/authentication/model/authenticate_request_token.php create mode 100644 examples/authentication/model/guest_session_token.php create mode 100644 examples/authentication/model/request_token.php create mode 100644 examples/authentication/model/session_token.php create mode 100644 lib/Tmdb/Factory/AuthenticationFactory.php create mode 100644 lib/Tmdb/Repository/AuthenticationRepository.php create mode 100644 test/Tmdb/Tests/Repository/AccountRepositoryTest.php create mode 100644 test/Tmdb/Tests/Repository/AuthenticationRepositoryTest.php diff --git a/examples/authentication/model/authenticate_request_token.php b/examples/authentication/model/authenticate_request_token.php new file mode 100644 index 00000000..16b1e29d --- /dev/null +++ b/examples/authentication/model/authenticate_request_token.php @@ -0,0 +1,23 @@ + + * @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); + +$authenticationRepository = new \Tmdb\Repository\AuthenticationRepository($client); +$requestToken = $authenticationRepository->getRequestToken(); + +// Will force a redirect +$authenticationRepository->authenticateRequestToken($requestToken); diff --git a/examples/authentication/model/guest_session_token.php b/examples/authentication/model/guest_session_token.php new file mode 100644 index 00000000..33e4ecf5 --- /dev/null +++ b/examples/authentication/model/guest_session_token.php @@ -0,0 +1,22 @@ + + * @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); + +$authenticationRepository = new \Tmdb\Repository\AuthenticationRepository($client); +$sessionToken = $authenticationRepository->getGuestSessionToken($requestToken); + +var_dump($sessionToken); diff --git a/examples/authentication/model/request_token.php b/examples/authentication/model/request_token.php new file mode 100644 index 00000000..6685084f --- /dev/null +++ b/examples/authentication/model/request_token.php @@ -0,0 +1,23 @@ + + * @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); + +$authenticationRepository = new \Tmdb\Repository\AuthenticationRepository($client); +$requestToken = $authenticationRepository->getRequestToken(); + +var_dump($requestToken); + diff --git a/examples/authentication/model/session_token.php b/examples/authentication/model/session_token.php new file mode 100644 index 00000000..00e28599 --- /dev/null +++ b/examples/authentication/model/session_token.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); + +$requestToken = new \Tmdb\RequestToken('2e57316025d7e4df5cfff81f0596209c2465a8bd'); + +$authenticationRepository = new \Tmdb\Repository\AuthenticationRepository($client); +$sessionToken = $authenticationRepository->getSessionToken($requestToken); + +var_dump($sessionToken); + diff --git a/lib/Tmdb/Factory/AuthenticationFactory.php b/lib/Tmdb/Factory/AuthenticationFactory.php new file mode 100644 index 00000000..3cf77797 --- /dev/null +++ b/lib/Tmdb/Factory/AuthenticationFactory.php @@ -0,0 +1,113 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Factory; + +use Tmdb\Exception\NotImplementedException; +use Tmdb\RequestToken; +use Tmdb\SessionToken; + +class AuthenticationFactory extends AbstractFactory +{ + /** + * @param array $data + * + * @throws NotImplementedException + * @return void + */ + public function create(array $data = array()) + { + throw new NotImplementedException(); + } + + /** + * @param array $data + * + * @throws NotImplementedException + * @return void + */ + public function createCollection(array $data = array()) + { + throw new NotImplementedException(); + } + + /** + * Create request token + * + * @param array $data + * @return RequestToken + */ + public function createRequestToken(array $data = array()) + { + $token = new RequestToken(); + + if (array_key_exists('expires_at', $data)) { + $token->setExpiresAt(new \DateTime($data['expires_at'])); + } + + if (array_key_exists('request_token', $data)) { + $token->setToken($data['request_token']); + } + + if (array_key_exists('success', $data)) { + $token->setSuccess($data['success']); + } + + return $token; + } + + /** + * Create session token for user + * + * @param array $data + * @return SessionToken + */ + public function createSessionToken(array $data = array()) + { + $token = new SessionToken(); + + if (array_key_exists('session_id', $data)) { + $token->setToken($data['session_id']); + } + + if (array_key_exists('success', $data)) { + $token->setSuccess($data['success']); + } + + return $token; + } + + /** + * Create session token for guest + * + * @param array $data + * @return SessionToken + */ + public function createGuestSessionToken(array $data = array()) + { + $token = new SessionToken(); + + if (array_key_exists('expires_at', $data)) { + $token->setExpiresAt(new \DateTime($data['expires_at'])); + } + + if (array_key_exists('guest_session_id', $data)) { + $token->setToken($data['guest_session_id']); + } + + if (array_key_exists('success', $data)) { + $token->setSuccess($data['success']); + } + + return $token; + } +} diff --git a/lib/Tmdb/Repository/AuthenticationRepository.php b/lib/Tmdb/Repository/AuthenticationRepository.php new file mode 100644 index 00000000..9c8d6fae --- /dev/null +++ b/lib/Tmdb/Repository/AuthenticationRepository.php @@ -0,0 +1,94 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Repository; + +use Tmdb\Factory\AuthenticationFactory; +use Tmdb\RequestToken; + +class AuthenticationRepository extends AbstractRepository { + + /** + * This method is used to generate a valid request token for user based authentication. + * A request token is required in order to request a session id. + * + * You can generate any number of request tokens but they will expire after 60 minutes. + * As soon as a valid session id has been created the token will be destroyed. + * + * @return RequestToken + */ + public function getRequestToken() + { + $data = $this->getApi()->getNewToken(); + return $this->getFactory()->createRequestToken($data); + } + + /** + * 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 + */ + public function getSessionToken(RequestToken $requestToken) + { + $data = $this->getApi()->getNewSession($requestToken->getToken()); + return $this->getFactory()->createSessionToken($data); + } + + /** + * This method is used to generate a guest session id. + * + * A guest session can be used to rate movies without having a registered TMDb user account. + * You should only generate a single guest session per user (or device) as you will be able to + * attach the ratings to a TMDb user account in the future. + * + * There is also IP limits in place so you should always make sure it's the end user doing the guest session actions. + * If a guest session is not used for the first time within 24 hours, it will be automatically discarded. + * + * @return RequestToken + */ + public function getGuestSessionToken() + { + $data = $this->getApi()->getNewGuestSession(); + return $this->getFactory()->createGuestSessionToken($data); + } + + /** + * Authenticate request token, redirects the user + * + * @param RequestToken $requestToken + * @return void + */ + public function authenticateRequestToken(RequestToken $requestToken) + { + $this->getApi()->authenticateRequestToken($requestToken->getToken()); + } + + /** + * Return the Collection API Class + * + * @return \Tmdb\Api\Authentication + */ + public function getApi() + { + return $this->getClient()->getAuthenticationApi(); + } + + /** + * @return AuthenticationFactory + */ + public function getFactory() + { + return new AuthenticationFactory(); + } +} diff --git a/lib/Tmdb/RequestToken.php b/lib/Tmdb/RequestToken.php index 551ce954..5c1215a6 100644 --- a/lib/Tmdb/RequestToken.php +++ b/lib/Tmdb/RequestToken.php @@ -27,6 +27,11 @@ class RequestToken { */ private $expiresAt; + /** + * @var bool + */ + private $success; + /** * Token bag * @@ -76,4 +81,22 @@ public function getExpiresAt() { return $this->expiresAt; } + + /** + * @param boolean $success + * @return $this + */ + public function setSuccess($success) + { + $this->success = $success; + return $this; + } + + /** + * @return boolean + */ + public function getSuccess() + { + return $this->success; + } } diff --git a/lib/Tmdb/SessionToken.php b/lib/Tmdb/SessionToken.php index 19283f00..7ef9b638 100644 --- a/lib/Tmdb/SessionToken.php +++ b/lib/Tmdb/SessionToken.php @@ -13,8 +13,21 @@ namespace Tmdb; class SessionToken { + /** + * @var string + */ private $sessionToken = null; + /** + * @var \DateTime + */ + private $expiresAt; + + /** + * @var bool + */ + private $success; + /** * Token bag * @@ -42,4 +55,44 @@ public function getToken() { return $this->sessionToken; } + + /** + * @param \DateTime $expiresAt + * @return $this + */ + public function setExpiresAt($expiresAt) + { + if (!$expiresAt instanceof \DateTime) { + $expiresAt = new \DateTime($expiresAt); + } + + $this->expiresAt = $expiresAt; + return $this; + } + + /** + * @return \DateTime + */ + public function getExpiresAt() + { + return $this->expiresAt; + } + + /** + * @param mixed $success + * @return $this + */ + public function setSuccess($success) + { + $this->success = $success; + return $this; + } + + /** + * @return mixed + */ + public function getSuccess() + { + return $this->success; + } } diff --git a/test/Tmdb/Tests/Repository/AccountRepositoryTest.php b/test/Tmdb/Tests/Repository/AccountRepositoryTest.php new file mode 100644 index 00000000..33571324 --- /dev/null +++ b/test/Tmdb/Tests/Repository/AccountRepositoryTest.php @@ -0,0 +1,126 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Tests\Repository; + +use Tmdb\Api\Account; +use Tmdb\Model\Movie; +use Tmdb\Repository\AccountRepository; + +class AccountRepositoryTest extends TestCase +{ + const ACCOUNT_ID = '12345'; + const LIST_ID = '509ec17b19c2950a0600050d'; + const MOVIE_ID = 150; + + /** + * @test + */ + public function shouldGetAccount() + { + $repository = $this->getRepositoryWithMockedHttpClient(); + + $repository->getAccount(); + } + + /** + * @test + */ + public function shouldGetLists() + { + $repository = $this->getRepositoryWithMockedHttpClient(); + + $repository->getLists(self::ACCOUNT_ID); + } + + /** + * @test + */ + public function shouldGetFavoriteMovies() + { + $repository = $this->getRepositoryWithMockedHttpClient(); + + $repository->getFavoriteMovies(self::ACCOUNT_ID); + } + + /** + * @test + */ + public function shouldFavorite() + { + $repository = $this->getRepositoryWithMockedHttpClient(); + + $repository->favorite(self::ACCOUNT_ID, self::MOVIE_ID, true); + } + + /** + * @test + */ + public function shouldFavoriteMovieObject() + { + $repository = $this->getRepositoryWithMockedHttpClient(); + + $movie = new Movie(); + $movie->setId(self::MOVIE_ID); + + $repository->favorite(self::ACCOUNT_ID, $movie, true); + } + + /** + * @test + */ + public function shouldGetRatedMovies() + { + $repository = $this->getRepositoryWithMockedHttpClient(); + + $repository->getRatedMovies(self::ACCOUNT_ID); + } + + /** + * @test + */ + public function shouldWatchlist() + { + $repository = $this->getRepositoryWithMockedHttpClient(); + + $repository->watchlist(self::ACCOUNT_ID, self::MOVIE_ID, true); + } + + /** + * @test + */ + public function shouldWatchlistMovieObject() + { + $repository = $this->getRepositoryWithMockedHttpClient(); + + $movie = new Movie(); + $movie->setId(self::MOVIE_ID); + + $repository->watchlist(self::ACCOUNT_ID, $movie, true); + } + + /** + * @return Account + */ + protected function getApiClass() + { + return 'Tmdb\Api\Account'; + } + + /** + * @return AccountRepository + */ + protected function getRepositoryClass() + { + return 'Tmdb\Repository\AccountRepository'; + } +} \ No newline at end of file diff --git a/test/Tmdb/Tests/Repository/AuthenticationRepositoryTest.php b/test/Tmdb/Tests/Repository/AuthenticationRepositoryTest.php new file mode 100644 index 00000000..d2c6995e --- /dev/null +++ b/test/Tmdb/Tests/Repository/AuthenticationRepositoryTest.php @@ -0,0 +1,70 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Tests\Repository; + +use Tmdb\Api\Authentication; +use Tmdb\Model\Movie; +use Tmdb\Repository\AuthenticationRepository; +use Tmdb\RequestToken; +use Tmdb\SessionToken; + +class AuthenticationRepositoryTest extends TestCase +{ + /** + * @test + */ + public function shouldGetRequestToken() + { + $repository = $this->getRepositoryWithMockedHttpClient(); + + $repository->getRequestToken(); + } + + /** + * @test + */ + public function shouldGetSessionToken() + { + $repository = $this->getRepositoryWithMockedHttpClient(); + + $token = new RequestToken('test'); + + $repository->getSessionToken($token); + } + + /** + * @test + */ + public function shouldGetGuestSession() + { + $repository = $this->getRepositoryWithMockedHttpClient(); + + $repository->getGuestSessionToken(); + } + + /** + * @return Authentication + */ + protected function getApiClass() + { + return 'Tmdb\Api\Authentication'; + } + + /** + * @return AuthenticationRepository + */ + protected function getRepositoryClass() + { + return 'Tmdb\Repository\AuthenticationRepository'; + } +} \ No newline at end of file diff --git a/test/Tmdb/Tests/RequestTokenTest.php b/test/Tmdb/Tests/RequestTokenTest.php index 28187081..90608004 100644 --- a/test/Tmdb/Tests/RequestTokenTest.php +++ b/test/Tmdb/Tests/RequestTokenTest.php @@ -22,8 +22,10 @@ public function testSetGet() $token = new \Tmdb\RequestToken(); $token->setToken(self::REQUEST_TOKEN); $token->setExpiresAt('2012-02-09 19:50:25 UTC'); + $token->setSuccess(true); $this->assertEquals(self::REQUEST_TOKEN, $token->getToken()); $this->assertInstanceOf('DateTime', $token->getExpiresAt()); + $this->assertEquals(true, $token->getSuccess()); } } diff --git a/test/Tmdb/Tests/SessionTokenTest.php b/test/Tmdb/Tests/SessionTokenTest.php index 1822902f..2a9d0836 100644 --- a/test/Tmdb/Tests/SessionTokenTest.php +++ b/test/Tmdb/Tests/SessionTokenTest.php @@ -21,7 +21,11 @@ public function testSetGet() { $token = new \Tmdb\SessionToken(); $token->setToken(self::SESSION_TOKEN); + $token->setExpiresAt('2012-12-04 22:51:19 UTC'); + $token->setSuccess(true); $this->assertEquals(self::SESSION_TOKEN, $token->getToken()); + $this->assertEquals('04-12-2012', $token->getExpiresAt()->format('d-m-Y')); + $this->assertEquals(true, $token->getSuccess()); } } From ddc0af336d86b1ae32a9f7e3a16055abd1c07a57 Mon Sep 17 00:00:00 2001 From: Michael Roterman Date: Wed, 26 Feb 2014 20:59:29 +0100 Subject: [PATCH 16/16] Updating unit tests --- lib/Tmdb/Factory/AccountFactory.php | 32 ++- .../Tmdb/Tests/Factory/AccountFactoryTest.php | 164 +++++++++++++ .../Factory/AuthenticationFactoryTest.php | 101 ++++++++ .../Tmdb/Tests/Factory/ChangesFactoryTest.php | 5 +- .../AuthenticationRepositoryTest.php | 13 +- .../Tests/Repository/MovieRepositoryTest.php | 20 ++ .../Tests/Resources/account/favorite.json | 4 + .../Resources/account/favorite_movies.json | 207 ++++++++++++++++ test/Tmdb/Tests/Resources/account/get.json | 8 + test/Tmdb/Tests/Resources/account/lists.json | 157 ++++++++++++ .../Resources/account/movie_watchlist.json | 207 ++++++++++++++++ .../Tests/Resources/account/rated_movies.json | 227 ++++++++++++++++++ .../Tests/Resources/account/watchlist.json | 4 + .../authentication/guest_session_token.json | 5 + .../authentication/request_token.json | 5 + .../authentication/session_token.json | 4 + 16 files changed, 1157 insertions(+), 6 deletions(-) create mode 100644 test/Tmdb/Tests/Factory/AccountFactoryTest.php create mode 100644 test/Tmdb/Tests/Factory/AuthenticationFactoryTest.php create mode 100644 test/Tmdb/Tests/Resources/account/favorite.json create mode 100644 test/Tmdb/Tests/Resources/account/favorite_movies.json create mode 100644 test/Tmdb/Tests/Resources/account/get.json create mode 100644 test/Tmdb/Tests/Resources/account/lists.json create mode 100644 test/Tmdb/Tests/Resources/account/movie_watchlist.json create mode 100644 test/Tmdb/Tests/Resources/account/rated_movies.json create mode 100644 test/Tmdb/Tests/Resources/account/watchlist.json create mode 100644 test/Tmdb/Tests/Resources/authentication/guest_session_token.json create mode 100644 test/Tmdb/Tests/Resources/authentication/request_token.json create mode 100644 test/Tmdb/Tests/Resources/authentication/session_token.json diff --git a/lib/Tmdb/Factory/AccountFactory.php b/lib/Tmdb/Factory/AccountFactory.php index 3b1559f9..ef481754 100644 --- a/lib/Tmdb/Factory/AccountFactory.php +++ b/lib/Tmdb/Factory/AccountFactory.php @@ -23,9 +23,15 @@ class AccountFactory extends AbstractFactory */ private $movieFactory; + /** + * @var ImageFactory + */ + private $imageFactory; + public function __construct() { $this->movieFactory = new MovieFactory(); + $this->imageFactory = new ImageFactory(); } /** @@ -66,7 +72,13 @@ public function createMovie(array $data = array()) { */ public function createListItem(array $data = array()) { - return $this->hydrate(new Account\ListItem(), $data); + $listItem = new Account\ListItem(); + + if (array_key_exists('poster_path', $data)) { + $listItem->setPosterImage($this->getImageFactory()->createFromPath($data['poster_path'], 'poster_path')); + } + + return $this->hydrate($listItem, $data); } /** @@ -94,4 +106,22 @@ public function getMovieFactory() { return $this->movieFactory; } + + /** + * @param \Tmdb\Factory\ImageFactory $imageFactory + * @return $this + */ + public function setImageFactory($imageFactory) + { + $this->imageFactory = $imageFactory; + return $this; + } + + /** + * @return \Tmdb\Factory\ImageFactory + */ + public function getImageFactory() + { + return $this->imageFactory; + } } diff --git a/test/Tmdb/Tests/Factory/AccountFactoryTest.php b/test/Tmdb/Tests/Factory/AccountFactoryTest.php new file mode 100644 index 00000000..09610e23 --- /dev/null +++ b/test/Tmdb/Tests/Factory/AccountFactoryTest.php @@ -0,0 +1,164 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Tests\Factory; + +use Tmdb\Factory\AccountFactory; +use Tmdb\Model\Account; +use Tmdb\Model\Collection\ResultCollection; + +class AccountFactoryTest extends TestCase +{ + /** + * @test + */ + public function shouldGetAccount() + { + /** + * @var AccountFactory $factory + */ + $factory = $this->getFactory(); + + /** + * @var Account $account + */ + $account = $factory->create($this->loadByFile('account/get.json')); + + $this->assertEquals(36, $account->getId()); + $this->assertEquals(false, $account->getIncludeAdult()); + $this->assertEquals('US', $account->getIso31661()); + $this->assertEquals('en', $account->getIso6391()); + $this->assertEquals('John Doe', $account->getName()); + $this->assertEquals('johndoe', $account->getUsername()); + } + + /** + * @test + */ + public function shouldGetLists() + { + /** + * @var AccountFactory $factory + */ + $factory = $this->getFactory(); + + /** + * @var ResultCollection $collection + */ + $collection = $factory->createResultCollection($this->loadByFile('account/lists.json'), 'createListItem'); + + $this->assertInstanceOf('Tmdb\Model\Collection\ResultCollection', $collection); + $this->assertEquals(1, $collection->getPage()); + $this->assertEquals(1, $collection->getTotalPages()); + $this->assertEquals(15, $collection->getTotalResults()); + } + + /** + * @test + */ + public function shouldGetFavoriteMovies() + { + /** + * @var AccountFactory $factory + */ + $factory = $this->getFactory(); + + /** + * @var ResultCollection $collection + */ + $collection = $factory->createResultCollection($this->loadByFile('account/favorite_movies.json'), 'createMovie'); + + $this->assertInstanceOf('Tmdb\Model\Collection\ResultCollection', $collection); + $this->assertEquals(1, $collection->getPage()); + $this->assertEquals(2, $collection->getTotalPages()); + $this->assertEquals(34, $collection->getTotalResults()); + } + + /** + * @test + */ + public function shouldCreateStatus() + { + /** + * @var AccountFactory $factory + */ + $factory = $this->getFactory(); + + $status = $factory->createStatusResult($this->loadByFile('account/favorite.json')); + + $this->assertEquals(12, $status->getStatusCode()); + $this->assertEquals('The item/record was updated successfully', $status->getStatusMessage()); + } + + /** + * @test + */ + public function shouldGetRatedMovies() + { + /** + * @var AccountFactory $factory + */ + $factory = $this->getFactory(); + + /** + * @var ResultCollection $collection + */ + $collection = $factory->createResultCollection($this->loadByFile('account/rated_movies.json'), 'createMovie'); + + $this->assertInstanceOf('Tmdb\Model\Collection\ResultCollection', $collection); + $this->assertEquals(1, $collection->getPage()); + $this->assertEquals(12, $collection->getTotalPages()); + $this->assertEquals(239, $collection->getTotalResults()); + } + + /** + * @test + */ + public function shouldGetMovieWatchlist() + { + /** + * @var AccountFactory $factory + */ + $factory = $this->getFactory(); + + /** + * @var ResultCollection $collection + */ + $collection = $factory->createResultCollection($this->loadByFile('account/movie_watchlist.json'), 'createMovie'); + + $this->assertInstanceOf('Tmdb\Model\Collection\ResultCollection', $collection); + $this->assertEquals(1, $collection->getPage()); + $this->assertEquals(4, $collection->getTotalPages()); + $this->assertEquals(67, $collection->getTotalResults()); + } + + /** + * @test + */ + public function shouldWatchlist() + { + /** + * @var AccountFactory $factory + */ + $factory = $this->getFactory(); + + $status = $factory->createStatusResult($this->loadByFile('account/watchlist.json')); + + $this->assertEquals(1, $status->getStatusCode()); + $this->assertEquals('Success', $status->getStatusMessage()); + } + + protected function getFactoryClass() + { + return 'Tmdb\Factory\AccountFactory'; + } +} \ No newline at end of file diff --git a/test/Tmdb/Tests/Factory/AuthenticationFactoryTest.php b/test/Tmdb/Tests/Factory/AuthenticationFactoryTest.php new file mode 100644 index 00000000..028dfd58 --- /dev/null +++ b/test/Tmdb/Tests/Factory/AuthenticationFactoryTest.php @@ -0,0 +1,101 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Tests\Factory; + +use Tmdb\Factory\AuthenticationFactory; + +class AuthenticationFactoryTest extends TestCase +{ + /** + * @test + */ + public function shouldCreateRequestToken() + { + /** + * @var AuthenticationFactory $factory + */ + $factory = $this->getFactory(); + + $token = $factory->createRequestToken($this->loadByFile('authentication/request_token.json')); + + $this->assertEquals('09-02-2012', $token->getExpiresAt()->format('d-m-Y')); + $this->assertEquals('641bf16c663db167c6cffcdff41126039d4445bf', $token->getToken()); + $this->assertEquals(true, $token->getSuccess()); + } + + /** + * @test + */ + public function shouldCreateSessionToken() + { + /** + * @var AuthenticationFactory $factory + */ + $factory = $this->getFactory(); + + $token = $factory->createSessionToken($this->loadByFile('authentication/session_token.json')); + + $this->assertEquals('80b2bf99520cd795ff54e31af97917bc9e3a7c8c', $token->getToken()); + $this->assertEquals(true, $token->getSuccess()); + } + + /** + * @test + */ + public function shouldCreateGuestSessionToken() + { + /** + * @var AuthenticationFactory $factory + */ + $factory = $this->getFactory(); + + $token = $factory->createGuestSessionToken($this->loadByFile('authentication/guest_session_token.json')); + + $this->assertEquals('04-12-2012', $token->getExpiresAt()->format('d-m-Y')); + $this->assertEquals('0c550fd5da2fc3f321ab3bs9b60ca108', $token->getToken()); + $this->assertEquals(true, $token->getSuccess()); + } + + /** + * @test + * @expectedException \Tmdb\Exception\NotImplementedException + */ + public function shouldThrowExceptionForCreate() + { + /** + * @var AuthenticationFactory $factory + */ + $factory = $this->getFactory(); + + $factory->create(array()); + } + + /** + * @test + * @expectedException \Tmdb\Exception\NotImplementedException + */ + public function shouldThrowExceptionForCreateCollection() + { + /** + * @var AuthenticationFactory $factory + */ + $factory = $this->getFactory(); + + $factory->createCollection(array()); + } + + protected function getFactoryClass() + { + return 'Tmdb\Factory\AuthenticationFactory'; + } +} \ No newline at end of file diff --git a/test/Tmdb/Tests/Factory/ChangesFactoryTest.php b/test/Tmdb/Tests/Factory/ChangesFactoryTest.php index b3c0cb59..5524238c 100644 --- a/test/Tmdb/Tests/Factory/ChangesFactoryTest.php +++ b/test/Tmdb/Tests/Factory/ChangesFactoryTest.php @@ -14,12 +14,9 @@ use Tmdb\Factory\CompanyFactory; use Tmdb\Model\Collection\Changes; -use Tmdb\Model\Company; class ChangesFactoryTest extends TestCase { - const COMPANY_ID = 1; - private $data; /** @@ -37,7 +34,7 @@ public function setUp() $factory = $this->getFactory(); /** - * @var Company $company + * @var Changes $changes */ $this->changes = $factory->createCollection($this->data); } diff --git a/test/Tmdb/Tests/Repository/AuthenticationRepositoryTest.php b/test/Tmdb/Tests/Repository/AuthenticationRepositoryTest.php index d2c6995e..085f26f1 100644 --- a/test/Tmdb/Tests/Repository/AuthenticationRepositoryTest.php +++ b/test/Tmdb/Tests/Repository/AuthenticationRepositoryTest.php @@ -16,7 +16,6 @@ use Tmdb\Model\Movie; use Tmdb\Repository\AuthenticationRepository; use Tmdb\RequestToken; -use Tmdb\SessionToken; class AuthenticationRepositoryTest extends TestCase { @@ -42,6 +41,18 @@ public function shouldGetSessionToken() $repository->getSessionToken($token); } + /** + * @test + */ + public function shouldAuthenticateRequestToken() + { + $repository = $this->getRepositoryWithMockedHttpClient(); + + $token = new RequestToken('test'); + + $repository->getSessionToken($token); + } + /** * @test */ diff --git a/test/Tmdb/Tests/Repository/MovieRepositoryTest.php b/test/Tmdb/Tests/Repository/MovieRepositoryTest.php index 33c66db1..d306d699 100644 --- a/test/Tmdb/Tests/Repository/MovieRepositoryTest.php +++ b/test/Tmdb/Tests/Repository/MovieRepositoryTest.php @@ -189,6 +189,26 @@ public function shouldGetTopRated() $repository->getTopRated(); } + /** + * @test + */ + public function shouldGetAccountStates() + { + $repository = $this->getRepositoryWithMockedHttpClient(); + + $repository->getAccountStates('id'); + } + + /** + * @test + */ + public function shouldRate() + { + $repository = $this->getRepositoryWithMockedHttpClient(); + + $repository->rate('id', 5.2); + } + /** * @test */ diff --git a/test/Tmdb/Tests/Resources/account/favorite.json b/test/Tmdb/Tests/Resources/account/favorite.json new file mode 100644 index 00000000..0738a914 --- /dev/null +++ b/test/Tmdb/Tests/Resources/account/favorite.json @@ -0,0 +1,4 @@ +{ + "status_code": 12, + "status_message": "The item/record was updated successfully" +} \ No newline at end of file diff --git a/test/Tmdb/Tests/Resources/account/favorite_movies.json b/test/Tmdb/Tests/Resources/account/favorite_movies.json new file mode 100644 index 00000000..d670e300 --- /dev/null +++ b/test/Tmdb/Tests/Resources/account/favorite_movies.json @@ -0,0 +1,207 @@ +{ + "page": 1, + "results": [ + { + "backdrop_path": "/wrKcSXtHz4LedgEf1aW5e4ZVyHJ.jpg", + "id": 9806, + "original_title": "The Incredibles", + "release_date": "2004-11-05", + "poster_path": "/9k4sgKD79q0MDHSWIqNnHqOfOEV.jpg", + "title": "The Incredibles", + "vote_average": 8.5999999999999996, + "vote_count": 46 + }, + { + "backdrop_path": "/uAVdwu4vEx0TwuC4ewp9RqplKEV.jpg", + "id": 1452, + "original_title": "Superman Returns", + "release_date": "2006-06-21", + "poster_path": "/qpsarVxFcxJxtCK5dAoHLt3365R.jpg", + "title": "Superman Returns", + "vote_average": 6.5999999999999996, + "vote_count": 20 + }, + { + "backdrop_path": "/x9a4Q6Qlgh9Fk1f5z6K4r5OeLd9.jpg", + "id": 8960, + "original_title": "Hancock", + "release_date": "2008-07-02", + "poster_path": "/dsCxSr4w3g2ylhlZg3v5CB5Pid7.jpg", + "title": "Hancock", + "vote_average": 7.0, + "vote_count": 34 + }, + { + "backdrop_path": "/oPE44KcuRBKfuE15RD8sC2awh3P.jpg", + "id": 9741, + "original_title": "Unbreakable", + "release_date": "2000-11-14", + "poster_path": "/ndb1jugavBmgcfZKrfHXxC0T6al.jpg", + "title": "Unbreakable", + "vote_average": 7.7999999999999998, + "vote_count": 25 + }, + { + "backdrop_path": "/7u3pxc0K1wx32IleAkLv78MKgrw.jpg", + "id": 603, + "original_title": "The Matrix", + "release_date": "1999-03-31", + "poster_path": "/gynBNzwyaHKtXqlEKKLioNkjKgN.jpg", + "title": "The Matrix", + "vote_average": 9.0999999999999996, + "vote_count": 249 + }, + { + "backdrop_path": "/af98P1bc7lJsFjhHOVWXQgNNgSQ.jpg", + "id": 424, + "original_title": "Schindler's List", + "release_date": "1993-11-30", + "poster_path": "/I2lJ7ens7Rzlm3x5HfDbwF3ykh.jpg", + "title": "Schindler's List", + "vote_average": 8.6999999999999993, + "vote_count": 41 + }, + { + "backdrop_path": "/6kVVfNT0auG6fU5SFQ1zbayNWUC.jpg", + "id": 7191, + "original_title": "Cloverfield", + "release_date": "2008-01-16", + "poster_path": "/as01o40tJ2FhtheqeXf7bVZ0EQO.jpg", + "title": "Cloverfield", + "vote_average": 7.2000000000000002, + "vote_count": 35 + }, + { + "backdrop_path": "/6yFoLNQgFdVbA8TZMdfgVpszOla.jpg", + "id": 218, + "original_title": "The Terminator", + "release_date": "1984-10-26", + "poster_path": "/q8ffBuxQlYOHrvPniLgCbmKK4Lv.jpg", + "title": "The Terminator", + "vote_average": 8.5999999999999996, + "vote_count": 67 + }, + { + "backdrop_path": "/8uO0gUM8aNqYLs1OsTBQiXu0fEv.jpg", + "id": 550, + "original_title": "Fight Club", + "release_date": "1999-10-15", + "poster_path": "/2lECpi35Hnbpa4y46JX0aY3AWTy.jpg", + "title": "Fight Club", + "vote_average": 9.0999999999999996, + "vote_count": 175 + }, + { + "backdrop_path": "/siKq2bQo09YGLTiqvKR1pXJ5li9.jpg", + "id": 23483, + "original_title": "Kick-Ass", + "release_date": "2010-04-16", + "poster_path": "/gtfggr5n3ED1neoTqVYmsVCoSS.jpg", + "title": "Kick-Ass", + "vote_average": 8.3000000000000007, + "vote_count": 108 + }, + { + "backdrop_path": "/419GfpzSip2cXf17x8FKIRHSSPK.jpg", + "id": 679, + "original_title": "Aliens", + "release_date": "1986-07-18", + "poster_path": "/qet8RDq99dRteBfSRfGeZeqY9xe.jpg", + "title": "Aliens", + "vote_average": 8.8000000000000007, + "vote_count": 107 + }, + { + "backdrop_path": "/sCtmAY3DgrFOjlrDh6mP7luUO7t.jpg", + "id": 489, + "original_title": "Good Will Hunting", + "release_date": "1997-12-05", + "poster_path": "/3yHtbRfp32AouPSwYESoJM3cOeQ.jpg", + "title": "Good Will Hunting", + "vote_average": 8.8000000000000007, + "vote_count": 32 + }, + { + "backdrop_path": "/5YF6MwuuKBRKLUE2dz3wetkgxAE.jpg", + "id": 453, + "original_title": "A Beautiful Mind", + "release_date": "2001-12-13", + "poster_path": "/79L8f0qbawvmdXE4ThVstC5sOxP.jpg", + "title": "A Beautiful Mind", + "vote_average": 8.5, + "vote_count": 28 + }, + { + "backdrop_path": "/bYtrTSGDqvd2KlHTO78b4Y3S4E9.jpg", + "id": 807, + "original_title": "Se7en", + "release_date": "1995-09-22", + "poster_path": "/zgB9CCTDlXRv50Z70ZI4elJtNEk.jpg", + "title": "Se7en", + "vote_average": 8.9000000000000004, + "vote_count": 96 + }, + { + "backdrop_path": "/6HbOqP1GUElNLdX8Bx2uP542CIP.jpg", + "id": 180, + "original_title": "Minority Report", + "release_date": "2002-06-21", + "poster_path": "/h3lpltSn7Rj1eYTPQO1lYGdw4Bz.jpg", + "title": "Minority Report", + "vote_average": 8.3000000000000007, + "vote_count": 34 + }, + { + "backdrop_path": "/i9A0UMFg1hI2kLyCCwnmSbpT2cd.jpg", + "id": 73, + "original_title": "American History X", + "release_date": "1998-10-30", + "poster_path": "/fXepRAYOx1qC3wju7XdDGx60775.jpg", + "title": "American History X", + "vote_average": 8.6999999999999993, + "vote_count": 61 + }, + { + "backdrop_path": "/5XPPB44RQGfkBrbJxmtdndKz05n.jpg", + "id": 19995, + "original_title": "Avatar", + "release_date": "2009-12-18", + "poster_path": "/s66l83fTQp0FAJsJqY0xUmkamcx.jpg", + "title": "Avatar", + "vote_average": 7.9000000000000004, + "vote_count": 516 + }, + { + "backdrop_path": "/e1uECwkwbD5Zpm9Gc6eb5mbG4C4.jpg", + "id": 38, + "original_title": "Eternal Sunshine of the Spotless Mind", + "release_date": "2004-03-19", + "poster_path": "/gutwXkVChJkpIrclokNESybj0GC.jpg", + "title": "Eternal Sunshine of the Spotless Mind", + "vote_average": 8.6999999999999993, + "vote_count": 57 + }, + { + "backdrop_path": "/tv8J6uCTKsTlASa8luJqrFiJlBX.jpg", + "id": 78, + "original_title": "Blade Runner", + "release_date": "1982-06-25", + "poster_path": "/ewq1lwhOT8GqBcQH1w8D1BagwTh.jpg", + "title": "Blade Runner", + "vote_average": 9.0, + "vote_count": 147 + }, + { + "backdrop_path": "/2nFyTvssbtJMLC6eyYwwZ88gALD.jpg", + "id": 10681, + "original_title": "WALL·E", + "release_date": "2008-06-27", + "poster_path": "/9cJETuLMc6R0bTWRA5i7ctY9bxk.jpg", + "title": "WALL·E", + "vote_average": 8.6999999999999993, + "vote_count": 164 + } + ], + "total_pages": 2, + "total_results": 34 +} \ No newline at end of file diff --git a/test/Tmdb/Tests/Resources/account/get.json b/test/Tmdb/Tests/Resources/account/get.json new file mode 100644 index 00000000..a8f30552 --- /dev/null +++ b/test/Tmdb/Tests/Resources/account/get.json @@ -0,0 +1,8 @@ +{ + "id": 36, + "include_adult": false, + "iso_3166_1": "US", + "iso_639_1": "en", + "name": "John Doe", + "username": "johndoe" +} \ No newline at end of file diff --git a/test/Tmdb/Tests/Resources/account/lists.json b/test/Tmdb/Tests/Resources/account/lists.json new file mode 100644 index 00000000..4e4b9249 --- /dev/null +++ b/test/Tmdb/Tests/Resources/account/lists.json @@ -0,0 +1,157 @@ +{ + "page": 1, + "results": [ + { + "description": "A list of \"frightful flicks waiting to be rediscovered\" -- compiled by the self-described leading name in the world of horror: Fangoria magazine.", + "favorite_count": 2, + "id": "50a6724919c295084b000028", + "item_count": 101, + "iso_639_1": "en", + "list_type": "movie", + "name": "Fangoria's 101 Best Horror Movies You've Never Seen", + "poster_path": "/3sL73Vy4kkrH4P61RA0n6UyYGlQ.jpg" + }, + { + "description": "Part of the AFI 100 Years… series, AFI's 100 Years…100 Thrills is a list of the top 100 heart-pounding movies in American cinema. The list was unveiled by the American Film Institute on June 12, 2001, during a CBS special hosted by Harrison Ford.", + "favorite_count": 2, + "id": "50a54d01760ee32e1400000b", + "item_count": 100, + "iso_639_1": "en", + "list_type": "movie", + "name": "AFI's 100 Most Thrilling American Films", + "poster_path": "/tayO4gCLyEo8Uul8FHkJGy3Kppb.jpg" + }, + { + "description": "A list of films that earned its actresses the Razzie Award for Worst Actress of the year.", + "favorite_count": 2, + "id": "509fca90760ee3490f000a12", + "item_count": 40, + "iso_639_1": "en", + "list_type": "movie", + "name": "Films featuring a Razzie winning Worst Actress Performance", + "poster_path": "/eL61XP1l8H0qrBPJoKqhXdxumkw.jpg" + }, + { + "description": "A list of all films in the Star Wars universe including the theatrical motion picture releases.", + "favorite_count": 2, + "id": "509fc02119c295114a0007cb", + "item_count": 14, + "iso_639_1": "en", + "list_type": "movie", + "name": "Star Wars Expanded Universe", + "poster_path": "/rf6uEcD5V8zs4J7Huo5L9sYgSki.jpg" + }, + { + "description": "Here's my list of best picture winners for the Oscars. Thought it would be neat to see them all together. There's a lot of movies here I have never even heard of.", + "favorite_count": 1, + "id": "509ec17c19c2950a0600050e", + "item_count": 84, + "iso_639_1": "en", + "list_type": "movie", + "name": "Best Picture Winners - The Academy Awards", + "poster_path": "/efBm2Nm2v5kQnO0w3hYcW6hVsJU.jpg" + }, + { + "description": "A list of the films that were nominated at the 2008 Oscars for best picture.", + "favorite_count": 1, + "id": "509ec007760ee36f0c000917", + "item_count": 5, + "iso_639_1": "en", + "list_type": "movie", + "name": "80th Academy Awards (2008) - Best Picture Nominations", + "poster_path": "/nWwFabqFaBbukXdkUCmtnrFxPNh.jpg" + }, + { + "description": "The View Askewniverse is a fictional universe created by writer/director Kevin Smith, featured in several films, comics and a television series; it is named for Smith's production company, View Askew Productions.", + "favorite_count": 2, + "id": "509691b119c29532730008fb", + "item_count": 6, + "iso_639_1": "en", + "list_type": "movie", + "name": "The View Askewniverse", + "poster_path": "/tGmU66LL8edoRm1RO7sbrz1xuhr.jpg" + }, + { + "description": "Name pretty much says it all, here's the top 50 grossing films of all time.", + "favorite_count": 2, + "id": "50957b1419c295013800023e", + "item_count": 50, + "iso_639_1": "en", + "list_type": "movie", + "name": "Top 50 Grossing Films of All Time (Worldwide)", + "poster_path": "/sRbZeVtRKIWybTOVpCRPZtzW5bd.jpg" + }, + { + "description": "A list of the films that were nominated at the 2009 Oscars for best picture.", + "favorite_count": 2, + "id": "50957064760ee3698a001fc1", + "item_count": 5, + "iso_639_1": "en", + "list_type": "movie", + "name": "81st Academy Awards (2009) - Best Picture Nominations", + "poster_path": "/gShtwIvdSHgCEQRZfymNkEUEwFm.jpg" + }, + { + "description": "A list of the films that were nominated at the 2010 Oscars for best picture.", + "favorite_count": 2, + "id": "50956fd2760ee3698a001fb1", + "item_count": 10, + "iso_639_1": "en", + "list_type": "movie", + "name": "82nd Academy Awards (2010) - Best Picture Nominations", + "poster_path": "/8iwe0iP49A6Gqcv31jBleZDZqI4.jpg" + }, + { + "description": "A list of the theatrical releases for Marvel's Avengers characters that are in the latest Avengers movie.", + "favorite_count": 3, + "id": "50953114760ee34b91000293", + "item_count": 7, + "iso_639_1": "en", + "list_type": "movie", + "name": "The Avengers", + "poster_path": "/2i89ujVkhJebuoB2zy6QZcwbr2N.jpg" + }, + { + "description": "A list of the films that were nominated at the 2011 Oscars for best picture.", + "favorite_count": 1, + "id": "509431ad19c2950b01000004", + "item_count": 10, + "iso_639_1": "en", + "list_type": "movie", + "name": "83rd Academy Awards (2011) - Best Picture Nominations", + "poster_path": "/iAHDZPyLD3NW7GuNV6U1TVtb0hN.jpg" + }, + { + "description": "Here's a list of the films that take place in the DC Comics universe.", + "favorite_count": 2, + "id": "5094147819c2955e4c00006b", + "item_count": 22, + "iso_639_1": "en", + "list_type": "movie", + "name": "The DC Comics Universe", + "poster_path": "/4H1jWsgEQOgTs4KeG5j5BorKMfX.jpg" + }, + { + "description": "A list of the films that were nominated at the 2012 Oscars for best picture.", + "favorite_count": 1, + "id": "50941340760ee35da9000054", + "item_count": 9, + "iso_639_1": "en", + "list_type": "movie", + "name": "84th Academy Awards (2012) - Best Picture Nominations", + "poster_path": "/zRqBleU93WncYnIwt8LAanQerZ7.jpg" + }, + { + "description": "The idea behind this list is to collect the live action comic book movies from within the Marvel franchise.", + "favorite_count": 5, + "id": "50941077760ee35e1500000d", + "item_count": 33, + "iso_639_1": "en", + "list_type": "movie", + "name": "The Marvel Universe", + "poster_path": "/w2JbuNpBnfevl0yCcYEm6vNFWdi.jpg" + } + ], + "total_pages": 1, + "total_results": 15 +} \ No newline at end of file diff --git a/test/Tmdb/Tests/Resources/account/movie_watchlist.json b/test/Tmdb/Tests/Resources/account/movie_watchlist.json new file mode 100644 index 00000000..383b62d3 --- /dev/null +++ b/test/Tmdb/Tests/Resources/account/movie_watchlist.json @@ -0,0 +1,207 @@ +{ + "page": 1, + "results": [ + { + "backdrop_path": "/xetk5vdoKxMIto5O5boqPGxWnoA.jpg", + "id": 76726, + "original_title": "Chronicle", + "release_date": "2012-02-03", + "poster_path": "/pSYRHYvOd8aFaddVUdyXJGZ8F6W.jpg", + "title": "Chronicle", + "vote_average": 7.2999999999999998, + "vote_count": 32 + }, + { + "backdrop_path": "/g9CDUXFBflsIch95wZxeNajTTX2.jpg", + "id": 70435, + "original_title": "Haywire", + "release_date": "2011-11-07", + "poster_path": "/8RlFYPPDFPr3ADrNHFGyB0JS6mo.jpg", + "title": "Haywire", + "vote_average": 6.9000000000000004, + "vote_count": 18 + }, + { + "backdrop_path": "/hbn46fQaRmlpBuUrEiFqv0GDL6Y.jpg", + "id": 24428, + "original_title": "The Avengers", + "release_date": "2012-05-04", + "poster_path": "/cezWGskPY5x7GaglTTRN4Fugfb8.jpg", + "title": "The Avengers", + "vote_average": 8.5, + "vote_count": 117 + }, + { + "backdrop_path": "/5Jj4SpbsxmH2yOlhka4LvNRtSud.jpg", + "id": 22970, + "original_title": "The Cabin in the Woods", + "release_date": "2012-04-13", + "poster_path": "/t8cW3FSCDYCaWRiNHSvI6SDuWeA.jpg", + "title": "The Cabin in the Woods", + "vote_average": 6.9000000000000004, + "vote_count": 22 + }, + { + "backdrop_path": "/8iNsXY3LPsuT0gnUiTBMoNuRZI7.jpg", + "id": 52520, + "original_title": "Underworld: Awakening", + "release_date": "2012-01-20", + "poster_path": "/76GXWKs2IDi0ZERKLT57wkToV0A.jpg", + "title": "Underworld: Awakening", + "vote_average": 7.5, + "vote_count": 36 + }, + { + "backdrop_path": "/gVfnoiCJBdv2SN7poIbU7eyNVq1.jpg", + "id": 12437, + "original_title": "Underworld: Rise of the Lycans", + "release_date": "2009-01-23", + "poster_path": "/hZtK6fkusSKzGc0f7yQ2syo14Ze.jpg", + "title": "Underworld: Rise of the Lycans", + "vote_average": 7.2999999999999998, + "vote_count": 30 + }, + { + "backdrop_path": "/LvmmDZxkTDqp0DX7mUo621ahdX.jpg", + "id": 10195, + "original_title": "Thor", + "release_date": "2011-05-06", + "poster_path": "/jqcMUV73jEhO0gv5yi28FD8JbHQ.jpg", + "title": "Thor", + "vote_average": 7.2000000000000002, + "vote_count": 79 + }, + { + "backdrop_path": "/1ueWzFe8Klk5WDurB5j8yl5qdaq.jpg", + "id": 1771, + "original_title": "Captain America: The First Avenger", + "release_date": "2011-07-22", + "poster_path": "/sBZs1jSybBRBXDwcCR8IOyHLUMc.jpg", + "title": "Captain America: The First Avenger", + "vote_average": 7.5, + "vote_count": 73 + }, + { + "backdrop_path": "/uOpFdld7CIifSEoGuRVgWqaeyFs.jpg", + "id": 64688, + "original_title": "21 Jump Street", + "release_date": "2012-05-10", + "poster_path": "/mH6xazzfGdszadd1Xy9JgdZYvn1.jpg", + "title": "21 Jump Street", + "vote_average": 7.5, + "vote_count": 25 + }, + { + "backdrop_path": "/9mnDfS7nuja6wCGK5bBG3412Qdo.jpg", + "id": 17578, + "original_title": "The Adventures of Tintin", + "release_date": "2011-10-26", + "poster_path": "/7NwqKqEqJDmFP8hkLBpV0Sk6xek.jpg", + "title": "The Adventures of Tintin", + "vote_average": 7.7000000000000002, + "vote_count": 47 + }, + { + "backdrop_path": "/wX0mOAa91dTAT2WCGRvvpWUKAeD.jpg", + "id": 59961, + "original_title": "Safe House", + "release_date": "2012-02-16", + "poster_path": "/itJBQuozyehzoTh0X4YpKwIiFLy.jpg", + "title": "Safe House", + "vote_average": 7.5999999999999996, + "vote_count": 39 + }, + { + "backdrop_path": "/elnVoZPBXwGVh5xD5PLbvIzmvOZ.jpg", + "id": 8967, + "original_title": "The Tree of Life", + "release_date": "2011-05-27", + "poster_path": "/5uiccn657MLiAbVHS5SfWFdeSTw.jpg", + "title": "The Tree of Life", + "vote_average": 7.4000000000000004, + "vote_count": 19 + }, + { + "backdrop_path": "/cnGPiAd7D50YFcpt6HK7CwTUCew.jpg", + "id": 49530, + "original_title": "In Time", + "release_date": "2011-10-28", + "poster_path": "/lnYuAr3QOPzvuEFlzpsRUq41IEy.jpg", + "title": "In Time", + "vote_average": 6.9000000000000004, + "vote_count": 54 + }, + { + "backdrop_path": "/1qQiuN2QlBR3VmIwqBXYFGCCZbl.jpg", + "id": 49527, + "original_title": "Man on a Ledge", + "release_date": "2012-01-27", + "poster_path": "/ssl4ZcThbMtEPNBEXmWpSgtT9xK.jpg", + "title": "Man on a Ledge", + "vote_average": 7.2000000000000002, + "vote_count": 16 + }, + { + "backdrop_path": "/gxbO2y8jeEvwGHDLC8ErqSf61ca.jpg", + "id": 80389, + "original_title": "Get the Gringo", + "release_date": "2012-05-01", + "poster_path": "/6yo4E8B0WbIpiHbY01Dq8r6dH8V.jpg", + "title": "Get the Gringo", + "vote_average": 7.7000000000000002, + "vote_count": 8 + }, + { + "backdrop_path": "/pbYQevN15y5aEusvcsp3bpuu5Ip.jpg", + "id": 65754, + "original_title": "The Girl with the Dragon Tattoo", + "release_date": "2011-12-21", + "poster_path": "/voxRWFTtagLiqnJQs9tWQLB0MN.jpg", + "title": "The Girl with the Dragon Tattoo", + "vote_average": 7.9000000000000004, + "vote_count": 49 + }, + { + "backdrop_path": "/3DdCnPuMq5QRXRE4PMrI3VEQI94.jpg", + "id": 13007, + "original_title": "Religulous", + "release_date": "2008-10-01", + "poster_path": "/lGo6P1rEs1GJnYJW9a6whlcljtZ.jpg", + "title": "Religulous", + "vote_average": 7.4000000000000004, + "vote_count": 4 + }, + { + "backdrop_path": "/wWwHt3NvdnGLXrGRR4n7GU6ISkh.jpg", + "id": 64690, + "original_title": "Drive", + "release_date": "2012-01-26", + "poster_path": "/fsnaaNQ4RmZwgRv6qfT7NIi41Sj.jpg", + "title": "Drive", + "vote_average": 7.7999999999999998, + "vote_count": 80 + }, + { + "backdrop_path": "/dNdrWdlOEuisZ1YyafkkPEWAihn.jpg", + "id": 12690, + "original_title": "Appaloosa", + "release_date": "2008-10-03", + "poster_path": "/5Ql3TsG08yvVBDyV5azOWUVKmuy.jpg", + "title": "Appaloosa", + "vote_average": 7.4000000000000004, + "vote_count": 13 + }, + { + "backdrop_path": "/7u3UyejCbhM3jXcZ86xzA9JJxge.jpg", + "id": 41154, + "original_title": "Men in Black 3", + "release_date": "2012-05-25", + "poster_path": "/sIuneIyme2O3qYxEZTVNyJ0F0LC.jpg", + "title": "Men in Black 3", + "vote_average": 7.5, + "vote_count": 27 + } + ], + "total_pages": 4, + "total_results": 67 +} \ No newline at end of file diff --git a/test/Tmdb/Tests/Resources/account/rated_movies.json b/test/Tmdb/Tests/Resources/account/rated_movies.json new file mode 100644 index 00000000..151d4929 --- /dev/null +++ b/test/Tmdb/Tests/Resources/account/rated_movies.json @@ -0,0 +1,227 @@ +{ + "page": 1, + "results": [ + { + "backdrop_path": "/tjMZ4RBLhvk670gYJPxIN8SBfnB.jpg", + "id": 13, + "original_title": "Forrest Gump", + "release_date": "1994-06-23", + "poster_path": "/iZvCkb34CAmV9BETIrHY4yiS115.jpg", + "rating": 8.0, + "title": "Forrest Gump", + "vote_average": 8.9000000000000004, + "vote_count": 84 + }, + { + "backdrop_path": "/e1uECwkwbD5Zpm9Gc6eb5mbG4C4.jpg", + "id": 38, + "original_title": "Eternal Sunshine of the Spotless Mind", + "release_date": "2004-03-19", + "poster_path": "/gutwXkVChJkpIrclokNESybj0GC.jpg", + "rating": 9.0, + "title": "Eternal Sunshine of the Spotless Mind", + "vote_average": 8.6999999999999993, + "vote_count": 57 + }, + { + "backdrop_path": "/gTFGr8q5YzYYiRyDYaEMNB6QRuL.jpg", + "id": 106, + "original_title": "Predator", + "release_date": "1987-06-12", + "poster_path": "/gUpto7r2XwoM5eW7MUvd8hl1etB.jpg", + "rating": 6.0, + "title": "Predator", + "vote_average": 8.4000000000000004, + "vote_count": 49 + }, + { + "backdrop_path": "/cNLZ7YGRikb4IsLblrzu86ndZPw.jpg", + "id": 107, + "original_title": "Snatch", + "release_date": "2000-12-06", + "poster_path": "/on9JlbGEccLsYkjeEph2Whm1DIp.jpg", + "rating": 8.0, + "title": "Snatch", + "vote_average": 8.5999999999999996, + "vote_count": 55 + }, + { + "backdrop_path": "/pIUvQ9Ed35wlWhY2oU6OmwEsmzG.jpg", + "id": 120, + "original_title": "The Lord of the Rings: The Fellowship of the Ring", + "release_date": "2001-12-19", + "poster_path": "/9HG6pINW1KoFTAKY3LdybkoOKAm.jpg", + "rating": 8.0, + "title": "The Lord of the Rings: The Fellowship of the Ring", + "vote_average": 8.8000000000000007, + "vote_count": 125 + }, + { + "backdrop_path": "/nnMC0BM6XbjIIrT4miYmMtPGcQV.jpg", + "id": 155, + "original_title": "The Dark Knight", + "release_date": "2008-07-18", + "poster_path": "/1hRoyzDtpgMU7Dz4JF22RANzQO7.jpg", + "rating": 9.0, + "title": "The Dark Knight", + "vote_average": 8.8000000000000007, + "vote_count": 269 + }, + { + "backdrop_path": "/uv5BRIaJKfcPBPEBV8qfTjD6PuY.jpg", + "id": 12, + "original_title": "Finding Nemo", + "release_date": "2003-05-30", + "poster_path": "/zjqInUwldOBa0q07fOyohYCWxWX.jpg", + "rating": 8.0, + "title": "Finding Nemo", + "vote_average": 8.6999999999999993, + "vote_count": 41 + }, + { + "backdrop_path": "/kriCxQiDhdosxzYXEf5JApMdmyq.jpg", + "id": 187, + "original_title": "Sin City", + "release_date": "2005-04-01", + "poster_path": "/eCJkepVJslq1nEtqURLaC1zLPAL.jpg", + "rating": 8.0, + "title": "Sin City", + "vote_average": 8.4000000000000004, + "vote_count": 64 + }, + { + "backdrop_path": "/6xKCYgH16UuwEGAyroLU6p8HLIn.jpg", + "id": 238, + "original_title": "The Godfather", + "release_date": "1972-03-24", + "poster_path": "/d4KNaTrltq6bpkFS01pYtyXa09m.jpg", + "rating": 9.0, + "title": "The Godfather", + "vote_average": 9.1999999999999993, + "vote_count": 125 + }, + { + "backdrop_path": "/iX99sWgGZCnjPpDgG29E0HomMLI.jpg", + "id": 275, + "original_title": "Fargo", + "release_date": "1996-03-15", + "poster_path": "/gO0Q7TMuu8PJ9Y736VTgvY02rVD.jpg", + "rating": 8.0, + "title": "Fargo", + "vote_average": 8.1999999999999993, + "vote_count": 29 + }, + { + "backdrop_path": "/d9AqtruwS8nljKjL5aYzM42hQJr.jpg", + "id": 280, + "original_title": "Terminator 2: Judgment Day", + "release_date": "1991-07-01", + "poster_path": "/2y4dmgWYRMYXdD1UyJVcn2HSd1D.jpg", + "rating": 8.0, + "title": "Terminator 2: Judgment Day", + "vote_average": 9.0999999999999996, + "vote_count": 106 + }, + { + "backdrop_path": "/xRqsFFteJrvLHxswk78NzU7zOrU.jpg", + "id": 289, + "original_title": "Casablanca", + "release_date": "1942-11-26", + "poster_path": "/sm1QVZu5RKe1vXVHZooo4SZyHMx.jpg", + "rating": 8.0, + "title": "Casablanca", + "vote_average": 8.5, + "vote_count": 27 + }, + { + "backdrop_path": "/heNbD1JojBNz6kfHWr3O8Uk0a3a.jpg", + "id": 296, + "original_title": "Terminator 3: Rise of the Machines", + "release_date": "2003-06-30", + "poster_path": "/lz4xYdF1n09lyiCfZWtWT44SZiG.jpg", + "rating": 7.0, + "title": "Terminator 3: Rise of the Machines", + "vote_average": 6.7000000000000002, + "vote_count": 44 + }, + { + "backdrop_path": "/wH8vtnsmU4olFJ5wSRHo8RXRhKF.jpg", + "id": 310, + "original_title": "Bruce Almighty", + "release_date": "2003-05-23", + "poster_path": "/oHA5eAeJh7ChPsHnSsppNx4ta6L.jpg", + "rating": 8.0, + "title": "Bruce Almighty", + "vote_average": 7.7000000000000002, + "vote_count": 25 + }, + { + "backdrop_path": "/tUGSLoMcxNWZ0OIRSqDaB2jNbdE.jpg", + "id": 503, + "original_title": "Poseidon", + "release_date": "2006-05-12", + "poster_path": "/kHrdehzlhyyb190D3RvH8mdX1y2.jpg", + "rating": 6.0, + "title": "Poseidon", + "vote_average": 6.2000000000000002, + "vote_count": 9 + }, + { + "backdrop_path": "/tBCOpjphzSLzC6oOjqzTEg6bJ7q.jpg", + "id": 534, + "original_title": "Terminator Salvation", + "release_date": "2009-05-21", + "poster_path": "/hxDfhavtxA2Ayx7O9BsQMcZRdG0.jpg", + "rating": 6.0, + "title": "Terminator Salvation", + "vote_average": 7.0, + "vote_count": 57 + }, + { + "backdrop_path": "/6TlMTnjtBcXFq7rSCcdQoBjTNPd.jpg", + "id": 571, + "original_title": "The Birds", + "release_date": "1963-03-28", + "poster_path": "/8tGRhGAbIZE97bnUAWrYSdqq71t.jpg", + "rating": 6.0, + "title": "The Birds", + "vote_average": 8.0999999999999996, + "vote_count": 6 + }, + { + "backdrop_path": "/7u3pxc0K1wx32IleAkLv78MKgrw.jpg", + "id": 603, + "original_title": "The Matrix", + "release_date": "1999-03-31", + "poster_path": "/gynBNzwyaHKtXqlEKKLioNkjKgN.jpg", + "rating": 9.0, + "title": "The Matrix", + "vote_average": 9.0999999999999996, + "vote_count": 249 + }, + { + "backdrop_path": "/jB9nQa6zJIZQ0htH5827Og7Mfsw.jpg", + "id": 615, + "original_title": "The Passion of the Christ", + "release_date": "2004-02-25", + "poster_path": "/6KyvP5bDmwTYdLLnhEn10NFPDIZ.jpg", + "rating": 6.0, + "title": "The Passion of the Christ", + "vote_average": 7.5, + "vote_count": 15 + }, + { + "backdrop_path": "/nO0GtGFQmEuuOyAQVpHjJlWBU8O.jpg", + "id": 616, + "original_title": "The Last Samurai", + "release_date": "2003-12-05", + "poster_path": "/cRz4FRx731ulws6zHuQVaDXpx73.jpg", + "rating": 8.0, + "title": "The Last Samurai", + "vote_average": 8.0999999999999996, + "vote_count": 26 + } + ], + "total_pages": 12, + "total_results": 239 +} \ No newline at end of file diff --git a/test/Tmdb/Tests/Resources/account/watchlist.json b/test/Tmdb/Tests/Resources/account/watchlist.json new file mode 100644 index 00000000..e36811f6 --- /dev/null +++ b/test/Tmdb/Tests/Resources/account/watchlist.json @@ -0,0 +1,4 @@ +{ + "status_code": 1, + "status_message": "Success" +} \ No newline at end of file diff --git a/test/Tmdb/Tests/Resources/authentication/guest_session_token.json b/test/Tmdb/Tests/Resources/authentication/guest_session_token.json new file mode 100644 index 00000000..9e0e7eaf --- /dev/null +++ b/test/Tmdb/Tests/Resources/authentication/guest_session_token.json @@ -0,0 +1,5 @@ +{ + "success": true, + "guest_session_id": "0c550fd5da2fc3f321ab3bs9b60ca108", + "expires_at": "2012-12-04 22:51:19 UTC" +} \ No newline at end of file diff --git a/test/Tmdb/Tests/Resources/authentication/request_token.json b/test/Tmdb/Tests/Resources/authentication/request_token.json new file mode 100644 index 00000000..9b57d6d4 --- /dev/null +++ b/test/Tmdb/Tests/Resources/authentication/request_token.json @@ -0,0 +1,5 @@ +{ + "expires_at": "2012-02-09 19:50:25 UTC", + "request_token": "641bf16c663db167c6cffcdff41126039d4445bf", + "success": true +} \ No newline at end of file diff --git a/test/Tmdb/Tests/Resources/authentication/session_token.json b/test/Tmdb/Tests/Resources/authentication/session_token.json new file mode 100644 index 00000000..cf074a32 --- /dev/null +++ b/test/Tmdb/Tests/Resources/authentication/session_token.json @@ -0,0 +1,4 @@ +{ + "session_id": "80b2bf99520cd795ff54e31af97917bc9e3a7c8c", + "success": true +} \ No newline at end of file