shoptet 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/shoptet.rb +14 -7
- 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: 682cc8f11ec548207514c501fb63e2c18ea8f9cb3a7ff4eb6db35b458b75b022
|
4
|
+
data.tar.gz: ec70519cd497dd8a49e9c72ee1940ec084fa0a2203889de3292febb658885c1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ce582d9fdbac257cffd92e2b9cb60ac718141af95a2a744ad27605c35c883bbd82f9838deb9b1fde57802a37740f49309ac034b541b19ad2557e41b09ca0bbc
|
7
|
+
data.tar.gz: 0bc005b177781df29dd9c7b0471d317ed108529b717455bd70a88bbb3ccbdc8b303bbd1ff21e9c2e7cb834a969876de547eecd86d17cddf32a80cfa473fe297a
|
data/lib/shoptet.rb
CHANGED
@@ -11,13 +11,14 @@ class Shoptet
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
class AddonSuspended < StandardError; end
|
14
|
+
class AddonNotInstalled < StandardError; end
|
14
15
|
|
15
16
|
DEFAULT_ON_TOKEN_ERROR = -> (api) do
|
16
17
|
api.api_token = api.new_api_token
|
17
18
|
end
|
18
19
|
|
19
20
|
def self.version
|
20
|
-
'0.0.
|
21
|
+
'0.0.3'
|
21
22
|
end
|
22
23
|
|
23
24
|
def self.ar_on_token_error(model)
|
@@ -106,7 +107,7 @@ class Shoptet
|
|
106
107
|
headers = { 'Authorization' => "Bearer #{@oauth_token}" }
|
107
108
|
|
108
109
|
result = Shoptet::Request.get @oauth_url, headers
|
109
|
-
handle_errors result, @oauth_url
|
110
|
+
handle_errors result, @oauth_url, headers
|
110
111
|
|
111
112
|
result.fetch 'access_token'
|
112
113
|
end
|
@@ -140,22 +141,26 @@ class Shoptet
|
|
140
141
|
end
|
141
142
|
end
|
142
143
|
|
143
|
-
def request uri
|
144
|
+
def request uri, retry_on_token_error = true
|
144
145
|
headers = { 'Shoptet-Access-Token' => @api_token,
|
145
146
|
'Content-Type' => 'application/vnd.shoptet.v1.0' }
|
146
147
|
|
147
148
|
result = Shoptet::Request.get uri, headers
|
148
|
-
token_errors = handle_errors result, uri
|
149
|
+
token_errors = handle_errors result, uri, headers
|
149
150
|
|
150
151
|
if token_errors.any?
|
151
|
-
|
152
|
-
|
152
|
+
if retry_on_token_error
|
153
|
+
@on_token_error.call self
|
154
|
+
request uri, false
|
155
|
+
else
|
156
|
+
raise Error.new result
|
157
|
+
end
|
153
158
|
else
|
154
159
|
result
|
155
160
|
end
|
156
161
|
end
|
157
162
|
|
158
|
-
def handle_errors result, uri
|
163
|
+
def handle_errors result, uri, headers
|
159
164
|
error = result['error']
|
160
165
|
errors = result['errors'] || []
|
161
166
|
token_errors, non_token_errors = errors.partition { |err| ['invalid-token', 'expired-token'].include? err['errorCode'] }
|
@@ -163,6 +168,8 @@ class Shoptet
|
|
163
168
|
if error || non_token_errors.any?
|
164
169
|
if error == 'addon_suspended'
|
165
170
|
raise AddonSuspended
|
171
|
+
elsif error == 'addon_not_installed'
|
172
|
+
raise AddonNotInstalled
|
166
173
|
else
|
167
174
|
additional_data = {
|
168
175
|
uri: uri,
|
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.3
|
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-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: irb
|