leaky_bucket 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cce4c867009f5db057f5eb30bc085588db30a7a0
4
- data.tar.gz: 328d84bdcd51b3818be1345b00f3166e74f0f689
3
+ metadata.gz: 5cca7ae9bd77604a22863e2c3ee3dab9a7c35320
4
+ data.tar.gz: 69563a92883c7275ab6e5b6a949c37d534e50046
5
5
  SHA512:
6
- metadata.gz: 05de9853313aecfe3b161054f8915951ec104b50c7fad5b98193a5ef4979746b02f2609d50a1a3e1b0f6f3be770d03dee112cc15473a71db5022d703134566fd
7
- data.tar.gz: 58523337eabe48dc23f78016ce50bab05a90a28cbcef08b9036f248bd04c64623cded6d71bcbf0ce59bd7e8d1a0bcd7415a9168fc6442676c208664e53085cae
6
+ metadata.gz: bc97b9bebf560779a0827c0d952261c0586d9c00baa7e984bc991659f18495c614e0a454cfddbca58a649963d11e27c3d6047c89516a195f97349b1f4a6e4f76
7
+ data.tar.gz: d4849fa6fccfce9fd889b04f4d73a13b454ea08a74f121737380a45b9c1370fb23b9fc933231bf018831bc00fb8bd443574f22fb92dd8017a2f00e066d1134ef
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # LeakyBucket
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/leaky_bucket`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ If you are running a busy application in production, you should limit the number of requests a user can make per time unit. LeakyBucket helps you do just that, easily.
6
4
 
7
5
  ## Installation
8
6
 
@@ -20,13 +18,41 @@ Or install it yourself as:
20
18
 
21
19
  $ gem install leaky_bucket
22
20
 
21
+ Then create a `leaky_bucket.rb` initializer file in `config/initializers` with :
22
+
23
+ ```ruby
24
+ LeakyBucket.cache = Rails.cache # or memcached
25
+ ```
26
+
27
+
23
28
  ## Usage
24
29
 
25
- TODO: Write usage instructions here
30
+ to limit the requests to an action, use the `throttle` method:
31
+
32
+ ```ruby
33
+ def create
34
+ LeakyBucket::Throttler.throttle(request.ip)
35
+ #other code that will run if the user has not reached the maximum threshold.
36
+ end
37
+ ```
38
+
39
+ the `throttle` method will raise an exception and return and 429 response code if the user has made too many requests.
40
+
41
+ By default, the threshold is 100 requests/hour, to override it, just provide the params:
42
+
43
+ ```ruby
44
+ # allow maximum 50 requests per minute.
45
+ LeakyBucket::Throttler.throttle(ip, threshold: 50, interval: 60, burst: 10)
46
+ ```
47
+
48
+ `threhold` is the number of requests.
49
+
50
+ `interval` is in seconds.
51
+
52
+ `burst` is the number of requests the user is allowed to make at once, when the burst is exhausted, the user will have to wait until the sometime has passed to make another request.
26
53
 
27
54
  ## Development
28
55
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
56
 
31
57
  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](https://rubygems.org).
32
58
 
@@ -1,3 +1,3 @@
1
1
  module LeakyBucket
2
- VERSION = "0.2.4"
2
+ VERSION = "0.2.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: leaky_bucket
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ahmad