lucid-shopify 0.61.1 → 0.62.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: d59c069d078e6fa47fe962a4d5ad0f14a3c78f7b6a727c66d6dfae0097fad9ec
4
- data.tar.gz: 851bace61bdcaedaeb9b48270336caa77ebd13754118080b67d7c6bcad84ef05
3
+ metadata.gz: e66a0c2dcd13c2a44f4200675e90d3f90199fee2a199d6be48fb52ceaffab607
4
+ data.tar.gz: f9d500101e5a5cae6a1f6d5de0eac6a737d5e4b7f83127e353db267f68d0d01a
5
5
  SHA512:
6
- metadata.gz: 4d3a9ea60b994ca6e5ae84122955ddfcc47b189d8bad46378bea6133595d1ce24ae54f7add5240a183e24f0f8d3269623718f8b7b83f6b624bd4f0591f3b8d7d
7
- data.tar.gz: e5e04c7dd54caf988cfdeec9257f97ec0a9aa28e647d85c7882440233e182a837590b31d209c7fd59e58beb132bf9d3ce62de4862efb09d5aa8f1fd813d551c7
6
+ metadata.gz: b9ef5945b9bf554b1826b028ddca3492c106d0c661f1a4ab7c4286a0daddd6d583043c239fd71c6803b14a17c18e3449dd07f9493faed5bc0098d13da73139a1
7
+ data.tar.gz: 25b6dc870fff5fbc006f1654793e1ab4a35159956c7f5361584e16ecca8ce7664c8f1254c108a40178e8682a2e81b067132e59e7f688b5365956508aea87f05f
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'json'
4
4
  require 'lucid/shopify'
5
+ require 'timeout'
5
6
 
6
7
  module Lucid
7
8
  module Shopify
@@ -71,21 +72,48 @@ module Lucid
71
72
 
72
73
  # Cancel the bulk operation.
73
74
  def cancel
74
- client.post_graphql(credentials, <<~QUERY)
75
- mutation {
76
- bulkOperationCancel(id: "#{id}") {
77
- userErrors {
78
- field
79
- message
75
+ begin
76
+ client.post_graphql(credentials, <<~QUERY)
77
+ mutation {
78
+ bulkOperationCancel(id: "#{id}") {
79
+ userErrors {
80
+ field
81
+ message
82
+ }
80
83
  }
81
84
  }
82
- }
83
- QUERY
85
+ QUERY
86
+ rescue Response::GraphQLClientError => e
87
+ return if e.response.error_message?([
88
+ /cannot be canceled when it is completed/,
89
+ ])
90
+
91
+ raise e
92
+ end
84
93
 
85
- loop do
86
- status, _ = poll
94
+ poll_until(['CANCELED', 'COMPLETED'])
95
+ end
87
96
 
88
- break unless status == 'CANCELING'
97
+ # Poll until operation status is met.
98
+ #
99
+ # @param statuses [Array<Regexp, String>] to terminate polling on
100
+ # @param timeout [Integer] in seconds
101
+ #
102
+ # @raise Timeout::Error
103
+ def poll_until(statuses, timeout: 60)
104
+ Timeout.timeout(timeout) do
105
+ loop do
106
+ status, _ = poll
107
+
108
+ break if statuses.any? do |expected_status|
109
+ case expected_status
110
+ when Regexp
111
+ status.match?(expected_status)
112
+ when String
113
+ status == expected_status
114
+ end
115
+ end
116
+ end
89
117
  end
90
118
  end
91
119
 
@@ -155,7 +183,12 @@ module Lucid
155
183
  }
156
184
  QUERY
157
185
 
158
- Operation.new(client, credentials, op['id']).cancel if op && op['status'] == 'RUNNING'
186
+ case op&.fetch('status')
187
+ when 'CANCELING'
188
+ Operation.new(client, credentials, op['id']).poll_until(['CANCELED'])
189
+ when 'CREATED', 'RUNNING'
190
+ Operation.new(client, credentials, op['id']).cancel
191
+ end
159
192
 
160
193
  id = client.post_graphql(credentials, <<~QUERY)['data']['bulkOperationRunQuery']['bulkOperation']['id']
161
194
  mutation {
@@ -118,7 +118,7 @@ module Lucid
118
118
  raise ShopError.new(request, self), 'Shop is frozen, awaiting payment'
119
119
  when 403
120
120
  # NOTE: Not sure what this one means (undocumented).
121
- if data_hash['errors'] =~ /unavailable shop/i
121
+ if error_message?(/unavailable shop/i)
122
122
  raise ShopError.new(request, self), 'Shop is unavailable'
123
123
  else
124
124
  raise ClientError.new(request, self)
@@ -229,12 +229,14 @@ module Lucid
229
229
  #
230
230
  # @return [Boolean]
231
231
  def error_message?(messages)
232
+ all_messages = error_messages + user_error_messages
233
+
232
234
  messages.any? do |message|
233
235
  case message
234
236
  when Regexp
235
- error_messages.any? { |other_message| other_message.match?(message) }
237
+ all_messages.any? { |other_message| other_message.match?(message) }
236
238
  when String
237
- error_messages.include?(message)
239
+ all_messages.include?(message)
238
240
  end
239
241
  end
240
242
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Lucid
4
4
  module Shopify
5
- VERSION = '0.61.1'
5
+ VERSION = '0.62.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lucid-shopify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.61.1
4
+ version: 0.62.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kelsey Judson