lucid_shopify 0.8.1 → 0.9.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: 12b757cd447fee99904c3353433439aa23137a30f013bf12a69306e1caa9b713
4
- data.tar.gz: d813b755fb636bbc8aaec08b32d1a041c7c2cb68ba276860b4b60e0b962b8595
3
+ metadata.gz: '06921ad4b8c0a2b5d8fd6a6e2d58001fde145d1f0c8dae16c1727cfba09f41b5'
4
+ data.tar.gz: bc83dad007907aa4f368903d4c9679dda345983c6b4269ceb513ba5982665a06
5
5
  SHA512:
6
- metadata.gz: 602f0e5c4bdca73c5aa52d86e726fed91399df1cf443394e1f97a64c8d32676be0ea2b40a7369ffc1325332debb5cecdc8160748c5386bc77d1f0cf62c97db46
7
- data.tar.gz: 4fe28f3352a77227954df395ac17675bf749852cb7d3c373caf0d8cd892580d8e74ad67feea840a2fc95413d6c0c1dd654abbd2a51ad9c783eb869c51e8f9426
6
+ metadata.gz: a9659399ab10805210c7c97fbdd43d8e712881a1f3b9e172d1d1432ac72b56f22f00df51073df1b594b934515d3e1c2ba12d9ba68e83605d435b4639bced3442
7
+ data.tar.gz: 914b1beba17b2d7d98b6c90b7fea4e94947585ef213ff84fe6e41566fdb826b09765da39b270f09baa2b262aee9b7d3cdee47696504cd899374f7a2a9f3eac0e
data/README.md CHANGED
@@ -79,7 +79,7 @@ Create/delete webhooks manually:
79
79
  Verify callback requests with the request params:
80
80
 
81
81
  begin
82
- LucidShopify::AssertCallback.new.(params)
82
+ LucidShopify::VerifyCallback.new.(params)
83
83
  rescue LucidShopify::Error => e
84
84
  # ...
85
85
  end
@@ -87,7 +87,7 @@ Verify callback requests with the request params:
87
87
  Verify webhook requests with the request data and the HMAC header:
88
88
 
89
89
  begin
90
- LucidShopify::AssertWebhook.new.(data, hmac)
90
+ LucidShopify::VerifyWebhook.new.(data, hmac)
91
91
  rescue LucidShopify::Error => e
92
92
  # ...
93
93
  end
@@ -4,7 +4,19 @@ require 'lucid_shopify'
4
4
 
5
5
  module LucidShopify
6
6
  #
7
- # Convenient way to build the charge hash for {CreateCharge}.
7
+ # @example Subclass to provide application defaults
8
+ # class Charge < LucidShopify::Charge
9
+ # def initialize(shop)
10
+ # super('Application name',
11
+ # 9,
12
+ # test: test?,
13
+ # trial_days: shop.trial_started_at?.nil? ? 30 : nil)
14
+ # end
15
+ #
16
+ # def test?
17
+ # # ...
18
+ # end
19
+ # end
8
20
  #
9
21
  class Charge
10
22
  #
@@ -2,43 +2,89 @@
2
2
 
3
3
  require 'lucid_shopify/container'
4
4
 
5
- %w(delete get post put).each { |m| require "lucid_shopify/#{m}_request" }
5
+ %w[delete get post put].each { |m| require "lucid_shopify/#{m}_request" }
6
6
 
7
7
  module LucidShopify
8
8
  class Client
9
9
  #
10
10
  # @param send_request [#call]
11
+ # @param send_throttled_request [#call]
11
12
  #
12
- def initialize(send_request: Container[:send_request])
13
+ def initialize(send_request: Container[:send_request],
14
+ send_throttled_request: Container[:send_throttled_request],
15
+ throttling: false)
13
16
  @send_request = send_request
17
+ @send_throttled_request = send_throttled_request
18
+ @throttling = throttling
19
+
20
+ @params = {
21
+ send_request: @send_request,
22
+ send_throttled_request: @send_throttled_request
23
+ }
24
+ end
25
+
26
+ #
27
+ # @return [#call]
28
+ #
29
+ private def send_request
30
+ throttled? ? @send_throttled_request : @send_request
31
+ end
32
+
33
+ #
34
+ # @return [Boolean]
35
+ #
36
+ def throttled?
37
+ @throttling
38
+ end
39
+
40
+ #
41
+ # Returns a new instance with throttling enabled, or self.
42
+ #
43
+ # @return [Client, self]
44
+ #
45
+ def throttled
46
+ return self if throttled?
47
+
48
+ self.class.new(**@params, throttling: true)
49
+ end
50
+
51
+ #
52
+ # Returns a new instance with throttling disabled, or self.
53
+ #
54
+ # @return [Client, self]
55
+ #
56
+ def unthrottled
57
+ return self unless throttled?
58
+
59
+ self.class.new(**@params, throttling: false)
14
60
  end
15
61
 
16
62
  #
17
63
  # @see DeleteRequest#initialize
18
64
  #
19
65
  def delete(*args)
20
- @send_request.(DeleteRequest.new(*args))
66
+ send_request.(DeleteRequest.new(*args))
21
67
  end
22
68
 
23
69
  #
24
70
  # @see GetRequest#initialize
25
71
  #
26
72
  def get(*args)
27
- @send_request.(GetRequest.new(*args))
73
+ send_request.(GetRequest.new(*args))
28
74
  end
29
75
 
30
76
  #
31
77
  # @see PostRequest#initialize
32
78
  #
33
79
  def post_json(*args)
34
- @send_request.(PostRequest.new(*args))
80
+ send_request.(PostRequest.new(*args))
35
81
  end
36
82
 
37
83
  #
38
84
  # @see PutRequest#initialize
39
85
  #
40
86
  def put_json(*args)
41
- @send_request.(PutRequest.new(*args))
87
+ send_request.(PutRequest.new(*args))
42
88
  end
43
89
  end
44
90
  end
@@ -9,8 +9,6 @@ module LucidShopify
9
9
 
10
10
  # Services only (dependencies); no value objects, entities.
11
11
  Container.register(:activate_charge) { ActivateCharge.new }
12
- Container.register(:assert_callback) { AssertCallback.new }
13
- Container.register(:assert_webhook) { AssertWebhook.new }
14
12
  Container.register(:client) { Client.new }
15
13
  Container.register(:create_all_webhooks) { CreateAllWebhooks.new }
16
14
  Container.register(:create_charge) { CreateCharge.new }
@@ -20,4 +18,6 @@ module LucidShopify
20
18
  Container.register(:fetch_access_token) { FetchAccessToken.new }
21
19
  Container.register(:send_request) { SendRequest.new }
22
20
  Container.register(:send_throttled_request) { SendThrottledRequest.new }
21
+ Container.register(:verify_callback) { VerifyCallback.new }
22
+ Container.register(:verify_webhook) { VerifyWebhook.new }
23
23
  end
@@ -5,11 +5,11 @@ require 'openssl'
5
5
  require 'lucid_shopify'
6
6
 
7
7
  module LucidShopify
8
- class AssertCallback
8
+ class VerifyCallback
9
9
  Error = Class.new(Error)
10
10
 
11
11
  #
12
- # Assert that the callback request originated from Shopify.
12
+ # Verify that the callback request originated from Shopify.
13
13
  #
14
14
  # @param params [Hash] the request params
15
15
  #
@@ -6,11 +6,11 @@ require 'openssl'
6
6
  require 'lucid_shopify'
7
7
 
8
8
  module LucidShopify
9
- class AssertWebhook
9
+ class VerifyWebhook
10
10
  Error = Class.new(Error)
11
11
 
12
12
  #
13
- # Assert that the webhook request originated from Shopify.
13
+ # Verify that the webhook request originated from Shopify.
14
14
  #
15
15
  # @param data [String] the signed request data
16
16
  # @param hmac [String] the signature
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LucidShopify
4
- VERSION = '0.8.1'
4
+ VERSION = '0.9.0'
5
5
  end
data/lib/lucid_shopify.rb CHANGED
@@ -4,8 +4,6 @@ require 'dry/initializer'
4
4
 
5
5
  module LucidShopify
6
6
  autoload :ActivateCharge, 'lucid_shopify/activate_charge'
7
- autoload :AssertCallback, 'lucid_shopify/assert_callback'
8
- autoload :AssertWebhook, 'lucid_shopify/assert_webhook'
9
7
  autoload :Charge, 'lucid_shopify/charge'
10
8
  autoload :Client, 'lucid_shopify/client'
11
9
  autoload :Config, 'lucid_shopify/config'
@@ -27,6 +25,8 @@ module LucidShopify
27
25
  autoload :Result, 'lucid_shopify/result'
28
26
  autoload :SendRequest, 'lucid_shopify/send_request'
29
27
  autoload :SendThrottledRequest, 'lucid_shopify/send_throttled_request'
28
+ autoload :VerifyCallback, 'lucid_shopify/verify_callback'
29
+ autoload :VerifyWebhook, 'lucid_shopify/verify_webhook'
30
30
  autoload :VERSION, 'lucid_shopify/version'
31
31
  autoload :Webhook, 'lucid_shopify/webhook'
32
32
  autoload :WebhookHandlerList, 'lucid_shopify/webhook_handler_list'
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.8.1
4
+ version: 0.9.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-05-01 00:00:00.000000000 Z
11
+ date: 2018-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv
@@ -117,8 +117,6 @@ files:
117
117
  - README.md
118
118
  - lib/lucid_shopify.rb
119
119
  - lib/lucid_shopify/activate_charge.rb
120
- - lib/lucid_shopify/assert_callback.rb
121
- - lib/lucid_shopify/assert_webhook.rb
122
120
  - lib/lucid_shopify/charge.rb
123
121
  - lib/lucid_shopify/client.rb
124
122
  - lib/lucid_shopify/config.rb
@@ -139,6 +137,8 @@ files:
139
137
  - lib/lucid_shopify/response.rb
140
138
  - lib/lucid_shopify/send_request.rb
141
139
  - lib/lucid_shopify/send_throttled_request.rb
140
+ - lib/lucid_shopify/verify_callback.rb
141
+ - lib/lucid_shopify/verify_webhook.rb
142
142
  - lib/lucid_shopify/version.rb
143
143
  - lib/lucid_shopify/webhook.rb
144
144
  - lib/lucid_shopify/webhook_handler_list.rb