PaulWalker
Paul Walker slows your application down before it crashes.
The main use case is consuming an API that has rate limiting enforced. This gem will help you keep a global limit so you can be 100% sure your request limit pool won't dry up..
Installation
Add this line to your application's Gemfile:
gem 'paul_walker'
And then execute:
$ bundle
Or install it yourself as:
$ gem install paul_walker
Usage
To add a new limit to the store:
PaulWalker::RateLimit.add(namespace, key, remaining, maximum)
OR
limit = PaulWalker::RateLimit.add('someapi', '1234', 40, 300)
limit.remaining
key in this case would most likely identify the API key associated with the call you make which is why a namespace is required in the case of key collision.
To pull the current limit from the store
PaulWalker::RateLimit.get(namespace, key)
The rate limiting store uses a timestamp internally that will increment the current limit when you retrieve it, up to the maximum provided when you added it.
Development
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/paul_walker.
License
The gem is available as open source under the terms of the MIT License.