fulfil-io 0.6.1 → 0.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d85caade2af0ca4d9ede6a970d0c9b802960e5bc192a41d70eb9c70f153640b1
4
- data.tar.gz: 13b43002ee089a9781221b7c42cef81a12474a11ccdb9f6e9df248eaabff8f84
3
+ metadata.gz: 63d67b77df97810e72d56c2cd60a859004ee97de438bd11332cb643c8b8d0466
4
+ data.tar.gz: 82708a84ce96c3254236ab4ce7e05a9d64477dc12b94ebb47d758ad267cc818e
5
5
  SHA512:
6
- metadata.gz: 415418f4c4a54490b95d3823272096e481b064bf0be0f45cd44dc2c093af7616d93e56b46e0286447febf154f1187fbcbf31a0d3f3d8e456846a5590b636bc04
7
- data.tar.gz: 854d989c8b343dabd2317850f578a7a2c37c9a19d04873b19eb278c278a78a51c94a928d5cf24f5a7265f05a63ff6d1dfcb5853971448843957827af9554bb9e
6
+ metadata.gz: 609049e9604f06602526be98da080e33bdbc1a1d5a46e4d338cc5a86cf5f9df9584963b6462e30da5d493b354bb73ca7c489d1c9229b37230ef7654af821cc43
7
+ data.tar.gz: f27513ccae674a68a294e12aacecf82c92a2caa6d65077a6abc7497c41703b7b689a4cb2a1b421a9b65c95584243d5a9d95b2f33b11571ec76eba009005cce13
data/README.md CHANGED
@@ -145,6 +145,18 @@ $ Fulfil.rate_limit.limit
145
145
  $ Fulfil.rate_limit.resets_at
146
146
  => #<DateTime: 2022-01-21T16:36:01-04:00 />
147
147
  ```
148
+
149
+ 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
+
151
+ ```ruby
152
+ # config/initializers/fulfil.rb
153
+
154
+ Fulfil.configure do |config|
155
+ config.retry_on_rate_limit = true # Defaults to false
156
+ config.retry_on_rate_limit_wait = 0.25 # Defaults to 1 (second)
157
+ end
158
+ ```
159
+
148
160
  ## Development
149
161
 
150
162
  After checking out the repo, run `bin/setup` to install dependencies. Then, run
data/lib/fulfil/client.rb CHANGED
@@ -164,6 +164,13 @@ module Fulfil
164
164
  rescue HTTP::ResponseError => e
165
165
  raise ResponseError, "Can't process response: #{e}"
166
166
  []
167
+ # If configured, the client will wait whenever the `RateLimitExceeded` exception
168
+ # is raised. Check `Fulfil::Configuration` for more details.
169
+ rescue RateLimitExceeded => e
170
+ raise e unless config.retry_on_rate_limit?
171
+
172
+ sleep config.retry_on_rate_limit_wait
173
+ retry
167
174
  end
168
175
 
169
176
  def client
@@ -172,5 +179,9 @@ module Fulfil
172
179
  client = client.headers(@headers)
173
180
  client
174
181
  end
182
+
183
+ def config
184
+ Fulfil.config
185
+ end
175
186
  end
176
187
  end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fulfil
4
+ # The `Fulfil::Configuration` contains the available configuration options
5
+ # for the `Fulfil` gem.
6
+ class Configuration
7
+ # Allow the `Fulfil::Client` to automatically retry when the rate limit is hit.
8
+ # By default, the `Fulfil::Client` will wait 1 second before retrying again.
9
+ attr_accessor :retry_on_rate_limit
10
+ attr_accessor :retry_on_rate_limit_wait
11
+
12
+ def initialize
13
+ @retry_on_rate_limit = false
14
+ @retry_on_rate_limit_wait = 1
15
+ end
16
+
17
+ def retry_on_rate_limit?
18
+ @retry_on_rate_limit
19
+ end
20
+ end
21
+
22
+ # Returns Fulfil's configuration.
23
+ # @return [Fulfil::Configuration] Fulfil's configuration
24
+ def self.config
25
+ @config ||= Configuration.new
26
+ end
27
+
28
+ # Allows setting a new configuration for Fulfil.
29
+ # @return [Fulfil::Configuration] Fulfil's new configuration
30
+ def self.config=(configuration)
31
+ @config = configuration
32
+ end
33
+
34
+ # Allows modifying Fulfil's configuration.
35
+ #
36
+ # Example usage:
37
+ #
38
+ # Fulfil.configure do |config|
39
+ # config.api_key = "..."
40
+ # end
41
+ #
42
+ def self.configure
43
+ yield(config)
44
+ end
45
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Fulfil
4
- VERSION = "0.6.1"
4
+ VERSION = "0.7.0"
5
5
  end
data/lib/fulfil.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'fulfil/version'
4
4
  require 'fulfil/error'
5
+ require 'fulfil/configuration'
5
6
  require 'fulfil/client'
6
7
  require 'fulfil/model'
7
8
  require 'fulfil/interactive_report'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fulfil-io
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Moore
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-04-22 00:00:00.000000000 Z
12
+ date: 2022-09-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: http
@@ -152,6 +152,7 @@ files:
152
152
  - lib/fulfil-io.rb
153
153
  - lib/fulfil.rb
154
154
  - lib/fulfil/client.rb
155
+ - lib/fulfil/configuration.rb
155
156
  - lib/fulfil/error.rb
156
157
  - lib/fulfil/interactive_report.rb
157
158
  - lib/fulfil/model.rb
@@ -180,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
180
181
  - !ruby/object:Gem::Version
181
182
  version: '0'
182
183
  requirements: []
183
- rubygems_version: 3.3.7
184
+ rubygems_version: 3.3.12
184
185
  signing_key:
185
186
  specification_version: 4
186
187
  summary: Interact with the Fulfil.io API