shoptet 0.0.13 → 0.0.18
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 +4 -4
- data/lib/shoptet.rb +23 -4
- data/lib/shoptet/request.rb +5 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e027e9838f1031078700fefa9208685301227a87998272534abab291b6592cc
|
4
|
+
data.tar.gz: b54940690e5ac0eeccce25a6d5cc44e8537eb934468e08334ae07393449bc28f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b432895ea1a1d8214531bb0097fcf036cd8f12016069410ae1cb04e4707420f117f59006245eeec87fe194cf8254b4f05dc0d96add6eddcf872a58d788f5f4c
|
7
|
+
data.tar.gz: e4a97e102621cc21658d07152d1a75c94b68807457edaf9eafb9da39323f924fef2f748236cba221cc0f0ed5307ec166f9a928ffb169e67043f8b0bf5e7188d9
|
data/lib/shoptet.rb
CHANGED
@@ -10,6 +10,11 @@ class Shoptet
|
|
10
10
|
class InvalidTokenNoRights < StandardError; end
|
11
11
|
class EmptyRequestResponse < StandardError; end
|
12
12
|
class MaxPageReached < StandardError; end
|
13
|
+
class UnsuccessfulApiResponse < StandardError; end
|
14
|
+
|
15
|
+
EXPIRED_TOKEN_CODE = 'expired-token'
|
16
|
+
INVALID_TOKEN_CODE = 'invalid-token'
|
17
|
+
ADDON_NOT_INSTALLED = 'Addon installation is not approved.'
|
13
18
|
|
14
19
|
DEFAULT_ON_TOKEN_ERROR = -> (api) do
|
15
20
|
api.api_token = api.new_api_token
|
@@ -68,7 +73,7 @@ class Shoptet
|
|
68
73
|
end
|
69
74
|
|
70
75
|
def self.version
|
71
|
-
'0.0.
|
76
|
+
'0.0.18'
|
72
77
|
end
|
73
78
|
|
74
79
|
def self.ar_on_token_error(model)
|
@@ -249,6 +254,14 @@ class Shoptet
|
|
249
254
|
end
|
250
255
|
end
|
251
256
|
|
257
|
+
def suspended?
|
258
|
+
data = shop_info
|
259
|
+
|
260
|
+
false if data
|
261
|
+
rescue Shoptet::AddonSuspended
|
262
|
+
true
|
263
|
+
end
|
264
|
+
|
252
265
|
private
|
253
266
|
|
254
267
|
def enumerize base_url, filters = {}, data_key = nil
|
@@ -258,12 +271,18 @@ class Shoptet
|
|
258
271
|
def handle_errors result, uri, headers
|
259
272
|
error = result['error']
|
260
273
|
errors = result['errors'] || []
|
261
|
-
token_errors, non_token_errors = errors.partition
|
274
|
+
token_errors, non_token_errors = errors.partition do |err|
|
275
|
+
code = err['errorCode']
|
276
|
+
message = err['message']
|
277
|
+
|
278
|
+
code == EXPIRED_TOKEN_CODE ||
|
279
|
+
code == INVALID_TOKEN_CODE && (message.include?('Invalid access token') || message.include?('Missing access token'))
|
280
|
+
end
|
262
281
|
|
263
282
|
if error || non_token_errors.any?
|
264
|
-
if error == 'addon_suspended'
|
283
|
+
if error == 'addon_suspended' || errors.any? { |e| e["errorCode"] == INVALID_TOKEN_CODE && e['message'] == ADDON_NOT_INSTALLED }
|
265
284
|
raise AddonSuspended
|
266
|
-
elsif error == 'addon_not_installed'
|
285
|
+
elsif (error == 'addon_not_installed')
|
267
286
|
raise AddonNotInstalled
|
268
287
|
elsif errors.any? { |err| err["errorCode"] == 'invalid-token-no-rights' }
|
269
288
|
raise InvalidTokenNoRights
|
data/lib/shoptet/request.rb
CHANGED
@@ -14,9 +14,6 @@ class Shoptet
|
|
14
14
|
|
15
15
|
class Request
|
16
16
|
def self.get uri, headers
|
17
|
-
attempt ||= 0
|
18
|
-
attempt += 1
|
19
|
-
|
20
17
|
parsed_uri = URI(uri)
|
21
18
|
|
22
19
|
http = Net::HTTP.new parsed_uri.host, parsed_uri.port
|
@@ -39,9 +36,12 @@ class Shoptet
|
|
39
36
|
fail Shoptet::EmptyRequestResponse.new(message)
|
40
37
|
end
|
41
38
|
|
39
|
+
unless response.code == '200'
|
40
|
+
message = "Status code: #{response.code}, url: #{uri}"
|
41
|
+
fail Shoptet::UnsuccessfulApiResponse.new(message)
|
42
|
+
end
|
43
|
+
|
42
44
|
parsed_body
|
43
|
-
rescue Net::OpenTimeout
|
44
|
-
retry if attempt < 4
|
45
45
|
end
|
46
46
|
|
47
47
|
def self.post uri, body
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shoptet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Premysl Donat
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-11-
|
11
|
+
date: 2020-11-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: irb
|