fulfil-io 0.7.0 → 0.7.1
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 +4 -4
- data/README.md +16 -0
- data/lib/fulfil/configuration.rb +13 -0
- data/lib/fulfil/rate_limit.rb +13 -2
- data/lib/fulfil/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 379e34db2187ee0e41cbc4a530deec467a6f7874c8474c6a5057981ed6ff7ffc
|
4
|
+
data.tar.gz: da1e1fcf9945729d29554c803fcd954611575ba54f74e7f1c1931fe4e4554731
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12f8136e71bbe678bac2e3091209b5c56f03f3a70ceb3df50ebca4d88ac32f527e3f29c308affa2180f6e0e6c23964b48fed87801f18173c369f8cc161eb794f
|
7
|
+
data.tar.gz: 415ab129cabfe1bba36c7fd9bd94b083eeeb64fe0ff71ad508a6f29e74111ab863c281d4da93020b44ec54b1d9ef3fc1ac19ef1809e74af08091deb8824bac1f
|
data/README.md
CHANGED
@@ -146,6 +146,8 @@ $ Fulfil.rate_limit.resets_at
|
|
146
146
|
=> #<DateTime: 2022-01-21T16:36:01-04:00 />
|
147
147
|
```
|
148
148
|
|
149
|
+
### Automatic retry API call after rate limit hit
|
150
|
+
|
149
151
|
Automatic retries are supported whenever the rate limit is reached. However, it's not enabled by default. To enable it, set the `retry_on_rate_limit` to `true`. By default, the request will be retried in 1 second.
|
150
152
|
|
151
153
|
```ruby
|
@@ -157,6 +159,20 @@ Fulfil.configure do |config|
|
|
157
159
|
end
|
158
160
|
```
|
159
161
|
|
162
|
+
### Monitor rate limit hits
|
163
|
+
|
164
|
+
Through the configurable `rate_limit_notification_handler` one can monitor the rate limit hits to the APM tool of choice.
|
165
|
+
|
166
|
+
```ruby
|
167
|
+
# config/initializers/fulfil.rb
|
168
|
+
|
169
|
+
Fulfil.configure do |config|
|
170
|
+
config.rate_limit_notification_handler = proc {
|
171
|
+
FakeAPM.increment_counter('fulfil.rate_limit_exceeded')
|
172
|
+
}
|
173
|
+
end
|
174
|
+
```
|
175
|
+
|
160
176
|
## Development
|
161
177
|
|
162
178
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
data/lib/fulfil/configuration.rb
CHANGED
@@ -9,6 +9,19 @@ module Fulfil
|
|
9
9
|
attr_accessor :retry_on_rate_limit
|
10
10
|
attr_accessor :retry_on_rate_limit_wait
|
11
11
|
|
12
|
+
# Allows the client to configure a notification handler. Can be used by APM
|
13
|
+
# tools to monitor the number of rate limit hits.
|
14
|
+
#
|
15
|
+
# @example Use APM to monitor the API rate limit hits
|
16
|
+
# Fulfil.configure do |config|
|
17
|
+
# config.rate_limit_notification_handler = proc {
|
18
|
+
# FakeAPM.increment_counter('fulfil.rate_limit_exceeded')
|
19
|
+
# }
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
# @return [Proc, nil]
|
23
|
+
attr_accessor :rate_limit_notification_handler
|
24
|
+
|
12
25
|
def initialize
|
13
26
|
@retry_on_rate_limit = false
|
14
27
|
@retry_on_rate_limit_wait = 1
|
data/lib/fulfil/rate_limit.rb
CHANGED
@@ -8,7 +8,8 @@ module Fulfil
|
|
8
8
|
|
9
9
|
# Analyses the rate limit based on the response headers from Fulfil.
|
10
10
|
# @param headers [HTTP::Headers] The HTTP response headers from Fulfil.
|
11
|
-
# @
|
11
|
+
# @raise [Fulfil::RateLimitExceeded] When the rate limit is hit.
|
12
|
+
# @return [true]
|
12
13
|
def analyse!(headers)
|
13
14
|
rate_limit_headers = RateLimitHeaders.new(headers)
|
14
15
|
|
@@ -16,7 +17,9 @@ module Fulfil
|
|
16
17
|
self.requests_left = rate_limit_headers.requests_left
|
17
18
|
self.resets_at = rate_limit_headers.resets_at
|
18
19
|
|
19
|
-
|
20
|
+
return true if requests_left?
|
21
|
+
|
22
|
+
report_rate_limit_hit_and_raise
|
20
23
|
end
|
21
24
|
|
22
25
|
# Returns whether there are any requests left in the current rate limit window.
|
@@ -24,5 +27,13 @@ module Fulfil
|
|
24
27
|
def requests_left?
|
25
28
|
requests_left&.positive?
|
26
29
|
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
# @raise [Fulfil::RateLimitExceeded]
|
34
|
+
def report_rate_limit_hit_and_raise
|
35
|
+
Fulfil.config.rate_limit_notification_handler&.call
|
36
|
+
raise Fulfil::RateLimitExceeded
|
37
|
+
end
|
27
38
|
end
|
28
39
|
end
|
data/lib/fulfil/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fulfil-io
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Moore
|
8
8
|
- Kat Fairbanks
|
9
|
+
- Stefan Vermaas
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date: 2022-09-
|
13
|
+
date: 2022-09-23 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: http
|
@@ -20,7 +21,7 @@ dependencies:
|
|
20
21
|
version: 4.4.1
|
21
22
|
- - "<"
|
22
23
|
- !ruby/object:Gem::Version
|
23
|
-
version: 5.
|
24
|
+
version: 5.2.0
|
24
25
|
type: :runtime
|
25
26
|
prerelease: false
|
26
27
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -30,7 +31,7 @@ dependencies:
|
|
30
31
|
version: 4.4.1
|
31
32
|
- - "<"
|
32
33
|
- !ruby/object:Gem::Version
|
33
|
-
version: 5.
|
34
|
+
version: 5.2.0
|
34
35
|
- !ruby/object:Gem::Dependency
|
35
36
|
name: bundler
|
36
37
|
requirement: !ruby/object:Gem::Requirement
|