Skip to content

Commit

Permalink
readme update
Browse files Browse the repository at this point in the history
  • Loading branch information
justijndepover committed Sep 16, 2021
1 parent 688910d commit 075af45
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ $teamleader->post('contacts.add', [

## Rate limiting

After each request, the package stores the rate limit headers. How you handle rate limiting is up to you, but the package does give you some handy functions to manage this:
After each request, the rate limiting headers are available.
```php
// returns the maximum rate limit your application can hit in 1 minute
$teamleader->getRateLimitLimit();
Expand All @@ -97,8 +97,12 @@ $teamleader->getRateLimitRemaining();

// returns the datetime (UTC) when your application can make calls again, after hitting the rate limit.
$teamleader->getRateLimitReset();
```

// if the current rate limit is equal to 1, sleep until the reset datetime has passed
How you handle rate limiting is up to you. But the application provides a helper method to ensure you never hit the limit:
```php
$teamleader->get('contacts.info', ['id' => $id]);
// executing this function will sleep until the X-RateLimitReset header has passed, but only if the rate limit is hit.
$teamleader->ensureRateLimitingIsNotExceeded();
```

Expand Down
2 changes: 1 addition & 1 deletion src/Teamleader.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public function post(string $endpoint, array $body, array $parameters = [])

public function ensureRateLimitingIsNotExceeded() : void
{
if ($this->rateLimitRemaining <= 2) {
if ($this->rateLimitRemaining <= 1) {
$seconds = Carbon::createFromFormat('Y-m-d\TH:i:sT', $this->rateLimitReset, 'UTC')->diffInSeconds();
$seconds++;

Expand Down

0 comments on commit 075af45

Please sign in to comment.