lucid-shopify 0.37.0 → 0.40.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +21 -6
- data/lib/lucid/shopify/client.rb +2 -1
- data/lib/lucid/shopify/container.rb +1 -0
- data/lib/lucid/shopify/parse_link_header.rb +39 -0
- data/lib/lucid/shopify/request.rb +1 -1
- data/lib/lucid/shopify/response.rb +36 -0
- data/lib/lucid/shopify/version.rb +1 -1
- data/lib/lucid/shopify.rb +2 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98281c9fea5c19507b29e96c9ac8d5ccaf1c1f94b902cd3f736c28514913228a
|
4
|
+
data.tar.gz: 5e7c2d62db39d4ca105666fccc329b255d3e20e4de7730d2d75f8dd031d3cd77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9461458119fca0aafc7fe4ebe00366a544ca63aba55588beec3d86d749f26ae9b2e7f31da3460511ea471b4f0fdbfb04c05a35ff0906fbb4809d7b5c00cc84a7
|
7
|
+
data.tar.gz: 6912e93c75a6c708b7da8e31b778fe266ce26e823473c3a6a5859b73e716feb73b307bab2b7dd0ddfe90ab88fde65bb7e219349705656ef9b7cda715db4719c6
|
data/README.md
CHANGED
@@ -16,7 +16,7 @@ Usage
|
|
16
16
|
|
17
17
|
Lucid::Shopify.configure do |config|
|
18
18
|
config.api_key = '...'
|
19
|
-
config.api_version = '...' # e.g. '
|
19
|
+
config.api_version = '...' # e.g. '2020-01'
|
20
20
|
config.billing_callback_uri = '...'
|
21
21
|
config.callback_uri = '...' # (for OAuth; unused by this gem)
|
22
22
|
config.logger = Logger.new(STDOUT)
|
@@ -135,11 +135,26 @@ Request logging is disabled by default. To enable it:
|
|
135
135
|
|
136
136
|
Lucid::Shopify.config.logger = Logger.new(STDOUT)
|
137
137
|
|
138
|
+
Request throttling is enabled by default. If you're using Redis, throttling
|
139
|
+
will automatically make use of it; otherwise, throttling will only be
|
140
|
+
maintained across a single thread.
|
138
141
|
|
139
|
-
### Make throttled API requests
|
140
142
|
|
141
|
-
|
142
|
-
client.throttled.post_json(credentials, 'orders', new_order)
|
143
|
+
### Make unthrottled API requests
|
143
144
|
|
144
|
-
|
145
|
-
|
145
|
+
client.unthrottled.get(credentials, 'orders')
|
146
|
+
client.unthrottled.post_json(credentials, 'orders', new_order)
|
147
|
+
|
148
|
+
|
149
|
+
### Pagination
|
150
|
+
|
151
|
+
Since API version 2019-07, Shopify has encouraged a new method for
|
152
|
+
pagination based on the Link header. When you make a GET request,
|
153
|
+
you can request the next or the previous page directly from the
|
154
|
+
response object.
|
155
|
+
|
156
|
+
page_1 = client.get(credentials, 'orders')
|
157
|
+
page_2 = page_1.next
|
158
|
+
page_1 = page_2.previous
|
159
|
+
|
160
|
+
When no page is available, `nil` will be returned.
|
data/lib/lucid/shopify/client.rb
CHANGED
@@ -9,9 +9,10 @@ module Lucid
|
|
9
9
|
class Client
|
10
10
|
# @param send_request [#call]
|
11
11
|
# @param send_throttled_request [#call]
|
12
|
+
# @param throttling [Boolean]
|
12
13
|
def initialize(send_request: Container[:send_request],
|
13
14
|
send_throttled_request: Container[:send_throttled_request],
|
14
|
-
throttling:
|
15
|
+
throttling: true)
|
15
16
|
@send_request = send_request
|
16
17
|
@send_throttled_request = send_throttled_request
|
17
18
|
@throttling = throttling
|
@@ -19,6 +19,7 @@ module Lucid
|
|
19
19
|
Container.register(:delete_all_webhooks) { DeleteAllWebhooks.new }
|
20
20
|
Container.register(:delete_webhook) { DeleteWebhook.new }
|
21
21
|
Container.register(:http) { ::HTTP::Client.new }
|
22
|
+
Container.register(:parse_link_header) { ParseLinkHeader.new }
|
22
23
|
Container.register(:send_request) { SendRequest.new }
|
23
24
|
Container.register(:send_throttled_request) do
|
24
25
|
if defined?(Redis)
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'lucid/shopify'
|
4
|
+
|
5
|
+
module Lucid
|
6
|
+
module Shopify
|
7
|
+
class ParseLinkHeader
|
8
|
+
# Parse a Link header into query params for each pagination link (e.g.
|
9
|
+
# :next, :previous).
|
10
|
+
#
|
11
|
+
# @param link_header [String, nil]
|
12
|
+
#
|
13
|
+
# @return [Hash]
|
14
|
+
def call(link_header)
|
15
|
+
return {} if link_header.nil?
|
16
|
+
|
17
|
+
link_header.split(',').map do |link|
|
18
|
+
url, rel = link.split(';') # rel should be the first param
|
19
|
+
url = url[/<(.*)>/, 1]
|
20
|
+
rel = rel[/rel="?(\w+)"?/, 1]
|
21
|
+
|
22
|
+
[rel.to_sym, query_params(url)]
|
23
|
+
end.to_h
|
24
|
+
end
|
25
|
+
|
26
|
+
# @param url [String]
|
27
|
+
#
|
28
|
+
# @return [Hash]
|
29
|
+
private def query_params(url)
|
30
|
+
url.split('?').last.split('&').map do |param|
|
31
|
+
name, value = param.split('=')
|
32
|
+
name == 'limit' && value = value.to_i
|
33
|
+
|
34
|
+
[name.to_sym, value]
|
35
|
+
end.to_h
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -43,6 +43,42 @@ module Lucid
|
|
43
43
|
# @return [String]
|
44
44
|
param :data
|
45
45
|
|
46
|
+
# @return [Hash]
|
47
|
+
param :link, default: -> { build_link }
|
48
|
+
|
49
|
+
# @return [Hash]
|
50
|
+
def build_link
|
51
|
+
Container[:parse_link_header].(headers['Link'])
|
52
|
+
end
|
53
|
+
|
54
|
+
# Request the next page of a GET request, if any.
|
55
|
+
#
|
56
|
+
# @param client [Client]
|
57
|
+
#
|
58
|
+
# @return [Response, nil]
|
59
|
+
def next(client: Container[:client], limit: nil)
|
60
|
+
return nil unless link[:next]
|
61
|
+
|
62
|
+
limit = limit ||
|
63
|
+
request.options.dig(:params, :limit) ||
|
64
|
+
link[:next][:limit]
|
65
|
+
client.get(request.credentials, request.path, {**link[:next], limit: limit})
|
66
|
+
end
|
67
|
+
|
68
|
+
# Request the previous page of a GET request, if any.
|
69
|
+
#
|
70
|
+
# @param client [Client]
|
71
|
+
#
|
72
|
+
# @return [Response, nil]
|
73
|
+
def previous(client: Container[:client], limit: nil)
|
74
|
+
return nil unless link[:previous]
|
75
|
+
|
76
|
+
limit = limit ||
|
77
|
+
request.options.dig(:params, :limit) ||
|
78
|
+
link[:previous][:limit]
|
79
|
+
client.get(request.credentials, request.path, {**link[:previous], limit: limit})
|
80
|
+
end
|
81
|
+
|
46
82
|
# The parsed response body.
|
47
83
|
#
|
48
84
|
# @return [Hash]
|
data/lib/lucid/shopify.rb
CHANGED
@@ -23,6 +23,7 @@ module Lucid
|
|
23
23
|
autoload :DeleteWebhook, 'lucid/shopify/delete_webhook'
|
24
24
|
autoload :Error, 'lucid/shopify/error'
|
25
25
|
autoload :GetRequest, 'lucid/shopify/get_request'
|
26
|
+
autoload :ParseLinkHeader, 'lucid/shopify/parse_link_header'
|
26
27
|
autoload :PostRequest, 'lucid/shopify/post_request'
|
27
28
|
autoload :PutRequest, 'lucid/shopify/put_request'
|
28
29
|
autoload :RedisThrottledStrategy, 'lucid/shopify/redis_throttled_strategy'
|
@@ -42,7 +43,7 @@ module Lucid
|
|
42
43
|
extend Dry::Configurable
|
43
44
|
|
44
45
|
setting :api_key
|
45
|
-
setting :api_version, '
|
46
|
+
setting :api_version, '2020-01'
|
46
47
|
setting :billing_callback_uri
|
47
48
|
setting :callback_uri
|
48
49
|
setting :logger, Logger.new(File::NULL).freeze
|
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.
|
4
|
+
version: 0.40.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: 2020-01-
|
11
|
+
date: 2020-01-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dotenv
|
@@ -158,6 +158,7 @@ files:
|
|
158
158
|
- lib/lucid/shopify/delete_webhook.rb
|
159
159
|
- lib/lucid/shopify/error.rb
|
160
160
|
- lib/lucid/shopify/get_request.rb
|
161
|
+
- lib/lucid/shopify/parse_link_header.rb
|
161
162
|
- lib/lucid/shopify/post_request.rb
|
162
163
|
- lib/lucid/shopify/put_request.rb
|
163
164
|
- lib/lucid/shopify/redis_throttled_strategy.rb
|