From 99873235f63e74e624162a597991021a72d8f25a Mon Sep 17 00:00:00 2001 From: Maarten Waegeman Date: Mon, 21 Dec 2020 13:23:06 +0100 Subject: [PATCH 1/5] Read minutely-reset header in Connection.php Added an extra getter for the minutely reset header. --- src/Picqer/Financials/Exact/Connection.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Picqer/Financials/Exact/Connection.php b/src/Picqer/Financials/Exact/Connection.php index 46924cc1..74f6919e 100644 --- a/src/Picqer/Financials/Exact/Connection.php +++ b/src/Picqer/Financials/Exact/Connection.php @@ -129,6 +129,11 @@ class Connection * @var int|null */ protected $minutelyLimitRemaining; + + /** + * @var int|null + */ + protected $minutelyLimitReset; /** * @return Client @@ -700,6 +705,13 @@ public function getMinutelyLimitRemaining() { return $this->minutelyLimitRemaining; } + /** + * @return int|null The time at which the minutely rate limit window resets in UTC epoch milliseconds + */ + public function getMinutelyLimitReset() + { + return $this->minutelyLimitReset; + } /** * @return string @@ -768,5 +780,6 @@ private function extractRateLimits(Response $response) $this->minutelyLimit = (int) $response->getHeaderLine('X-RateLimit-Minutely-Limit'); $this->minutelyLimitRemaining = (int) $response->getHeaderLine('X-RateLimit-Minutely-Remaining'); + $this->minutelyLimitReset = (int) $response->getHeaderLine('X-RateLimit-Minutely-Reset'); } } From 1fceed6c9bd7155cff57365516c462f2b6146a11 Mon Sep 17 00:00:00 2001 From: Maarten Waegeman Date: Mon, 21 Dec 2020 13:25:59 +0100 Subject: [PATCH 2/5] Also extractRateLimits on put requests --- src/Picqer/Financials/Exact/Connection.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Picqer/Financials/Exact/Connection.php b/src/Picqer/Financials/Exact/Connection.php index 74f6919e..a0efa372 100644 --- a/src/Picqer/Financials/Exact/Connection.php +++ b/src/Picqer/Financials/Exact/Connection.php @@ -413,12 +413,12 @@ public function needsAuthentication() private function parseResponse(Response $response, $returnSingleIfPossible = true) { try { + $this->extractRateLimits($response); + if ($response->getStatusCode() === 204) { return []; } - $this->extractRateLimits($response); - Psr7\rewind_body($response); $json = json_decode($response->getBody()->getContents(), true); if (false === is_array($json)) { From acac9083a1abebcbe01d155cda55f86f1e120177 Mon Sep 17 00:00:00 2001 From: Maarten Waegeman Date: Mon, 21 Dec 2020 13:36:42 +0100 Subject: [PATCH 3/5] Update Readme to add the new getMinutelyLimitReset --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 45ac0234..352e96c5 100644 --- a/README.md +++ b/README.md @@ -111,7 +111,10 @@ $connection->getDailyLimitRemaining(); // Retrieve the remaining amount of API c $connection->getDailyLimitReset(); // Retrieve the timestamp for when the limit will reset $connection->getMinutelyLimit(); // Retrieve your limit per minute $connection->getMinutelyLimitRemaining(); // Retrieve the amount of API calls remaining for this minute +$connection->getMinutelyLimitReset(); // Retrieve the timestamp for when the minutely limit will reset ``` +_Do note that when you have no more minutely calls available, Exact only sends the Minutely Limit headers. So in that case, the Daily Limit headers will remain 0 untill the minutely reset rolls over._ + ### Use the library to do stuff (examples) From 1c147ca4cdfc35c3cf960171a4eee688a0ad36da Mon Sep 17 00:00:00 2001 From: Maarten Waegeman Date: Mon, 21 Dec 2020 13:46:25 +0100 Subject: [PATCH 4/5] Fix style issues --- src/Picqer/Financials/Exact/Connection.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Picqer/Financials/Exact/Connection.php b/src/Picqer/Financials/Exact/Connection.php index a0efa372..e72267dc 100644 --- a/src/Picqer/Financials/Exact/Connection.php +++ b/src/Picqer/Financials/Exact/Connection.php @@ -129,7 +129,7 @@ class Connection * @var int|null */ protected $minutelyLimitRemaining; - + /** * @var int|null */ @@ -414,7 +414,7 @@ private function parseResponse(Response $response, $returnSingleIfPossible = tru { try { $this->extractRateLimits($response); - + if ($response->getStatusCode() === 204) { return []; } @@ -705,6 +705,7 @@ public function getMinutelyLimitRemaining() { return $this->minutelyLimitRemaining; } + /** * @return int|null The time at which the minutely rate limit window resets in UTC epoch milliseconds */ From 3db453b6833f03d3588c1e2818990d3b46fc7bc6 Mon Sep 17 00:00:00 2001 From: Maarten Waegeman Date: Mon, 21 Dec 2020 13:48:48 +0100 Subject: [PATCH 5/5] Fix typo in description --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 352e96c5..875de4b2 100644 --- a/README.md +++ b/README.md @@ -113,7 +113,7 @@ $connection->getMinutelyLimit(); // Retrieve your limit per minute $connection->getMinutelyLimitRemaining(); // Retrieve the amount of API calls remaining for this minute $connection->getMinutelyLimitReset(); // Retrieve the timestamp for when the minutely limit will reset ``` -_Do note that when you have no more minutely calls available, Exact only sends the Minutely Limit headers. So in that case, the Daily Limit headers will remain 0 untill the minutely reset rolls over._ +_Do note when you have no more minutely calls available, Exact only sends the Minutely Limit headers. So in that case, the Daily Limit headers will remain 0 until the minutely reset rolls over._ ### Use the library to do stuff (examples)