grape-throttler 1.0.1 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.fasterer.yml +12 -12
- data/.gitignore +0 -2
- data/.rubocop.yml +31 -23
- data/.travis.yml +22 -2
- data/CHANGELOG.md +30 -0
- data/CODE_OF_CONDUCT.md +68 -7
- data/Gemfile +1 -3
- data/Gemfile.lock +130 -0
- data/README.md +15 -7
- data/_config.yml +1 -0
- data/bin/console +2 -2
- data/bin/setup +2 -1
- data/grape-throttler.gemspec +23 -5
- data/lib/grape-throttler.rb +5 -6
- data/lib/grape-throttler/middleware/throttle_middleware.rb +15 -9
- data/lib/grape-throttler/version.rb +3 -1
- metadata +35 -24
- data/.gitattributes +0 -2
- data/.irbrc +0 -44
- data/.reek.yml +0 -22
- data/.ruby-version +0 -1
- data/bin/rake +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9340326427b8e9996850ce329b5c93db8c1cd68e2211259b4cc6fd3679ab59e
|
4
|
+
data.tar.gz: 289e3a04990a9ba9ce03f7391dfde7123d131dcc98566b79e87f33a6b0b8d767
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e38f16cbfb71efb8b18b75f65e1a13cb512156ab3420e196c15c748cf6c56a7d3c9371e80767522710d6e538f686afbd6500db2974ef4cea3be42fcd824ab80
|
7
|
+
data.tar.gz: 14f1f3069f9447efea296de63702c474b98c7dfdcc5fb06aed2385a9565f3e0b6d63ed5428016793f126b5c7cf2359c5bb9a4f7138bca3ad5b31115c76b1fd4d
|
data/.fasterer.yml
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
speedups:
|
2
|
-
|
3
|
-
module_eval: true
|
4
|
-
shuffle_first_vs_sample: true
|
5
|
-
for_loop_vs_each: true
|
2
|
+
block_vs_symbol_to_proc: true
|
6
3
|
each_with_index_vs_while: false
|
7
|
-
map_flatten_vs_flat_map: true
|
8
|
-
reverse_each_vs_reverse_each: true
|
9
|
-
select_first_vs_detect: true
|
10
|
-
sort_vs_sort_by: true
|
11
4
|
fetch_with_argument_vs_block: true
|
12
|
-
|
5
|
+
for_loop_vs_each: true
|
6
|
+
getter_vs_attr_reader: true
|
7
|
+
gsub_vs_tr: true
|
13
8
|
hash_merge_bang_vs_hash_brackets: true
|
14
|
-
|
9
|
+
keys_each_vs_each_key: true
|
10
|
+
map_flatten_vs_flat_map: true
|
11
|
+
module_eval: true
|
15
12
|
proc_call_vs_yield: true
|
16
|
-
|
13
|
+
rescue_vs_respond_to: true
|
14
|
+
reverse_each_vs_reverse_each: true
|
15
|
+
select_first_vs_detect: true
|
17
16
|
select_last_vs_reverse_detect: true
|
18
|
-
getter_vs_attr_reader: true
|
19
17
|
setter_vs_attr_writer: true
|
18
|
+
shuffle_first_vs_sample: true
|
19
|
+
sort_vs_sort_by: true
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -1,39 +1,47 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-performance
|
3
|
+
- rubocop-rake
|
4
|
+
- rubocop-rspec
|
1
5
|
AllCops:
|
6
|
+
TargetRubyVersion: 3.0
|
7
|
+
NewCops: enable
|
2
8
|
DisplayCopNames: true
|
3
9
|
DisplayStyleGuide: true
|
4
|
-
|
10
|
+
Gemspec/RequiredRubyVersion:
|
11
|
+
Enabled: false
|
12
|
+
Layout/EmptyLinesAroundAttributeAccessor:
|
13
|
+
Enabled: true
|
14
|
+
Layout/EmptyLinesAroundBlockBody:
|
5
15
|
Exclude:
|
6
|
-
- 'lib/**/**/templates/*'
|
7
16
|
- 'spec/**/**/*'
|
8
17
|
Layout/EmptyLinesAroundClassBody:
|
9
|
-
|
18
|
+
EnforcedStyle: empty_lines_except_namespace
|
10
19
|
Layout/EmptyLinesAroundModuleBody:
|
11
|
-
|
12
|
-
LineLength:
|
20
|
+
EnforcedStyle: empty_lines_except_namespace
|
21
|
+
Layout/LineLength:
|
13
22
|
Max: 100
|
14
|
-
|
15
|
-
Enabled:
|
16
|
-
Lint/
|
17
|
-
Enabled:
|
18
|
-
Lint/
|
19
|
-
Enabled:
|
20
|
-
Metrics/
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
Layout/SpaceAroundMethodCallOperator:
|
24
|
+
Enabled: true
|
25
|
+
Lint/RaiseException:
|
26
|
+
Enabled: true
|
27
|
+
Lint/StructNewOverride:
|
28
|
+
Enabled: true
|
29
|
+
Metrics/BlockLength:
|
30
|
+
Exclude:
|
31
|
+
- 'spec/**/**/*'
|
32
|
+
- '*.gemspec'
|
33
|
+
Naming/FileName:
|
25
34
|
Enabled: false
|
26
|
-
|
35
|
+
RSpec/ExampleLength:
|
27
36
|
Enabled: false
|
28
|
-
|
37
|
+
RSpec/FilePath:
|
38
|
+
Exclude:
|
39
|
+
- 'spec/grape-throttler/version_spec.rb'
|
40
|
+
RSpec/MultipleExpectations:
|
29
41
|
Enabled: false
|
30
|
-
Style/
|
42
|
+
Style/ArgumentsForwarding:
|
31
43
|
Enabled: false
|
32
44
|
Style/Documentation:
|
33
45
|
Enabled: false
|
34
46
|
Style/ExpandPathArguments:
|
35
47
|
Enabled: false
|
36
|
-
Style/RescueModifier:
|
37
|
-
Enabled: false
|
38
|
-
Style/RescueStandardError:
|
39
|
-
Enabled: false
|
data/.travis.yml
CHANGED
@@ -1,5 +1,25 @@
|
|
1
1
|
sudo: false
|
2
2
|
language: ruby
|
3
|
+
cache: bundler
|
3
4
|
rvm:
|
4
|
-
|
5
|
-
|
5
|
+
- 2.5
|
6
|
+
- 2.6
|
7
|
+
- 2.7
|
8
|
+
- ruby-head
|
9
|
+
matrix:
|
10
|
+
fast_finish: true
|
11
|
+
allow_failures:
|
12
|
+
- rvm: ruby-head
|
13
|
+
before_install:
|
14
|
+
- gem update --system
|
15
|
+
- gem install bundler
|
16
|
+
install:
|
17
|
+
- bundle install --jobs=3 --retry=3
|
18
|
+
script:
|
19
|
+
- bundle exec rspec
|
20
|
+
- bundle exec rubocop
|
21
|
+
- bundle exec fasterer
|
22
|
+
notifications:
|
23
|
+
email: false
|
24
|
+
slack:
|
25
|
+
secure: WN6Tc8kREPwVy7a+Pk1TpzKkzM8Hk++8Z8znAS51mkpvkv8g95HO9TysTZtQ+gv05L4l9V9tJsjVF2vCvJgrWQ84ilhpgBG62X+L2E/2SPB3TX0Hxh+VInCkmsg1h/FsnoZ1S9H4WjW6jbunCWl+ecytCJXNFvKtkmsbUAIVZY2jji6oKacsQZMeL+BvsKAnny7/1JJ3sSEuGZ4LXeQ1TL+mI74awmeJIuGWJfwNH6fW/z6sN4f/25ZNtiLEMZ+0rzzE7mO4k3GBv+tPPwqL1547/2KTEwHCSmPDHjpmzdA0yQ/razrA4n/Iqb5vS0ZCS6WYg6udiAh5aWwUg+g4VAzMegTqw0kGWpnTHNTuMzRGh1uKTXF5MH4T+a1FGOxnrFkZUZhCJPa2+NTbuHHxl6pycFxA+D7sGvEwaEbRgJ26y0IGk9ZnhJAhmtEddsCsdcPE4pb+10+ppbOZI1fW56UT3/f6l75Zj2QclmE2EjEi4+MqgLX8FJvT5iHhsBH7/MFNlOGftH/l2iiRFu9MmFC/BroAOF541DSP/n/Eocu7f2tiHV3Km9beHOWwYLL7nGhPhp2XlzaYA2eTQtzF3foswL440OO0PMfmmT2AbjK8uagvPPQkPFv40L40KLOnsKo+/tli8IjSqWDdwKrR69X0EmAflpu8UBzez8pCe9A=
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# Changelog
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
|
4
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
|
+
|
7
|
+
## [Unreleased]
|
8
|
+
|
9
|
+
## [1.2.1] - 2021-07-19
|
10
|
+
### Changed
|
11
|
+
- Setup clean up
|
12
|
+
|
13
|
+
## [1.2.0] - 2021-07-19
|
14
|
+
### Added
|
15
|
+
- Added Ruby 3.0 support
|
16
|
+
|
17
|
+
## [1.1.1] - 2021-07-05
|
18
|
+
### Changed
|
19
|
+
- Linter fixes
|
20
|
+
|
21
|
+
## [1.1.0] - 2019-11-25
|
22
|
+
### Added
|
23
|
+
- Added CHANGELOG.md
|
24
|
+
- Added ruby 2.7 support
|
25
|
+
### Changed
|
26
|
+
- Refactor code to clean up lint errors
|
27
|
+
|
28
|
+
## [1.0.1] - 2019-11-25
|
29
|
+
### NOTE
|
30
|
+
- Previous version without CHANGELOG.md
|
data/CODE_OF_CONDUCT.md
CHANGED
@@ -1,13 +1,74 @@
|
|
1
|
-
# Contributor Code of Conduct
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
2
|
|
3
|
-
|
3
|
+
## Our Pledge
|
4
4
|
|
5
|
-
|
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.
|
6
11
|
|
7
|
-
|
12
|
+
## Our Standards
|
8
13
|
|
9
|
-
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
10
16
|
|
11
|
-
|
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
|
12
22
|
|
13
|
-
|
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 j.gomez@drexed.com. 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
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
grape-throttler (1.2.1)
|
5
|
+
grape (>= 0.16.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activesupport (6.1.4)
|
11
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
12
|
+
i18n (>= 1.6, < 2)
|
13
|
+
minitest (>= 5.1)
|
14
|
+
tzinfo (~> 2.0)
|
15
|
+
zeitwerk (~> 2.3)
|
16
|
+
ast (2.4.2)
|
17
|
+
builder (3.2.4)
|
18
|
+
colorize (0.8.1)
|
19
|
+
concurrent-ruby (1.1.9)
|
20
|
+
diff-lcs (1.4.4)
|
21
|
+
dry-configurable (0.12.1)
|
22
|
+
concurrent-ruby (~> 1.0)
|
23
|
+
dry-core (~> 0.5, >= 0.5.0)
|
24
|
+
dry-container (0.8.0)
|
25
|
+
concurrent-ruby (~> 1.0)
|
26
|
+
dry-configurable (~> 0.1, >= 0.1.3)
|
27
|
+
dry-core (0.7.1)
|
28
|
+
concurrent-ruby (~> 1.0)
|
29
|
+
dry-inflector (0.2.1)
|
30
|
+
dry-logic (1.2.0)
|
31
|
+
concurrent-ruby (~> 1.0)
|
32
|
+
dry-core (~> 0.5, >= 0.5)
|
33
|
+
dry-types (1.5.1)
|
34
|
+
concurrent-ruby (~> 1.0)
|
35
|
+
dry-container (~> 0.3)
|
36
|
+
dry-core (~> 0.5, >= 0.5)
|
37
|
+
dry-inflector (~> 0.1, >= 0.1.2)
|
38
|
+
dry-logic (~> 1.0, >= 1.0.2)
|
39
|
+
fakeredis (0.8.0)
|
40
|
+
redis (~> 4.1)
|
41
|
+
fasterer (0.9.0)
|
42
|
+
colorize (~> 0.7)
|
43
|
+
ruby_parser (>= 3.14.1)
|
44
|
+
grape (1.5.3)
|
45
|
+
activesupport
|
46
|
+
builder
|
47
|
+
dry-types (>= 1.1)
|
48
|
+
mustermann-grape (~> 1.0.0)
|
49
|
+
rack (>= 1.3.0)
|
50
|
+
rack-accept
|
51
|
+
i18n (1.8.10)
|
52
|
+
concurrent-ruby (~> 1.0)
|
53
|
+
minitest (5.14.4)
|
54
|
+
mustermann (1.1.1)
|
55
|
+
ruby2_keywords (~> 0.0.1)
|
56
|
+
mustermann-grape (1.0.1)
|
57
|
+
mustermann (>= 1.0.0)
|
58
|
+
parallel (1.20.1)
|
59
|
+
parser (3.0.2.0)
|
60
|
+
ast (~> 2.4.1)
|
61
|
+
rack (2.2.3)
|
62
|
+
rack-accept (0.4.5)
|
63
|
+
rack (>= 0.4)
|
64
|
+
rack-test (1.1.0)
|
65
|
+
rack (>= 1.0, < 3)
|
66
|
+
rainbow (3.0.0)
|
67
|
+
rake (13.0.6)
|
68
|
+
redis (4.3.1)
|
69
|
+
regexp_parser (2.1.1)
|
70
|
+
rexml (3.2.5)
|
71
|
+
rspec (3.10.0)
|
72
|
+
rspec-core (~> 3.10.0)
|
73
|
+
rspec-expectations (~> 3.10.0)
|
74
|
+
rspec-mocks (~> 3.10.0)
|
75
|
+
rspec-core (3.10.1)
|
76
|
+
rspec-support (~> 3.10.0)
|
77
|
+
rspec-expectations (3.10.1)
|
78
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
79
|
+
rspec-support (~> 3.10.0)
|
80
|
+
rspec-mocks (3.10.2)
|
81
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
82
|
+
rspec-support (~> 3.10.0)
|
83
|
+
rspec-support (3.10.2)
|
84
|
+
rubocop (1.18.3)
|
85
|
+
parallel (~> 1.10)
|
86
|
+
parser (>= 3.0.0.0)
|
87
|
+
rainbow (>= 2.2.2, < 4.0)
|
88
|
+
regexp_parser (>= 1.8, < 3.0)
|
89
|
+
rexml
|
90
|
+
rubocop-ast (>= 1.7.0, < 2.0)
|
91
|
+
ruby-progressbar (~> 1.7)
|
92
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
93
|
+
rubocop-ast (1.8.0)
|
94
|
+
parser (>= 3.0.1.1)
|
95
|
+
rubocop-performance (1.11.4)
|
96
|
+
rubocop (>= 1.7.0, < 2.0)
|
97
|
+
rubocop-ast (>= 0.4.0)
|
98
|
+
rubocop-rake (0.6.0)
|
99
|
+
rubocop (~> 1.0)
|
100
|
+
rubocop-rspec (2.4.0)
|
101
|
+
rubocop (~> 1.0)
|
102
|
+
rubocop-ast (>= 1.1.0)
|
103
|
+
ruby-progressbar (1.11.0)
|
104
|
+
ruby2_keywords (0.0.5)
|
105
|
+
ruby_parser (3.16.0)
|
106
|
+
sexp_processor (~> 4.15, >= 4.15.1)
|
107
|
+
sexp_processor (4.15.3)
|
108
|
+
tzinfo (2.0.4)
|
109
|
+
concurrent-ruby (~> 1.0)
|
110
|
+
unicode-display_width (2.0.0)
|
111
|
+
zeitwerk (2.4.2)
|
112
|
+
|
113
|
+
PLATFORMS
|
114
|
+
ruby
|
115
|
+
|
116
|
+
DEPENDENCIES
|
117
|
+
bundler
|
118
|
+
fakeredis
|
119
|
+
fasterer
|
120
|
+
grape-throttler!
|
121
|
+
rack-test
|
122
|
+
rake
|
123
|
+
rspec
|
124
|
+
rubocop
|
125
|
+
rubocop-performance
|
126
|
+
rubocop-rake
|
127
|
+
rubocop-rspec
|
128
|
+
|
129
|
+
BUNDLED WITH
|
130
|
+
2.2.24
|
data/README.md
CHANGED
@@ -53,7 +53,7 @@ The `user_key` parameter is a function that can be used to determine a custom id
|
|
53
53
|
|
54
54
|
**Logging**
|
55
55
|
|
56
|
-
The gem will log errors to
|
56
|
+
The gem will log errors to $stdout by default. If you prefer a different logger you can use the `logger` option to pass in your own logger.
|
57
57
|
|
58
58
|
```ruby
|
59
59
|
use GrapeThrottler::Middleware::ThrottleMiddleware, cache: Redis.new, logger: Logger.new('my_custom_log.log')
|
@@ -115,12 +115,20 @@ class API < GrapeThrottler::API
|
|
115
115
|
end
|
116
116
|
```
|
117
117
|
|
118
|
+
## Development
|
119
|
+
|
120
|
+
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.
|
121
|
+
|
122
|
+
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).
|
123
|
+
|
118
124
|
## Contributing
|
119
125
|
|
120
|
-
|
126
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/grape-throttler. 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.
|
127
|
+
|
128
|
+
## License
|
129
|
+
|
130
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
131
|
+
|
132
|
+
## Code of Conduct
|
121
133
|
|
122
|
-
|
123
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
124
|
-
3. Commit your changes (`git commit -am 'Added some feature'`)
|
125
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
126
|
-
5. Create new Pull Request
|
134
|
+
Everyone interacting in the Lite::Ruby project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/grape-throttler/blob/master/CODE_OF_CONDUCT.md).
|
data/_config.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
theme: jekyll-theme-leap-day
|
data/bin/console
CHANGED
@@ -8,8 +8,8 @@ require 'grape-throttler'
|
|
8
8
|
# with your gem easier. You can also use a different console, if you like.
|
9
9
|
|
10
10
|
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
-
# require
|
11
|
+
# require "pry"
|
12
12
|
# Pry.start
|
13
13
|
|
14
14
|
require 'irb'
|
15
|
-
IRB.start
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
CHANGED
data/grape-throttler.gemspec
CHANGED
@@ -10,25 +10,43 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.authors = ['Juan Gomez']
|
11
11
|
spec.email = ['j.gomez@drexed.com']
|
12
12
|
|
13
|
-
spec.summary = '
|
14
|
-
spec.description = 'A middleware for Grape to add endpoint-specific throttling.'
|
13
|
+
spec.summary = 'Middleware for Grape to add endpoint-specific throttling.'
|
15
14
|
spec.homepage = 'http://drexed.github.io/grape-throttler'
|
16
15
|
spec.license = 'MIT'
|
17
16
|
|
18
|
-
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata.merge(
|
21
|
+
'allowed_push_host' => 'https://rubygems.org',
|
22
|
+
'changelog_uri' => 'https://github.com/drexed/grape-throttler/blob/master/CHANGELOG.md',
|
23
|
+
'homepage_uri' => spec.homepage,
|
24
|
+
'source_code_uri' => 'https://github.com/drexed/grape-throttler'
|
25
|
+
)
|
26
|
+
else
|
27
|
+
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
28
|
+
'public gem pushes.'
|
29
|
+
end
|
30
|
+
|
31
|
+
# Specify which files should be added to the gem when it is released.
|
32
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
33
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
34
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
35
|
+
end
|
19
36
|
spec.bindir = 'exe'
|
20
37
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
38
|
spec.require_paths = %w[lib]
|
22
39
|
|
23
40
|
spec.add_runtime_dependency 'grape', '>= 0.16.0'
|
24
|
-
spec.add_runtime_dependency 'rails'
|
25
41
|
|
26
42
|
spec.add_development_dependency 'bundler'
|
27
43
|
spec.add_development_dependency 'fakeredis'
|
28
44
|
spec.add_development_dependency 'fasterer'
|
29
45
|
spec.add_development_dependency 'rack-test'
|
30
46
|
spec.add_development_dependency 'rake'
|
31
|
-
spec.add_development_dependency 'reek'
|
32
47
|
spec.add_development_dependency 'rspec'
|
33
48
|
spec.add_development_dependency 'rubocop'
|
49
|
+
spec.add_development_dependency 'rubocop-performance'
|
50
|
+
spec.add_development_dependency 'rubocop-rake'
|
51
|
+
spec.add_development_dependency 'rubocop-rspec'
|
34
52
|
end
|
data/lib/grape-throttler.rb
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
end
|
3
|
+
require 'grape' unless defined?(Grape)
|
4
|
+
require 'logger' unless defined?(Logger)
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
require 'grape-throttler/version'
|
7
|
+
|
8
|
+
require 'grape-throttler/extensions/throttle_extension'
|
10
9
|
|
11
10
|
module GrapeThrottler
|
12
11
|
module Middleware
|
@@ -4,11 +4,13 @@ module GrapeThrottler
|
|
4
4
|
module Middleware
|
5
5
|
class ThrottleMiddleware < Grape::Middleware::Base
|
6
6
|
|
7
|
-
COUNTER_START
|
7
|
+
COUNTER_START = 0
|
8
8
|
|
9
|
+
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
|
10
|
+
# rubocop:disable Metrics/PerceivedComplexity, Lint/AssignmentInCondition
|
9
11
|
def before
|
10
12
|
endpoint = env['api.endpoint']
|
11
|
-
logger = options[:logger] || Logger.new(
|
13
|
+
logger = options[:logger] || Logger.new($stdout)
|
12
14
|
|
13
15
|
return unless throttle_options = endpoint.route_setting(:throttle)
|
14
16
|
|
@@ -32,14 +34,16 @@ module GrapeThrottler
|
|
32
34
|
endpoint.error!('Too Many Requests', 429)
|
33
35
|
else
|
34
36
|
redis.multi do
|
35
|
-
redis.set(rate_key, COUNTER_START,
|
37
|
+
redis.set(rate_key, COUNTER_START, nx: true, ex: period.to_i)
|
36
38
|
redis.incr(rate_key)
|
37
39
|
end
|
38
40
|
end
|
39
|
-
rescue
|
41
|
+
rescue StandardError => e
|
40
42
|
logger.warn(e.message)
|
41
43
|
end
|
42
44
|
end
|
45
|
+
# rubocop:enable Metrics/PerceivedComplexity, Lint/AssignmentInCondition
|
46
|
+
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
|
43
47
|
|
44
48
|
private
|
45
49
|
|
@@ -49,19 +53,21 @@ module GrapeThrottler
|
|
49
53
|
raise ArgumentError, 'Please set a period and limit (see documentation)'
|
50
54
|
end
|
51
55
|
|
56
|
+
# rubocop:disable Lint/AssignmentInCondition
|
52
57
|
def find_limit_and_period(throttle_options)
|
53
58
|
if limit = throttle_options[:hourly]
|
54
|
-
period =
|
59
|
+
period = 3_600
|
55
60
|
elsif limit = throttle_options[:daily]
|
56
|
-
period =
|
61
|
+
period = 86_400
|
57
62
|
elsif limit = throttle_options[:monthly]
|
58
|
-
period =
|
63
|
+
period = 2_629_746
|
59
64
|
elsif period = throttle_options[:period]
|
60
65
|
limit = throttle_options[:limit]
|
61
66
|
end
|
62
67
|
|
63
68
|
[limit, period]
|
64
69
|
end
|
70
|
+
# rubocop:enable Lint/AssignmentInCondition
|
65
71
|
|
66
72
|
def find_user_value(options)
|
67
73
|
user_key = options[:user_key]
|
@@ -71,8 +77,8 @@ module GrapeThrottler
|
|
71
77
|
end
|
72
78
|
|
73
79
|
def generate_rate_key(endpoint, user_value)
|
74
|
-
|
75
|
-
"#{
|
80
|
+
endpoint_route = endpoint.routes.first
|
81
|
+
"#{endpoint_route.request_method}:#{endpoint_route.path}:#{user_value}"
|
76
82
|
end
|
77
83
|
|
78
84
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape-throttler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juan Gomez
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-07-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grape
|
@@ -25,13 +25,13 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 0.16.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
|
-
type: :
|
34
|
+
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: fakeredis
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: fasterer
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
@@ -67,7 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: rack-test
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
@@ -81,7 +81,7 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: rake
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
@@ -95,7 +95,7 @@ dependencies:
|
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: rspec
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - ">="
|
@@ -109,7 +109,7 @@ dependencies:
|
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
112
|
+
name: rubocop
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - ">="
|
@@ -123,7 +123,7 @@ dependencies:
|
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
126
|
+
name: rubocop-performance
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
129
|
- - ">="
|
@@ -137,7 +137,21 @@ dependencies:
|
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
|
-
name: rubocop
|
140
|
+
name: rubocop-rake
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: rubocop-rspec
|
141
155
|
requirement: !ruby/object:Gem::Requirement
|
142
156
|
requirements:
|
143
157
|
- - ">="
|
@@ -150,7 +164,7 @@ dependencies:
|
|
150
164
|
- - ">="
|
151
165
|
- !ruby/object:Gem::Version
|
152
166
|
version: '0'
|
153
|
-
description:
|
167
|
+
description:
|
154
168
|
email:
|
155
169
|
- j.gomez@drexed.com
|
156
170
|
executables: []
|
@@ -158,20 +172,18 @@ extensions: []
|
|
158
172
|
extra_rdoc_files: []
|
159
173
|
files:
|
160
174
|
- ".fasterer.yml"
|
161
|
-
- ".gitattributes"
|
162
175
|
- ".gitignore"
|
163
|
-
- ".irbrc"
|
164
|
-
- ".reek.yml"
|
165
176
|
- ".rspec"
|
166
177
|
- ".rubocop.yml"
|
167
|
-
- ".ruby-version"
|
168
178
|
- ".travis.yml"
|
179
|
+
- CHANGELOG.md
|
169
180
|
- CODE_OF_CONDUCT.md
|
170
181
|
- Gemfile
|
182
|
+
- Gemfile.lock
|
171
183
|
- README.md
|
172
184
|
- Rakefile
|
185
|
+
- _config.yml
|
173
186
|
- bin/console
|
174
|
-
- bin/rake
|
175
187
|
- bin/setup
|
176
188
|
- grape-throttler.gemspec
|
177
189
|
- lib/grape-throttler.rb
|
@@ -182,7 +194,7 @@ homepage: http://drexed.github.io/grape-throttler
|
|
182
194
|
licenses:
|
183
195
|
- MIT
|
184
196
|
metadata: {}
|
185
|
-
post_install_message:
|
197
|
+
post_install_message:
|
186
198
|
rdoc_options: []
|
187
199
|
require_paths:
|
188
200
|
- lib
|
@@ -197,9 +209,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
197
209
|
- !ruby/object:Gem::Version
|
198
210
|
version: '0'
|
199
211
|
requirements: []
|
200
|
-
|
201
|
-
|
202
|
-
signing_key:
|
212
|
+
rubygems_version: 3.2.24
|
213
|
+
signing_key:
|
203
214
|
specification_version: 4
|
204
|
-
summary:
|
215
|
+
summary: Middleware for Grape to add endpoint-specific throttling.
|
205
216
|
test_files: []
|
data/.gitattributes
DELETED
data/.irbrc
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Awesome print
|
4
|
-
begin
|
5
|
-
require 'awesome_print'
|
6
|
-
|
7
|
-
AwesomePrint.irb!
|
8
|
-
rescue LoadError => err
|
9
|
-
warn "Couldn't load awesome_print: #{err}"
|
10
|
-
end
|
11
|
-
|
12
|
-
# IRB
|
13
|
-
require 'irb/completion'
|
14
|
-
|
15
|
-
ARGV.concat %w[--readline --prompt-mode simple]
|
16
|
-
|
17
|
-
IRB.conf[:PROMPT_MODE] = :SIMPLE
|
18
|
-
IRB.conf[:EVAL_HISTORY] = 1000
|
19
|
-
IRB.conf[:SAVE_HISTORY] = 1000
|
20
|
-
IRB.conf[:HISTORY_FILE] = File.expand_path('.irbrc_history')
|
21
|
-
|
22
|
-
# Rails
|
23
|
-
railsrc_path = File.expand_path('.irbrc_rails')
|
24
|
-
|
25
|
-
if (ENV['RAILS_ENV'] || defined?(Rails)) && File.exist?(railsrc_path)
|
26
|
-
begin
|
27
|
-
load railsrc_path
|
28
|
-
rescue Exception => err
|
29
|
-
warn "Could not load: #{railsrc_path} because of #{err}"
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
# Object
|
34
|
-
class Object
|
35
|
-
|
36
|
-
def interesting_methods
|
37
|
-
case self.class
|
38
|
-
when Class then public_methods.sort - Object.public_methods
|
39
|
-
when Module then public_methods.sort - Module.public_methods
|
40
|
-
else public_methods.sort - Object.new.public_methods
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
data/.reek.yml
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
---
|
2
|
-
detectors:
|
3
|
-
Attribute:
|
4
|
-
enabled: false
|
5
|
-
IrresponsibleModule:
|
6
|
-
enabled: false
|
7
|
-
MissingSafeMethod:
|
8
|
-
enabled: false
|
9
|
-
NilCheck:
|
10
|
-
enabled: false
|
11
|
-
TooManyInstanceVariables:
|
12
|
-
enabled: false
|
13
|
-
TooManyStatements:
|
14
|
-
max_statements: 10
|
15
|
-
exclude:
|
16
|
-
- 'GrapeThrottler::Middleware::ThrottleMiddleware#before'
|
17
|
-
UncommunicativeVariableName:
|
18
|
-
accept:
|
19
|
-
- '/^.$/'
|
20
|
-
- '/[0-9]$/'
|
21
|
-
UtilityFunction:
|
22
|
-
enabled: false
|
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
2.5.1
|
data/bin/rake
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
# This file was generated by Bundler.
|
5
|
-
#
|
6
|
-
# The application 'rake' is installed as part of a gem, and
|
7
|
-
# this file is here to facilitate running it.
|
8
|
-
|
9
|
-
require 'pathname'
|
10
|
-
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', Pathname.new(__FILE__).realpath)
|
11
|
-
|
12
|
-
require 'rubygems'
|
13
|
-
require 'bundler/setup'
|
14
|
-
|
15
|
-
load Gem.bin_path('rake', 'rake')
|