lucid-shopify 0.50.2 → 0.51.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0bde6faec2cf0c1f3aebaa448053cfd08de85aaf84886fc4dfac7ee54c9b16d4
|
4
|
+
data.tar.gz: 9d88ca4bf4e318ecb84095c11e6ed4a7cf1466851a67bbbf9737f2be9c612040
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15792eae82caf1d7b9990a9c18c8ef4d38a5c1a42ce9b644e2628db014d38b9316fe6c3ecc007581a0c8022ba4e93c0763b1c1ddffc69a72e2a802da21966a34
|
7
|
+
data.tar.gz: 9b85663e3679692a27ad2022527f101a4ac00586f044b85c3e68fae3851425c6c20d29cfa9ebe6ea55f3b45055642ad845f024d8e59ea2d7df20dd7a350fe19d
|
data/lib/lucid/shopify.rb
CHANGED
@@ -24,9 +24,9 @@ module Lucid
|
|
24
24
|
autoload :DeleteWebhook, 'lucid/shopify/delete_webhook'
|
25
25
|
autoload :Error, 'lucid/shopify/error'
|
26
26
|
autoload :GetRequest, 'lucid/shopify/get_request'
|
27
|
+
autoload :GraphQLPostRequest, 'lucid/shopify/graphql_post_request'
|
27
28
|
autoload :ParseLinkHeader, 'lucid/shopify/parse_link_header'
|
28
29
|
autoload :PostRequest, 'lucid/shopify/post_request'
|
29
|
-
autoload :PostGraphQLRequest, 'lucid/shopify/post_graphql_request'
|
30
30
|
autoload :PutRequest, 'lucid/shopify/put_request'
|
31
31
|
autoload :RedisThrottledStrategy, 'lucid/shopify/redis_throttled_strategy'
|
32
32
|
autoload :Request, 'lucid/shopify/request'
|
data/lib/lucid/shopify/client.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'lucid/shopify/container'
|
4
4
|
|
5
|
-
%w[delete get post
|
5
|
+
%w[delete get post graphql_post put].each { |m| require "lucid/shopify/#{m}_request" }
|
6
6
|
|
7
7
|
module Lucid
|
8
8
|
module Shopify
|
@@ -77,9 +77,9 @@ module Lucid
|
|
77
77
|
send_request.(GetRequest.new(*args))
|
78
78
|
end
|
79
79
|
|
80
|
-
# @see
|
80
|
+
# @see GraphQLPostRequest#initialize
|
81
81
|
def post_graphql(*args)
|
82
|
-
send_request.(
|
82
|
+
send_request.(GraphQLPostRequest.new(*args))
|
83
83
|
end
|
84
84
|
|
85
85
|
# @see PostRequest#initialize
|
@@ -19,7 +19,7 @@ module Lucid
|
|
19
19
|
# @return [String]
|
20
20
|
def message
|
21
21
|
if response.errors?
|
22
|
-
"bad response (#{response.status_code})
|
22
|
+
"bad response (#{response.status_code}): #{response.error_messages.first}"
|
23
23
|
else
|
24
24
|
"bad response (#{response.status_code})"
|
25
25
|
end
|
@@ -30,6 +30,19 @@ module Lucid
|
|
30
30
|
ServerError = Class.new(Error)
|
31
31
|
ShopError = Class.new(Error)
|
32
32
|
|
33
|
+
class GraphQLClientError < ClientError
|
34
|
+
def message
|
35
|
+
case
|
36
|
+
when response.errors?
|
37
|
+
"bad response: #{response.error_messages.first}"
|
38
|
+
when response.user_errors?
|
39
|
+
"bad response: #{response.user_error_messages.first}"
|
40
|
+
else
|
41
|
+
"bad response"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
33
46
|
extend Dry::Initializer
|
34
47
|
|
35
48
|
include Enumerable
|
@@ -112,8 +125,8 @@ module Lucid
|
|
112
125
|
end
|
113
126
|
|
114
127
|
# GraphQL always has status 200.
|
115
|
-
if request.is_a?(
|
116
|
-
raise
|
128
|
+
if request.is_a?(GraphQLPostRequest) && (errors? || user_errors?)
|
129
|
+
raise GraphQLClientError.new(request, self)
|
117
130
|
end
|
118
131
|
|
119
132
|
self
|
@@ -131,15 +144,13 @@ module Lucid
|
|
131
144
|
|
132
145
|
# @return [Boolean]
|
133
146
|
def errors?
|
134
|
-
return true if user_errors?
|
135
|
-
|
136
147
|
data_hash.has_key?('errors') # should be only on 422
|
137
148
|
end
|
138
149
|
|
139
150
|
# GraphQL user errors.
|
140
151
|
#
|
141
152
|
# @return [Boolean]
|
142
|
-
|
153
|
+
def user_errors?
|
143
154
|
errors = find_user_errors
|
144
155
|
|
145
156
|
!errors.nil? && !errors.empty?
|
@@ -151,7 +162,7 @@ module Lucid
|
|
151
162
|
#
|
152
163
|
# @return [Array, nil]
|
153
164
|
private def find_user_errors(hash = data_hash)
|
154
|
-
return nil unless request.is_a?(
|
165
|
+
return nil unless request.is_a?(GraphQLPostRequest)
|
155
166
|
|
156
167
|
hash.each do |k, v|
|
157
168
|
return v if k == 'userErrors'
|
@@ -169,7 +180,7 @@ module Lucid
|
|
169
180
|
# @return [Hash]
|
170
181
|
def errors
|
171
182
|
errors = data_hash['errors']
|
172
|
-
|
183
|
+
case
|
173
184
|
when errors.nil?
|
174
185
|
{}
|
175
186
|
when errors.is_a?(String)
|
@@ -177,14 +188,12 @@ module Lucid
|
|
177
188
|
else
|
178
189
|
errors
|
179
190
|
end
|
180
|
-
|
181
|
-
errors.merge(user_errors)
|
182
191
|
end
|
183
192
|
|
184
193
|
# GraphQL user errors.
|
185
194
|
#
|
186
195
|
# @return [Hash]
|
187
|
-
|
196
|
+
def user_errors
|
188
197
|
errors = find_user_errors
|
189
198
|
return {} if errors.nil? || errors.empty?
|
190
199
|
errors.map do |error|
|
@@ -197,7 +206,16 @@ module Lucid
|
|
197
206
|
|
198
207
|
# @return [Array<String>]
|
199
208
|
def error_messages
|
200
|
-
errors.map
|
209
|
+
errors.map do |field, message|
|
210
|
+
"#{field} #{message}"
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
# @return [Array<String>]
|
215
|
+
def user_error_messages
|
216
|
+
user_errors.map do |field, message|
|
217
|
+
"#{message} [#{field}]"
|
218
|
+
end
|
201
219
|
end
|
202
220
|
|
203
221
|
# @param messages [Array<String>]
|
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.51.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-02-
|
11
|
+
date: 2020-02-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dotenv
|
@@ -159,8 +159,8 @@ files:
|
|
159
159
|
- lib/lucid/shopify/delete_webhook.rb
|
160
160
|
- lib/lucid/shopify/error.rb
|
161
161
|
- lib/lucid/shopify/get_request.rb
|
162
|
+
- lib/lucid/shopify/graphql_post_request.rb
|
162
163
|
- lib/lucid/shopify/parse_link_header.rb
|
163
|
-
- lib/lucid/shopify/post_graphql_request.rb
|
164
164
|
- lib/lucid/shopify/post_request.rb
|
165
165
|
- lib/lucid/shopify/put_request.rb
|
166
166
|
- lib/lucid/shopify/redis_throttled_strategy.rb
|