Skip to content

Commit

Permalink
Add rate limiting examples [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Dec 1, 2013
1 parent 74c0d81 commit b082ed0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions .yardopts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ CONTRIBUTING.md
LICENSE.md
README.md
examples/Configuration.md
examples/RateLimiting.md
examples/Update.md
23 changes: 23 additions & 0 deletions examples/RateLimiting.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Rate Limits

Here's an example of how to handle rate limits:

```ruby
require 'twitter'

MAX_ATTEMPTS = 3
num_attempts = 0
begin
num_attempts += 1
retweets = client.retweeted_by_user("sferik")
rescue Twitter::Error::TooManyRequests => error
if num_attempts <= MAX_ATTEMPTS
# NOTE: Your process could go to sleep for up to 15 minutes but if you
# retry any sooner, it will almost certainly fail with the same exception.
sleep error.rate_limit.reset_in
retry
else
raise
end
end
```

0 comments on commit b082ed0

Please sign in to comment.