diff --git a/README.md b/README.md index 45ac0234..875de4b2 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 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) diff --git a/src/Picqer/Financials/Exact/Connection.php b/src/Picqer/Financials/Exact/Connection.php index 46924cc1..e72267dc 100644 --- a/src/Picqer/Financials/Exact/Connection.php +++ b/src/Picqer/Financials/Exact/Connection.php @@ -130,6 +130,11 @@ class Connection */ protected $minutelyLimitRemaining; + /** + * @var int|null + */ + protected $minutelyLimitReset; + /** * @return Client */ @@ -408,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)) { @@ -701,6 +706,14 @@ 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 +781,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'); } }