fulfil-io 0.6.0 → 0.7.0

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: 0c58e4104ae9106550bca7c000cbf3f576f551c9e4512cee93dc74dd0aa5604f
4
- data.tar.gz: ee0644f88360b5356efa034833772a54d207ce4be7e81040219e8d66019ff301
3
+ metadata.gz: 63d67b77df97810e72d56c2cd60a859004ee97de438bd11332cb643c8b8d0466
4
+ data.tar.gz: 82708a84ce96c3254236ab4ce7e05a9d64477dc12b94ebb47d758ad267cc818e
5
5
  SHA512:
6
- metadata.gz: d697a2153dcbcd379621b59bc7ef8af428c4f6ecc2445d454afc38eddb34247430279136f758fe52e538abcda923c386dbc4d7f2af00c27e9e41c26f71a4c5e2
7
- data.tar.gz: e6e891f839dd472f24f1dc89ce1189cb80b9218ac09c35c4141c0dd0b575097ecb0d238d47de8e688bc69c3298da0f4e1b2478ebfed1010d139c3fb4087f0ccf
6
+ metadata.gz: 609049e9604f06602526be98da080e33bdbc1a1d5a46e4d338cc5a86cf5f9df9584963b6462e30da5d493b354bb73ca7c489d1c9229b37230ef7654af821cc43
7
+ data.tar.gz: f27513ccae674a68a294e12aacecf82c92a2caa6d65077a6abc7497c41703b7b689a4cb2a1b421a9b65c95584243d5a9d95b2f33b11571ec76eba009005cce13
data/README.md CHANGED
@@ -9,7 +9,7 @@ A Ruby library for the [Fulfil.io](https://fulfil.io) API.
9
9
  Add this line to your application's Gemfile:
10
10
 
11
11
  ```ruby
12
- gem 'fulfil-io', require: 'fulfil'
12
+ gem 'fulfil-io'
13
13
  ```
14
14
 
15
15
  And then execute:
@@ -37,8 +37,6 @@ if oauth doesn't work, returning an Unauthorized error, to use the
37
37
  `FULFIL_API_KEY`, the `FULFIL_OAUTH_TOKEN` shouldn't be specified.
38
38
 
39
39
  ```ruby
40
- require 'fulfil' # this is necessary only in case of running without bundler
41
-
42
40
  fulfil = Fulfil::Client.new # or, to enable request debugging, Fulfil::Client.new(debug: true)
43
41
 
44
42
  sale_model = Fulfil::Model.new(
@@ -47,7 +45,7 @@ sale_model = Fulfil::Model.new(
47
45
  )
48
46
 
49
47
  sales = sale_model.search(
50
- domain: [['id', '=', [10]]],
48
+ domain: [['id', '=', 10]],
51
49
  fields: ['id', 'rec_name', 'lines']
52
50
  )
53
51
 
@@ -147,6 +145,18 @@ $ Fulfil.rate_limit.limit
147
145
  $ Fulfil.rate_limit.resets_at
148
146
  => #<DateTime: 2022-01-21T16:36:01-04:00 />
149
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
+
150
160
  ## Development
151
161
 
152
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.0"
4
+ VERSION = "0.7.0"
5
5
  end
data/lib/fulfil-io.rb ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ # By convention, Bundler will attempt to load the `fulfil/io.rb` or `fulfil-io.rb` file.
4
+ # See https://guides.rubygems.org/name-your-gem/
5
+ #
6
+ # Due to this convention, the developer using this gem will need to manually
7
+ # require fulfil in the Gemfile or anywhere else in their application.
8
+ #
9
+ # To make it a little bit more convenient, we've added the `fulfil-io.rb` file
10
+ # that is loaded by default by Bundler and it's only job is to include all of
11
+ # the other gem files.
12
+
13
+ require 'fulfil'
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.0
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-03-23 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
@@ -149,8 +149,10 @@ files:
149
149
  - LICENSE.txt
150
150
  - README.md
151
151
  - Rakefile
152
+ - lib/fulfil-io.rb
152
153
  - lib/fulfil.rb
153
154
  - lib/fulfil/client.rb
155
+ - lib/fulfil/configuration.rb
154
156
  - lib/fulfil/error.rb
155
157
  - lib/fulfil/interactive_report.rb
156
158
  - lib/fulfil/model.rb
@@ -179,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
179
181
  - !ruby/object:Gem::Version
180
182
  version: '0'
181
183
  requirements: []
182
- rubygems_version: 3.3.7
184
+ rubygems_version: 3.3.12
183
185
  signing_key:
184
186
  specification_version: 4
185
187
  summary: Interact with the Fulfil.io API