From c563f43b1126f87b29f56063c7b6150dcb0acada Mon Sep 17 00:00:00 2001 From: robvandelisdonk Date: Fri, 6 Dec 2019 12:35:25 +0100 Subject: [PATCH 1/2] add check to ratelimit on request access token call. --- src/Pinterest/Authentication.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Pinterest/Authentication.php b/src/Pinterest/Authentication.php index bdbc45e..a4fc012 100644 --- a/src/Pinterest/Authentication.php +++ b/src/Pinterest/Authentication.php @@ -20,6 +20,7 @@ use Pinterest\Api\Exceptions\TooManyScopesGiven; use Pinterest\Api\Exceptions\AtLeastOneScopeNeeded; use Pinterest\Api\Exceptions\InvalidScopeException; +use Pinterest\Http\Exceptions\RateLimitedReached; /** * This class is responsible for authenticating requests. @@ -199,6 +200,7 @@ private function assertValidScopes(array $scopes) * @return string The OAuth access token. * * @throws TokenMissing + * @throws RateLimitedReached */ public function requestAccessToken($code) { @@ -215,6 +217,10 @@ public function requestAccessToken($code) $response = $this->http->execute($request); + if($response->rateLimited()) { + throw new RateLimitedReached($response); + } + if ( !isset($response->body) || !isset($response->body->access_token) From 42e49f1a67727bab31730942b4b32fae42171a8c Mon Sep 17 00:00:00 2001 From: robvandelisdonk Date: Fri, 6 Dec 2019 14:03:54 +0100 Subject: [PATCH 2/2] adding extra space to comply with formatting --- src/Pinterest/Authentication.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Pinterest/Authentication.php b/src/Pinterest/Authentication.php index a4fc012..9ffa9a0 100644 --- a/src/Pinterest/Authentication.php +++ b/src/Pinterest/Authentication.php @@ -217,7 +217,7 @@ public function requestAccessToken($code) $response = $this->http->execute($request); - if($response->rateLimited()) { + if ($response->rateLimited()) { throw new RateLimitedReached($response); }