shoptet 0.0.9 → 0.0.14
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 +30 -6
- data/lib/shoptet/request.rb +11 -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: 289440d376a54ad0d925741b1964a1db28beb3f27ea7bfc667eccbc427458f2d
|
4
|
+
data.tar.gz: '09d1742a1b57c06acb939aa547aefdea76513905fd89679475438e3c2e515e65'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 366aa1983278c08fac3864f79e9b3322e5ac72e99a5beca1a3aea72926eb0facafb2cfc8018f46c7fe40459c197823c05c2c6e291231d8e48a41bcac254be199
|
7
|
+
data.tar.gz: 745cc481bb6fcc8711bc69b81242097da6a52c9afe0e31a499e5405fc5e8b08c3659e4a5154c151032f0050d18ee99ee8887c14c8316701045d0193289ea6d41
|
data/lib/shoptet.rb
CHANGED
@@ -8,6 +8,12 @@ class Shoptet
|
|
8
8
|
class AddonSuspended < StandardError; end
|
9
9
|
class AddonNotInstalled < StandardError; end
|
10
10
|
class InvalidTokenNoRights < StandardError; end
|
11
|
+
class EmptyRequestResponse < StandardError; end
|
12
|
+
class MaxPageReached < StandardError; end
|
13
|
+
|
14
|
+
EXPIRED_TOKEN_CODE = 'expired-token'
|
15
|
+
INVALID_TOKEN_CODE = 'invalid-token'
|
16
|
+
ADDON_NOT_INSTALLED = 'Addon installation is not approved.'
|
11
17
|
|
12
18
|
DEFAULT_ON_TOKEN_ERROR = -> (api) do
|
13
19
|
api.api_token = api.new_api_token
|
@@ -66,7 +72,7 @@ class Shoptet
|
|
66
72
|
end
|
67
73
|
|
68
74
|
def self.version
|
69
|
-
'0.0.
|
75
|
+
'0.0.14'
|
70
76
|
end
|
71
77
|
|
72
78
|
def self.ar_on_token_error(model)
|
@@ -150,12 +156,14 @@ class Shoptet
|
|
150
156
|
end
|
151
157
|
|
152
158
|
def shop_info api_params = {}
|
153
|
-
|
159
|
+
url = assemble_uri 'https://api.myshoptet.com/api/eshop', api_params
|
160
|
+
result = request url
|
154
161
|
result['data']
|
155
162
|
end
|
156
163
|
|
157
164
|
def design_info api_params = {}
|
158
|
-
|
165
|
+
url = assemble_uri 'https://api.myshoptet.com/api/eshop/design', api_params
|
166
|
+
result = request url
|
159
167
|
|
160
168
|
result['data']
|
161
169
|
end
|
@@ -245,6 +253,14 @@ class Shoptet
|
|
245
253
|
end
|
246
254
|
end
|
247
255
|
|
256
|
+
def suspended?
|
257
|
+
data = shop_info
|
258
|
+
|
259
|
+
false if data
|
260
|
+
rescue Shoptet::AddonSuspended
|
261
|
+
true
|
262
|
+
end
|
263
|
+
|
248
264
|
private
|
249
265
|
|
250
266
|
def enumerize base_url, filters = {}, data_key = nil
|
@@ -254,15 +270,23 @@ class Shoptet
|
|
254
270
|
def handle_errors result, uri, headers
|
255
271
|
error = result['error']
|
256
272
|
errors = result['errors'] || []
|
257
|
-
token_errors, non_token_errors = errors.partition
|
273
|
+
token_errors, non_token_errors = errors.partition do |err|
|
274
|
+
code = err['errorCode']
|
275
|
+
message = err['message']
|
276
|
+
|
277
|
+
code == EXPIRED_TOKEN_CODE ||
|
278
|
+
code == INVALID_TOKEN_CODE && message == "Invalid access token."
|
279
|
+
end
|
258
280
|
|
259
281
|
if error || non_token_errors.any?
|
260
|
-
if error == 'addon_suspended'
|
282
|
+
if error == 'addon_suspended' || errors.any? { |e| e["errorCode"] == INVALID_TOKEN_CODE && e['message'] == ADDON_NOT_INSTALLED }
|
261
283
|
raise AddonSuspended
|
262
|
-
elsif error == 'addon_not_installed'
|
284
|
+
elsif (error == 'addon_not_installed')
|
263
285
|
raise AddonNotInstalled
|
264
286
|
elsif errors.any? { |err| err["errorCode"] == 'invalid-token-no-rights' }
|
265
287
|
raise InvalidTokenNoRights
|
288
|
+
elsif errors.any? { |err| err["errorCode"] == 'page-not-found' && err['message'].include?('max page is') }
|
289
|
+
raise MaxPageReached
|
266
290
|
else
|
267
291
|
raise Error.new result
|
268
292
|
end
|
data/lib/shoptet/request.rb
CHANGED
@@ -21,10 +21,10 @@ class Shoptet
|
|
21
21
|
|
22
22
|
http = Net::HTTP.new parsed_uri.host, parsed_uri.port
|
23
23
|
http.use_ssl = true
|
24
|
-
http.open_timeout =
|
25
|
-
http.read_timeout =
|
26
|
-
http.write_timeout =
|
27
|
-
http.ssl_timeout =
|
24
|
+
http.open_timeout = 60
|
25
|
+
http.read_timeout = 60
|
26
|
+
http.write_timeout = 60
|
27
|
+
http.ssl_timeout = 60
|
28
28
|
|
29
29
|
request = Net::HTTP::Get.new parsed_uri
|
30
30
|
headers.each do |key, value|
|
@@ -32,8 +32,14 @@ class Shoptet
|
|
32
32
|
end
|
33
33
|
|
34
34
|
response = http.request request
|
35
|
+
parsed_body = JSON.parse response.body
|
35
36
|
|
36
|
-
|
37
|
+
unless parsed_body
|
38
|
+
message = "Status code: #{response.code}, url: #{uri}"
|
39
|
+
fail Shoptet::EmptyRequestResponse.new(message)
|
40
|
+
end
|
41
|
+
|
42
|
+
parsed_body
|
37
43
|
rescue Net::OpenTimeout
|
38
44
|
retry if attempt < 4
|
39
45
|
end
|
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.14
|
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-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: irb
|