From 5a48d4ad853d7155218fed3c322e8b8f114362ca Mon Sep 17 00:00:00 2001 From: = Date: Fri, 9 Oct 2020 17:45:51 +0100 Subject: [PATCH 1/5] Add exception to docblock --- src/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Builder.php b/src/Builder.php index 9abe1fc..98db5d2 100644 --- a/src/Builder.php +++ b/src/Builder.php @@ -1555,7 +1555,7 @@ public function first() /** * @return mixed - * @throws \MarcReichel\IGDBLaravel\Exceptions\MissingEndpointException + * @throws \MarcReichel\IGDBLaravel\Exceptions\MissingEndpointException|AuthenticationException */ public function count() { From 88cd8c998606f2cd0f4d70e45128bdbdbd2cc964 Mon Sep 17 00:00:00 2001 From: = Date: Fri, 9 Oct 2020 17:46:39 +0100 Subject: [PATCH 2/5] Retrieve and use access token --- src/Builder.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Builder.php b/src/Builder.php index 98db5d2..6bacc63 100644 --- a/src/Builder.php +++ b/src/Builder.php @@ -1559,6 +1559,8 @@ public function first() */ public function count() { + $accessToken = $this->retrieveAccessToken(); + if ($this->endpoint) { $this->endpoint = Str::finish($this->endpoint, '/') . 'count'; @@ -1570,10 +1572,13 @@ public function count() } $data = Cache::remember($cacheKey, $this->cacheLifetime, - function () { + function () use ($accessToken) { try { return (int)json_decode($this->client->get($this->endpoint, [ + 'headers' => [ + 'Authorization' => 'Bearer '.$accessToken, + ], 'body' => $this->getQuery(), ])->getBody())['count']; } catch (\Exception $exception) { From 7d81e7c497bc0ce209d13aa80d29eb57bae70d05 Mon Sep 17 00:00:00 2001 From: = Date: Fri, 9 Oct 2020 17:47:11 +0100 Subject: [PATCH 3/5] Change method to post --- src/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Builder.php b/src/Builder.php index 6bacc63..776aee1 100644 --- a/src/Builder.php +++ b/src/Builder.php @@ -1574,7 +1574,7 @@ public function count() $data = Cache::remember($cacheKey, $this->cacheLifetime, function () use ($accessToken) { try { - return (int)json_decode($this->client->get($this->endpoint, + return (int)json_decode($this->client->post($this->endpoint, [ 'headers' => [ 'Authorization' => 'Bearer '.$accessToken, From 64a06a7e73f67d7ead3f2114bbadc90760a6cf9e Mon Sep 17 00:00:00 2001 From: = Date: Fri, 9 Oct 2020 17:48:10 +0100 Subject: [PATCH 4/5] Decode to associative array (rather than object) --- src/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Builder.php b/src/Builder.php index 776aee1..c7263fb 100644 --- a/src/Builder.php +++ b/src/Builder.php @@ -1580,7 +1580,7 @@ function () use ($accessToken) { 'Authorization' => 'Bearer '.$accessToken, ], 'body' => $this->getQuery(), - ])->getBody())['count']; + ])->getBody(), true)['count']; } catch (\Exception $exception) { $this->handleRequestException($exception); } From 0978798f9e5a6f50eaa51b66f9908c05f9d9c404 Mon Sep 17 00:00:00 2001 From: = Date: Fri, 9 Oct 2020 17:50:22 +0100 Subject: [PATCH 5/5] Add description to docblock --- src/Builder.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Builder.php b/src/Builder.php index c7263fb..94c9516 100644 --- a/src/Builder.php +++ b/src/Builder.php @@ -1554,6 +1554,8 @@ public function first() } /** + * Return the total "count" result of the query. + * * @return mixed * @throws \MarcReichel\IGDBLaravel\Exceptions\MissingEndpointException|AuthenticationException */