Ruby client for the Bucketeer rate limiting service
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
spec
.gitignore
.travis.yml
Gemfile
Guardfile
LICENSE
README.md
Rakefile
bucketeer-client.gemspec

README.md

bucketeer-client

Build Status

bucketeer-client is a Ruby client for the HTTP rate limiting service, Bucketeer.

Status

Not yet on rubygems.

Usage

require 'bucketeer/client'

client = Bucketeer::Client.new("http://localhost:3000")

client.buckets
#=> [#<Bucketeer::Bucket: @consumer="michael", @feature="fun_stuff", @restore_rate=10000, @capacity=10>]

client.remaining('michael', 'fun_stuff')
#=> 1

client.tick('michael', 'fun_stuff')
#=> 0

client.tick('michael', 'fun_stuff')
# nil means user has exceeded capacity. Kick 'em to the curb
#=> nil

client.tick('bogus', 'whatever')
# raises Bucketeer::Client::BucketNotFound

consumer = 'another_guy'
feature = 'do_things'
restore_rate = 2000 # 2 seconds, 2000 milliseconds
capacity = 10

new_bucket = Bucketeer::Bucket(consumer, feature, restore_rate, capacity)
client.write_bucket(new_bucket)

client.delete_bucket(consumer, feature)
client.delete_feature(consumer)

client.remaining('michael', 'fun_stuff')
#=> 0

client.refill('michael', 'fun_stuff')
# capacity
#=> 10

client.drain('michael', 'fun_stuff')
# reduce remaining to zero

Configuration

The second argument to the initializer is mostly a pass through to Faraday's options. Additionally, you can specify an :adapter option if you want to use something other than the default backend for Faraday:

client = Bucketeer::Client.new("http://localhost:3000",
                               :adapter      => SomeAdapter,
                               :timeout      => 20,
                               :open_timeout => 20)