lucid_shopify 0.15.1 → 0.16.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: b1fa336bfc2abcc35129665ab1679ce26a214e8cc711a9f2f02cb8d12dc910ff
4
- data.tar.gz: 59d6e27a766ef0b189e4475a658986ede24c8aaba514e5e0f8a4ac9aba859bf5
3
+ metadata.gz: fa7a124e765e51f59294a364b97b006e5898b96cf2613745c66ac35051ec46ab
4
+ data.tar.gz: deb41acf5b31b21a7eee70bf644b8daff3badf6e716653076df2760940545145
5
5
  SHA512:
6
- metadata.gz: c95ec5d9ba4317494ac5d761bea90ee846b096f75dad3e15399d974966ad663bb0a924262b08053fc382c3126c26de5ebbff34d7a95bd2436cde579d566c31c9
7
- data.tar.gz: 0dbea237b8786e642e596999c8500f6a57efa8bf9fc92aa8ca044a5c097e38ecd7c637ee8e3a8958e978f783ff52fe4b5618d96a7b5f49779030b38eff79aec6
6
+ metadata.gz: d86eb37763f25cdbc7fd686a9bd0fe31e5139db86d33a87a11cf27bd8ce05c7617f3b02a978a4f4194f67f6fad44f86ee299ad69e25cea2ca2843980a5761183
7
+ data.tar.gz: bfd6ace749c04766bd6270350fdcce7ac4593f0881c561091ce2b70fca3caeae25a78bc41efb0b7cf12b19033ccbbcd2cf834da8e99dd9d249fa356ed857b56d
data/lib/lucid_shopify.rb CHANGED
@@ -23,7 +23,7 @@ module LucidShopify
23
23
  autoload :Response, 'lucid_shopify/response'
24
24
  autoload :Result, 'lucid_shopify/result'
25
25
  autoload :SendRequest, 'lucid_shopify/send_request'
26
- autoload :SendThrottledRequest, 'lucid_shopify/send_throttled_request'
26
+ autoload :ThrottledStrategy, 'lucid_shopify/throttled_strategy'
27
27
  autoload :VerifyCallback, 'lucid_shopify/verify_callback'
28
28
  autoload :VerifyWebhook, 'lucid_shopify/verify_webhook'
29
29
  autoload :VERSION, 'lucid_shopify/version'
@@ -19,7 +19,7 @@ module LucidShopify
19
19
  Container.register(:delete_webhook) { DeleteWebhook.new }
20
20
  Container.register(:http) { ::HTTP::Client.new }
21
21
  Container.register(:send_request) { SendRequest.new }
22
- Container.register(:send_throttled_request) { SendThrottledRequest.new }
22
+ Container.register(:send_throttled_request) { SendRequest.new(strategy: ThrottledStrategy.new) }
23
23
  Container.register(:verify_callback) { VerifyCallback.new }
24
24
  Container.register(:verify_webhook) { VerifyWebhook.new }
25
25
  Container.register(:webhook_handler_list) { LucidShopify.handlers }
@@ -13,9 +13,12 @@ module LucidShopify
13
13
 
14
14
  #
15
15
  # @param http [HTTP::Client]
16
+ # @param strategy [#call, nil] unthrottled by default
16
17
  #
17
- def initialize(http: Container[:http])
18
+ def initialize(http: Container[:http],
19
+ strategy: ->(*, &block) { block.() })
18
20
  @http = http
21
+ @strategy = strategy
19
22
  end
20
23
 
21
24
  #
@@ -29,8 +32,11 @@ module LucidShopify
29
32
  # @raise [Response::ServerError] for status 5xx
30
33
  #
31
34
  def call(request, attempts: default_attempts)
32
- res = send(request)
33
- res = Response.new(request, res.code, res.headers.to_h, res.to_s)
35
+ res = @strategy.(request) do
36
+ res = send(request)
37
+
38
+ Response.new(request, res.code, res.headers.to_h, res.to_s)
39
+ end
34
40
 
35
41
  res.assert!.data_hash
36
42
  rescue HTTP::ConnectionError,
@@ -3,16 +3,20 @@
3
3
  require 'lucid_shopify'
4
4
 
5
5
  module LucidShopify
6
- class SendThrottledRequest < SendRequest
6
+ class ThrottledStrategy
7
7
  MINIMUM_INTERVAL = 500 # ms
8
8
 
9
9
  #
10
- # @see SendRequest#call
10
+ # @param request [Request]
11
+ #
12
+ # @yieldreturn [Response]
13
+ #
14
+ # @return [Response]
11
15
  #
12
- def call(request, attempts: default_attempts)
16
+ def call(request, &send_request)
13
17
  interval(build_interval_key(request))
14
18
 
15
- super(request, attempts: attempts)
19
+ send_request.()
16
20
  end
17
21
 
18
22
  #
@@ -26,7 +30,7 @@ module LucidShopify
26
30
  private def interval(interval_key)
27
31
  if Thread.current[interval_key]
28
32
  (timestamp - Thread.current[interval_key]).tap do |n|
29
- sleep(Rational(n, 1000)) if n < MINIMUM_INTERVAL
33
+ sleep(Rational(MINIMUM_INTERVAL - n, 1000)) if n < MINIMUM_INTERVAL
30
34
  end
31
35
  end
32
36
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LucidShopify
4
- VERSION = '0.15.1'
4
+ VERSION = '0.16.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lucid_shopify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.1
4
+ version: 0.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kelsey Judson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-13 00:00:00.000000000 Z
11
+ date: 2018-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv
@@ -135,7 +135,7 @@ files:
135
135
  - lib/lucid_shopify/request.rb
136
136
  - lib/lucid_shopify/response.rb
137
137
  - lib/lucid_shopify/send_request.rb
138
- - lib/lucid_shopify/send_throttled_request.rb
138
+ - lib/lucid_shopify/throttled_strategy.rb
139
139
  - lib/lucid_shopify/verify_callback.rb
140
140
  - lib/lucid_shopify/verify_webhook.rb
141
141
  - lib/lucid_shopify/version.rb