rlimiter 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +38 -0
- data/LICENSE.txt +21 -0
- data/README.md +124 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/rlimiter/client.rb +18 -0
- data/lib/rlimiter/invalid_client_error.rb +4 -0
- data/lib/rlimiter/redis_client.rb +101 -0
- data/lib/rlimiter/version.rb +3 -0
- data/lib/rlimiter.rb +49 -0
- data/rlimiter.gemspec +37 -0
- metadata +118 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9302bec359d72e7e409dadb2f2c90ddf1eeb67dfc89010b8eccd49ee6fac00e0
|
4
|
+
data.tar.gz: ddbb3f185d724c7c2c3de52da79e867795ea3d52240a05439837ffab30cb43ac
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 32fcab4227ff1437bf11e6b3d3ed421c6ac53aa86d6bbfef2ab562935575d78fda25f5b21f22e8b5a2ae231345fcb868bb2993d54c37ef6ff246b16805ed7348
|
7
|
+
data.tar.gz: 5c32ce88d853cbf5fad618ba872b3904de1423afb2418e27d722159238ab9e986f4a391df49cbf0558de4c670a17694baa853c4d7bbcf4bcc2dd401e9b993a6e
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at TODO: Write your email address. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rlimiter (0.1.8)
|
5
|
+
redis (~> 4.0.2)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
diff-lcs (1.3)
|
11
|
+
rake (10.5.0)
|
12
|
+
redis (4.0.2)
|
13
|
+
rspec (3.8.0)
|
14
|
+
rspec-core (~> 3.8.0)
|
15
|
+
rspec-expectations (~> 3.8.0)
|
16
|
+
rspec-mocks (~> 3.8.0)
|
17
|
+
rspec-core (3.8.0)
|
18
|
+
rspec-support (~> 3.8.0)
|
19
|
+
rspec-expectations (3.8.1)
|
20
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
21
|
+
rspec-support (~> 3.8.0)
|
22
|
+
rspec-mocks (3.8.0)
|
23
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
24
|
+
rspec-support (~> 3.8.0)
|
25
|
+
rspec-support (3.8.0)
|
26
|
+
|
27
|
+
PLATFORMS
|
28
|
+
ruby
|
29
|
+
|
30
|
+
DEPENDENCIES
|
31
|
+
bundler (~> 1.16)
|
32
|
+
rake (~> 10.0)
|
33
|
+
redis
|
34
|
+
rlimiter!
|
35
|
+
rspec (~> 3.0)
|
36
|
+
|
37
|
+
BUNDLED WITH
|
38
|
+
1.16.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 TODO: Write your name
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
# Rlimiter
|
2
|
+
|
3
|
+
Rlimiter is a simple rate limiting client for Ruby (not limited to RoR!).
|
4
|
+
|
5
|
+
The fundamental idea behind this client is to limit the number of hits of any code within the application. Hence it is not
|
6
|
+
only limited to API rate limiting, instead can be used in all sorts of scenarios that require circumstantial throttling of throughput.
|
7
|
+
|
8
|
+
It currently uses Redis as the main storage client for storing the necessary keys, provided it's fast IO operations and ubiquity in web applications. It is written
|
9
|
+
in a manner to effortlessly extend and implement custom storage clients as required.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'rlimiter'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
$ gem install rlimiter
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
Rlimiter has to be initialized in application.rb if you are using Rails, or any other bootstrap/initialization file in your application by doing the following:
|
30
|
+
```ruby
|
31
|
+
|
32
|
+
CLIENT = 'redis' # Recommended and the only client for now
|
33
|
+
HOST = 'rds.host.foobaz' # Redis server hostname, enter 'localhost' if the redis server is on the same machine
|
34
|
+
PORT = 6379 # Default port, could be left empty
|
35
|
+
|
36
|
+
# Initializes the Rlimiter static class for usage
|
37
|
+
Rlimiter.init(client: CLIENT, host: HOST, port: PORT)
|
38
|
+
```
|
39
|
+
|
40
|
+
There is one common way to use Rlimiter (which suffices most of the use cases)
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
|
44
|
+
LIMIT_COUNT = 100 # Max number of hits allowed
|
45
|
+
|
46
|
+
LIMIT_DURATION = 60 # Duration in which the max hits are applicable (in seconds)
|
47
|
+
# After the aforementioned duration has elapsed, hit counter is reset to 0.
|
48
|
+
|
49
|
+
LIMIT_KEY = 'send_mobile_otp_limit' # Unique key for each operation that has to be rate limited
|
50
|
+
|
51
|
+
|
52
|
+
# Implementation
|
53
|
+
|
54
|
+
return send_mobile_otp if Rlimiter.limit(LIMIT_KEY, LIMIT_COUNT, LIMIT_DURATION)
|
55
|
+
return limit_exceeded_message
|
56
|
+
|
57
|
+
# :send_mobile_otp is the function that has to be rate limited, Rlimiter.limit call increments the hit count and
|
58
|
+
# returns true if the operation's limit has not been exceeded, otherwise returns false.
|
59
|
+
```
|
60
|
+
|
61
|
+
A more complicated approach could also be implemented :
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
|
65
|
+
@phone_number = '2947126943'
|
66
|
+
@limit_key = generate_limit_key
|
67
|
+
@limit_count = fetch_limit_count
|
68
|
+
limit_breached = Rlimiter.limit(@limit_key, @limit_count, DEFAULT_LIMIT_DURATION)
|
69
|
+
unless limit_breached
|
70
|
+
{
|
71
|
+
:status_code => 200,
|
72
|
+
:otp_dispatch_status => send_mobile_otp,
|
73
|
+
:requests_left => @limit_count - Rlimiter.current_count(@limit_key)
|
74
|
+
}
|
75
|
+
else
|
76
|
+
{
|
77
|
+
:status_code => 429,
|
78
|
+
:otp_dispatch_status => nil,
|
79
|
+
:requests_left => 0,
|
80
|
+
:next_request_in => Rlimiter.next_in(@limit_key, DEFAULT_LIMIT_DURATION)
|
81
|
+
}
|
82
|
+
end
|
83
|
+
|
84
|
+
# ..........
|
85
|
+
|
86
|
+
def generate_limit_key
|
87
|
+
"#{LIMIT_KEY_PREFIX}.#{@phone_number}"
|
88
|
+
end
|
89
|
+
|
90
|
+
def fetch_limit_count
|
91
|
+
return USA_LIMIT_COUNT if number_from_usa?(@phone_number)
|
92
|
+
return INDIA_LIMIT_COUNT if number_from_india?(@phone_number)
|
93
|
+
DEFAULT_LIMIT_COUNT
|
94
|
+
end
|
95
|
+
|
96
|
+
# ..........
|
97
|
+
|
98
|
+
end
|
99
|
+
```
|
100
|
+
|
101
|
+
## Development
|
102
|
+
|
103
|
+
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.
|
104
|
+
|
105
|
+
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).
|
106
|
+
|
107
|
+
### TODOs:
|
108
|
+
|
109
|
+
1. Write specs for 100% code coverage.
|
110
|
+
2. Add benchmarks.
|
111
|
+
3. Integrate Travis.
|
112
|
+
4. Push to rubygems.org.
|
113
|
+
|
114
|
+
## Contributing
|
115
|
+
|
116
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/sdpatro/rlimiter. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
117
|
+
|
118
|
+
## License
|
119
|
+
|
120
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
121
|
+
|
122
|
+
## Code of Conduct
|
123
|
+
|
124
|
+
Everyone interacting in the Rlimiter project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/sdpatro/rlimiter/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rlimiter"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# Inherit the below class for custom implementations of any storage clients.
|
2
|
+
module Rlimiter
|
3
|
+
class Client
|
4
|
+
|
5
|
+
def limit(key, count, duration)
|
6
|
+
# Stub
|
7
|
+
end
|
8
|
+
|
9
|
+
def next_in(key, duration)
|
10
|
+
# Stub
|
11
|
+
end
|
12
|
+
|
13
|
+
def current_count
|
14
|
+
# Stub
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'redis'
|
2
|
+
|
3
|
+
module Rlimiter
|
4
|
+
|
5
|
+
# Redis concrete class of abstract Client
|
6
|
+
# Maintains two redis keys, one for number of hits and other for the start of the time window.
|
7
|
+
# Increases the hit count every time :limit is called, if hit count exceeds the limit count then it is checked whether
|
8
|
+
# if the previous time window is active or not, on the basis of which true/false is returned.
|
9
|
+
class RedisClient < Client
|
10
|
+
|
11
|
+
# Name of key of the hit count number, stores an integer.
|
12
|
+
RATE_COUNT = 'rate_count'.freeze
|
13
|
+
|
14
|
+
# Name of key of the start time of the time window, stores the UTC epoch time.
|
15
|
+
START_TIME = 'start_time'.freeze
|
16
|
+
|
17
|
+
# Initializes and returns a Redis object.
|
18
|
+
#
|
19
|
+
# Requires params hash i.e.
|
20
|
+
# {
|
21
|
+
# :host => [String] (The hostname of the Redis server)
|
22
|
+
# :port => [String] (Numeric port number)
|
23
|
+
# }
|
24
|
+
#
|
25
|
+
# For further documentation refer to https://github.com/redis/redis-rb
|
26
|
+
#
|
27
|
+
# Any errors thrown are generated by the redis-rb client.
|
28
|
+
#
|
29
|
+
# @param [Hash] params
|
30
|
+
# @return [Redis]
|
31
|
+
#
|
32
|
+
def initialize(params)
|
33
|
+
@redis = Redis.new(params.deep_symbolize_keys)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Registers a hit corresponding to the key specified, requires the max hit count and the duration to be passed.
|
37
|
+
#
|
38
|
+
# @param [String] key : Should be unique for one operation, can be added for multiple operations if a single rate
|
39
|
+
# limiter is to be used for those operations.
|
40
|
+
# @param [Integer] count : Max rate limit count
|
41
|
+
# @param [Integer] duration : Duration of the time window.
|
42
|
+
#
|
43
|
+
# Count and duration params could change in each call and the limit breach value is returned corresponding to that.
|
44
|
+
# Ideally this method should be called with each param a constant on the application level.
|
45
|
+
#
|
46
|
+
# Returns false if the limit has been breached.
|
47
|
+
# Returns true if limit has not been breached. (duh)
|
48
|
+
def limit(key, count, duration)
|
49
|
+
@key = key.to_s
|
50
|
+
@duration = duration.to_i
|
51
|
+
|
52
|
+
# :incr_count increases the hit count and simultaneously checks for breach
|
53
|
+
if incr_count > count
|
54
|
+
|
55
|
+
# :elapsed is the time window start Redis cache
|
56
|
+
# If the time elapsed is less than window duration, the limit has been breached for the current window (return false).
|
57
|
+
return false if @duration - elapsed > 0
|
58
|
+
|
59
|
+
# Else reset the hit count to zero and window start time.
|
60
|
+
reset
|
61
|
+
end
|
62
|
+
true
|
63
|
+
end
|
64
|
+
|
65
|
+
# Gets the hit count for the key passed.
|
66
|
+
# @param [Integer] key
|
67
|
+
def current_count(key)
|
68
|
+
@redis.hget(key, RATE_COUNT).to_i
|
69
|
+
end
|
70
|
+
|
71
|
+
# Gets the ETA for the next window start only if the limit has been breached.
|
72
|
+
# Returns 0 if the limit has not been breached.
|
73
|
+
# @param [String] key
|
74
|
+
# @param [Integer] count
|
75
|
+
# @param [Integer] duration
|
76
|
+
def next_in(key, count, duration)
|
77
|
+
@key = key
|
78
|
+
@duration = duration
|
79
|
+
return 0 if current_count(key) <= count
|
80
|
+
@duration - elapsed
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def reset
|
86
|
+
@redis.hmset(@key, RATE_COUNT, 1, START_TIME, Time.now.getutc.to_f * 1000)
|
87
|
+
end
|
88
|
+
|
89
|
+
def incr_count
|
90
|
+
@redis.hincrby(@key, RATE_COUNT, 1)
|
91
|
+
end
|
92
|
+
|
93
|
+
def elapsed
|
94
|
+
((Time.now.getutc.to_f * 1000 - start_time) / 1000).to_i
|
95
|
+
end
|
96
|
+
|
97
|
+
def start_time
|
98
|
+
@redis.hget(@key, START_TIME).to_i
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
data/lib/rlimiter.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'rlimiter/version'
|
2
|
+
|
3
|
+
# It is important that the files are loaded in the order specified below because of inheritance dependencies.
|
4
|
+
# TODO: Figure out a better way to load
|
5
|
+
require_files = %w[/rlimiter/client.rb /rlimiter/invalid_client_error.rb /rlimiter/version.rb /rlimiter/redis_client.rb]
|
6
|
+
require_files.each do |file|
|
7
|
+
Dir.glob(File.dirname(File.absolute_path(__FILE__)) + file, &method(:require))
|
8
|
+
end
|
9
|
+
|
10
|
+
# Module which is single-instantiated in the application via :init.
|
11
|
+
module Rlimiterclass InvalidClientError < RuntimeError
|
12
|
+
class << self
|
13
|
+
|
14
|
+
# At the moment only redis client is supported.
|
15
|
+
CLIENTS = %w[redis].freeze
|
16
|
+
attr_accessor :client
|
17
|
+
|
18
|
+
# One time initializes the client which is to be used throughout the application.
|
19
|
+
# The value of params variable will change depending on the storage client to be initialized.
|
20
|
+
# @param [Hash] params
|
21
|
+
# @return [Rlimiter::Client]
|
22
|
+
def init(params)
|
23
|
+
case params[:client]
|
24
|
+
when 'redis'
|
25
|
+
@client = RedisClient.new(params)
|
26
|
+
else
|
27
|
+
raise InvalidClientError, "Valid clients are #{CLIENTS.join(',')}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# Note : Params for the below methods are kept arbitrary for free implementation and are specific to a single client,
|
32
|
+
# after usage feedback it will be refactored to pertain to a single signature.
|
33
|
+
|
34
|
+
# Register a hit to the client.
|
35
|
+
def limit(*params)
|
36
|
+
client.limit(*params)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Returns when the next hit will be accepted
|
40
|
+
def next_in(*params)
|
41
|
+
client.next_in(*params)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Returns the current hit count.
|
45
|
+
def current_count(*params)
|
46
|
+
client.current_count(*params)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/rlimiter.gemspec
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'rlimiter/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'rlimiter'
|
7
|
+
spec.version = Rlimiter::VERSION
|
8
|
+
spec.authors = ['Sidharth Patro']
|
9
|
+
spec.email = ['sidharth.patro@outlook.com']
|
10
|
+
|
11
|
+
spec.summary = 'Rate limiting library for Ruby'
|
12
|
+
spec.homepage = 'https://github.com/sdpatro/rlimiter'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
16
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
17
|
+
if spec.respond_to?(:metadata)
|
18
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
19
|
+
else
|
20
|
+
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
21
|
+
'public gem pushes.'
|
22
|
+
end
|
23
|
+
|
24
|
+
# Specify which files should be added to the gem when it is released.
|
25
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
26
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
27
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
28
|
+
end
|
29
|
+
spec.bindir = 'exe'
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ['lib']
|
32
|
+
|
33
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
34
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
35
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
36
|
+
spec.add_runtime_dependency 'redis', '~> 4.0.2'
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rlimiter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sidharth Patro
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-09-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: redis
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 4.0.2
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 4.0.2
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- sidharth.patro@outlook.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
79
|
+
- CODE_OF_CONDUCT.md
|
80
|
+
- Gemfile
|
81
|
+
- Gemfile.lock
|
82
|
+
- LICENSE.txt
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- bin/console
|
86
|
+
- bin/setup
|
87
|
+
- lib/rlimiter.rb
|
88
|
+
- lib/rlimiter/client.rb
|
89
|
+
- lib/rlimiter/invalid_client_error.rb
|
90
|
+
- lib/rlimiter/redis_client.rb
|
91
|
+
- lib/rlimiter/version.rb
|
92
|
+
- rlimiter.gemspec
|
93
|
+
homepage: https://github.com/sdpatro/rlimiter
|
94
|
+
licenses:
|
95
|
+
- MIT
|
96
|
+
metadata:
|
97
|
+
allowed_push_host: https://rubygems.org
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
requirements: []
|
113
|
+
rubyforge_project:
|
114
|
+
rubygems_version: 2.7.7
|
115
|
+
signing_key:
|
116
|
+
specification_version: 4
|
117
|
+
summary: Rate limiting library for Ruby
|
118
|
+
test_files: []
|