Skip to content
This repository has been archived by the owner on Nov 7, 2020. It is now read-only.

Commit

Permalink
Introduce api version constant
Browse files Browse the repository at this point in the history
  • Loading branch information
hansott committed Mar 13, 2016
1 parent 59fab42 commit b1e1b80
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Pinterest/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
24 changes: 18 additions & 6 deletions src/Pinterest/Authentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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.
*
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
);
Expand Down

0 comments on commit b1e1b80

Please sign in to comment.