From b1e1b801fc7895c233ccc97f4a39216e3c205957 Mon Sep 17 00:00:00 2001 From: Hans Ott Date: Sun, 13 Mar 2016 19:10:58 +0100 Subject: [PATCH] Introduce api version constant --- src/Pinterest/Api.php | 2 +- src/Pinterest/Authentication.php | 24 ++++++++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/Pinterest/Api.php b/src/Pinterest/Api.php index d313edf..550109f 100644 --- a/src/Pinterest/Api.php +++ b/src/Pinterest/Api.php @@ -559,7 +559,7 @@ private function buildRequestForPagedList(PagedList $pagedList) parse_str($components['query'], $params); $path = $components['path']; - $versionPath = '/v1/'; + $versionPath = sprintf('/%s/', Authentication::API_VERSION); $versionPathLength = strlen($versionPath); $path = substr($path, $versionPathLength); diff --git a/src/Pinterest/Authentication.php b/src/Pinterest/Authentication.php index 4b6f488..f0bcbf0 100644 --- a/src/Pinterest/Authentication.php +++ b/src/Pinterest/Authentication.php @@ -33,10 +33,17 @@ final class Authentication implements ClientInterface * * @var string */ - const BASE_URI = 'https://api.pinterest.com/v1/'; + const BASE_URI = 'https://api.pinterest.com'; /** - * The http client. + * The API version. + * + * @var string + */ + const API_VERSION = 'v1'; + + /** + * The HTTP client. * * @var ClientInterface */ @@ -80,7 +87,7 @@ public function __construct(ClientInterface $client, $clientId, $clientSecret) /** * Alternative constructor for when we already have an accessToken. * - * @param ClientInterface $client The (un-authenticated) Http client. + * @param ClientInterface $client The (un-authenticated) HTTP client. * @param string $clientId The client id. * @param string $clientSecret The client secret. * @param string $accessToken The OAuth access token. @@ -104,7 +111,7 @@ public static function withAccessToken( * * ATTENTION: only the execute method will work, as the others need client id and secret. * - * @param ClientInterface $client The http client. + * @param ClientInterface $client The HTTP client. * @param string $accessToken The OAuth access token. * * @return static @@ -119,6 +126,11 @@ public static function onlyAccessToken( return $authentication; } + private function getBaseUriWithVersion() + { + return sprintf('%s/%s/', static::BASE_URI, static::API_VERSION); + } + /** * First step of the OAuth process. * @@ -192,7 +204,7 @@ public function requestAccessToken($code) { $request = new Request( 'POST', - static::BASE_URI.'oauth/token', + $this->getBaseUriWithVersion().'oauth/token', array( 'grant_type' => 'authorization_code', 'client_id' => $this->clientId, @@ -229,7 +241,7 @@ public function execute(Request $request) $authenticatedRequest = new Request( $request->getMethod(), - static::BASE_URI.$request->getEndpoint(), + $this->getBaseUriWithVersion().$request->getEndpoint(), $request->getParams(), $headers );