forked from php-tmdb/api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding the rest of Account related methods
- Loading branch information
1 parent
53f109c
commit e62f084
Showing
12 changed files
with
578 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
examples/authentication/model/authenticate_request_token.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
/** | ||
* This file is part of the Tmdb PHP API created by Michael Roterman. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @package Tmdb | ||
* @author Michael Roterman <[email protected]> | ||
* @copyright (c) 2013, Michael Roterman | ||
* @version 0.0.1 | ||
*/ | ||
require_once('../../../vendor/autoload.php'); | ||
require_once('../../../apikey.php'); | ||
|
||
$token = new \Tmdb\ApiToken(TMDB_API_KEY); | ||
$client = new \Tmdb\Client($token); | ||
|
||
$authenticationRepository = new \Tmdb\Repository\AuthenticationRepository($client); | ||
$requestToken = $authenticationRepository->getRequestToken(); | ||
|
||
// Will force a redirect | ||
$authenticationRepository->authenticateRequestToken($requestToken); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
/** | ||
* This file is part of the Tmdb PHP API created by Michael Roterman. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @package Tmdb | ||
* @author Michael Roterman <[email protected]> | ||
* @copyright (c) 2013, Michael Roterman | ||
* @version 0.0.1 | ||
*/ | ||
require_once('../../../vendor/autoload.php'); | ||
require_once('../../../apikey.php'); | ||
|
||
$token = new \Tmdb\ApiToken(TMDB_API_KEY); | ||
$client = new \Tmdb\Client($token); | ||
|
||
$authenticationRepository = new \Tmdb\Repository\AuthenticationRepository($client); | ||
$sessionToken = $authenticationRepository->getGuestSessionToken($requestToken); | ||
|
||
var_dump($sessionToken); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
/** | ||
* This file is part of the Tmdb PHP API created by Michael Roterman. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @package Tmdb | ||
* @author Michael Roterman <[email protected]> | ||
* @copyright (c) 2013, Michael Roterman | ||
* @version 0.0.1 | ||
*/ | ||
require_once('../../../vendor/autoload.php'); | ||
require_once('../../../apikey.php'); | ||
|
||
$token = new \Tmdb\ApiToken(TMDB_API_KEY); | ||
$client = new \Tmdb\Client($token); | ||
|
||
$authenticationRepository = new \Tmdb\Repository\AuthenticationRepository($client); | ||
$requestToken = $authenticationRepository->getRequestToken(); | ||
|
||
var_dump($requestToken); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
/** | ||
* This file is part of the Tmdb PHP API created by Michael Roterman. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @package Tmdb | ||
* @author Michael Roterman <[email protected]> | ||
* @copyright (c) 2013, Michael Roterman | ||
* @version 0.0.1 | ||
*/ | ||
require_once('../../../vendor/autoload.php'); | ||
require_once('../../../apikey.php'); | ||
|
||
$token = new \Tmdb\ApiToken(TMDB_API_KEY); | ||
$client = new \Tmdb\Client($token); | ||
|
||
$requestToken = new \Tmdb\RequestToken('2e57316025d7e4df5cfff81f0596209c2465a8bd'); | ||
|
||
$authenticationRepository = new \Tmdb\Repository\AuthenticationRepository($client); | ||
$sessionToken = $authenticationRepository->getSessionToken($requestToken); | ||
|
||
var_dump($sessionToken); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
<?php | ||
/** | ||
* This file is part of the Tmdb PHP API created by Michael Roterman. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @package Tmdb | ||
* @author Michael Roterman <[email protected]> | ||
* @copyright (c) 2013, Michael Roterman | ||
* @version 0.0.1 | ||
*/ | ||
namespace Tmdb\Factory; | ||
|
||
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
/** | ||
* This file is part of the Tmdb PHP API created by Michael Roterman. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @package Tmdb | ||
* @author Michael Roterman <[email protected]> | ||
* @copyright (c) 2013, Michael Roterman | ||
* @version 0.0.1 | ||
*/ | ||
namespace Tmdb\Repository; | ||
|
||
use Tmdb\Factory\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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.