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()); + } +}