grape-throttling 0.1.0 → 0.1.1

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
  SHA256:
3
- metadata.gz: af60e3bd619a2608ab8ab0ad68b3040b03bb14c26a84467e996e23ffb96db0bf
4
- data.tar.gz: 1eadd65155a233b585f7c547f500760703dcc1d773cf45cc33b6eed76264bf83
3
+ metadata.gz: 3aab77fdedb6a77b7a4de1583352c11f8eb73d797fe3bc67f8075436257100ac
4
+ data.tar.gz: 67fabd18bd8324a7d2a1f8df795b5a9507d6a3ff6f7ea164c14d582d91f99051
5
5
  SHA512:
6
- metadata.gz: 32e1eb6a1d13978bbcd11e1f2fcad756ad91ad333e3c86d9617ff00c13006eb911e319a8097d04495c6c18fdccb7c9958fa4cccc1f3be3d7f150981fcc5ff48c
7
- data.tar.gz: '09ef4bd9a04b3a6a1f054aff1dfb77e054a6c84995e0ba8ee76d92138bc1082278b44840e8c8412e48c4026de4257008145e1bdfd0f4d778f1e087f4f5c6797d'
6
+ metadata.gz: 20ba672eca5e35767111fc8c042cfb870a3677df47ffcc87dba8dc82885d135a8bf1165a92cf966249f38ed7b33152b2733668347e7143be0f8c19b81f013563
7
+ data.tar.gz: 7e4fc918914fe7e9d6b1a2aef41a8440cdae79fe405a2012fb34318ae01e4e3c4bf7339b994af0b7c72ebd9fe88d7a64e363889467818629db0cb899366493c0
@@ -1,6 +1,7 @@
1
1
  require:
2
- # - rubocop-packaging
3
2
  - rubocop-performance
3
+ - rubocop-minitest
4
+ # - rubocop-packaging
4
5
 
5
6
  Metrics/BlockLength:
6
7
  Enabled: false
@@ -14,5 +15,11 @@ Lint/NestedMethodDefinition:
14
15
  Layout/RescueEnsureAlignment:
15
16
  Enabled: false
16
17
 
18
+ Layout/LineLength:
19
+ Max: 120
20
+
21
+ Style/DoubleNegation:
22
+ Enabled: false
23
+
17
24
  Gemspec/OrderedDependencies:
18
25
  Enabled: false
@@ -1,15 +1,24 @@
1
1
  ---
2
2
  services:
3
3
  - redis
4
+
4
5
  language: ruby
6
+
5
7
  rvm:
6
8
  - 2.5.8
7
9
  - 2.6.6
8
10
  - 2.7.2
11
+
9
12
  before_install: gem install bundler
13
+
10
14
  after_success: bundle install
15
+
11
16
  gemfile:
12
17
  - gemfiles/grape-0-16
13
18
  - gemfiles/grape-1-0
14
19
  - gemfiles/grape-1-5
20
+
15
21
  script: bundle exec rake test && bundle exec rubocop
22
+
23
+ notifications:
24
+ email: false
@@ -0,0 +1,7 @@
1
+ # Change log
2
+
3
+ ## master
4
+
5
+ ### 0.1.1 (2020-11-05)
6
+
7
+ - Dimension reduction support ruby >= 2.3.0
data/README.md CHANGED
@@ -5,6 +5,8 @@
5
5
 
6
6
  If your api through [`grape`](https://github.com/ruby-grape/grape) build, you can use `grape-throttling` limit api rate.
7
7
 
8
+ **Import:** `Grape::Throttling` depend on [`redis`](https://github.com/redis/redis), you must install [`redis`](https://github.com/redis/redis) first
9
+
8
10
  - **Simple**. The you only need to call `use_throttle` in your api internal.
9
11
  - **Throttle remind**. The response header include `X-RateLimit-Limit`, `X-Ratelimit-Used`, `X-RateLimit-Remaining`, `X-RateLimit-Reset`.
10
12
 
@@ -43,6 +45,15 @@ end
43
45
  | `condition` | `proc { true }` | Condition of enabled throttle. |
44
46
  | `identity` | `proc { request.ip }` | Used for throttle identity. |
45
47
 
48
+ ## Configure
49
+
50
+ ```ruby
51
+ # default configuration
52
+ Grape::Throttling.configure do |config|
53
+ config.redis = ::Redis.new(url: 'redis://localhost:6379/0', driver: :hiredis)
54
+ end
55
+ ```
56
+
46
57
  ## Development
47
58
 
48
59
  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.
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
12
12
  spec.description = 'Grape rate limit exceeded.'
13
13
  spec.homepage = 'https://github.com/OuYangJinTing/grape-throttling'
14
14
  spec.license = 'MIT'
15
- spec.required_ruby_version = Gem::Requirement.new('>= 2.4.0')
15
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
16
16
 
17
17
  # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
18
18
 
@@ -37,7 +37,9 @@ Gem::Specification.new do |spec|
37
37
  spec.add_development_dependency 'rack-test'
38
38
  spec.add_development_dependency 'pry'
39
39
  spec.add_development_dependency 'minitest-reporters'
40
- spec.add_development_dependency 'rubocop'
40
+ # The higher rubocop do not support ruby-2.3
41
+ spec.add_development_dependency 'rubocop', '~> 0.81.0'
42
+ spec.add_development_dependency 'rubocop-performance', '~> 1.6.1'
43
+ spec.add_development_dependency 'rubocop-minitest'
41
44
  # spec.add_development_dependency 'rubocop-packaging'
42
- spec.add_development_dependency 'rubocop-performance'
43
45
  end
@@ -8,7 +8,7 @@ module Grape
8
8
 
9
9
  module ClassMethods # :nodoc:
10
10
  # rubocop:disable Style/ClassVars
11
- def use_throttle(max: 60, expire: 1.day, condition: proc { true }, identity: proc { request.ip }) # rubocop:disable Metrics/MethodLength
11
+ def use_throttle(max: 60, expire: 1.day, condition: proc { true }, identity: proc { request.ip }) # rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity
12
12
  max = max.try(:to_i).to_i
13
13
  raise ArgumentError, 'max must be positive number' unless max.positive?
14
14
  raise ArgumentError, 'condition must be Proc' unless condition.is_a?(Proc)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Grape
4
4
  module Throttling
5
- VERSION = '0.1.0'
5
+ VERSION = '0.1.1'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grape-throttling
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - OuYangJinTing
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-11-04 00:00:00.000000000 Z
11
+ date: 2020-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grape
@@ -112,18 +112,32 @@ dependencies:
112
112
  name: rubocop
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ">="
115
+ - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '0'
117
+ version: 0.81.0
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ">="
122
+ - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '0'
124
+ version: 0.81.0
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: rubocop-performance
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 1.6.1
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 1.6.1
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop-minitest
127
141
  requirement: !ruby/object:Gem::Requirement
128
142
  requirements:
129
143
  - - ">="
@@ -181,7 +195,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
181
195
  requirements:
182
196
  - - ">="
183
197
  - !ruby/object:Gem::Version
184
- version: 2.4.0
198
+ version: 2.3.0
185
199
  required_rubygems_version: !ruby/object:Gem::Requirement
186
200
  requirements:
187
201
  - - ">="