sferik/twitter

View on GitHub
examples/RateLimiting.md

Summary

Maintainability
Test Coverage
# Rate Limits

This example assumes you have a configured Twitter REST `client`. Instructions
on how to configure a client can be found in [examples/Configuration.md][cfg].

[cfg]: https://github.com/sferik/twitter/blob/master/examples/Configuration.md

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

```ruby
follower_ids = client.follower_ids('justinbieber')
begin
  follower_ids.to_a
rescue Twitter::Error::TooManyRequests => error
  # 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 + 1
  retry
end
```