shoptet 0.0.34 → 0.0.35
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 +61 -8
- data/lib/shoptet/request.rb +28 -0
- 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: 834618535e5ec061b17899047e826cb4258cbcd1f162efba35dbd73201947eb8
|
4
|
+
data.tar.gz: 5b5cf393befc33bee8bf68f6352bb4a4e63d26b33c9d1d0fa5b3d01a02614340
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4478297d6958d02c4c647ed1b568b2da7748e774764625477179a029d04feacbd9ce80d3f6cc36d094b3ec2d2e511ce2281aec7658b15e5a0f4e21060a061b4
|
7
|
+
data.tar.gz: 52393d9a48043fac3485b4f99ca8b1c807987df18a50bf6abc9686b6ed850f1b24613e29c8beb5a2b20184bc3268c37ac9110f3102c95d161c356f4a5440c2ce
|
data/lib/shoptet.rb
CHANGED
@@ -25,7 +25,7 @@ class Shoptet
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def self.version
|
28
|
-
'0.0.
|
28
|
+
'0.0.35'
|
29
29
|
end
|
30
30
|
|
31
31
|
def self.ar_on_token_error(model)
|
@@ -113,12 +113,12 @@ class Shoptet
|
|
113
113
|
end
|
114
114
|
|
115
115
|
def shop_info api_params = {}
|
116
|
-
result =
|
116
|
+
result = get('https://api.myshoptet.com/api/eshop', api_params)
|
117
117
|
result['data']
|
118
118
|
end
|
119
119
|
|
120
120
|
def design_info api_params = {}
|
121
|
-
result =
|
121
|
+
result = get('https://api.myshoptet.com/api/eshop/design', api_params)
|
122
122
|
|
123
123
|
result['data']
|
124
124
|
end
|
@@ -165,17 +165,32 @@ class Shoptet
|
|
165
165
|
end
|
166
166
|
|
167
167
|
def order code, api_params = {}
|
168
|
-
result =
|
168
|
+
result = get("https://api.myshoptet.com/api/orders/#{code}", api_params)
|
169
169
|
result.dig('data', 'order')
|
170
170
|
end
|
171
171
|
|
172
172
|
def product guid, api_params = {}
|
173
|
-
result =
|
173
|
+
result = get("https://api.myshoptet.com/api/products/#{guid}", api_params)
|
174
174
|
result['data']
|
175
175
|
end
|
176
176
|
|
177
177
|
def product_by_code code, api_params = {}
|
178
|
-
result =
|
178
|
+
result = get("https://api.myshoptet.com/api/products/code/#{code}", api_params)
|
179
|
+
result['data']
|
180
|
+
end
|
181
|
+
|
182
|
+
def template_includes
|
183
|
+
result = get('https://api.myshoptet.com/api/template-include')
|
184
|
+
result['data']
|
185
|
+
end
|
186
|
+
|
187
|
+
def set_templates(data)
|
188
|
+
result = post_binary('https://api.myshoptet.com/api/template-include', data)
|
189
|
+
result['data']
|
190
|
+
end
|
191
|
+
|
192
|
+
def delete_template(location)
|
193
|
+
result = delete("https://api.myshoptet.com/api/template-include/#{location}")
|
179
194
|
result['data']
|
180
195
|
end
|
181
196
|
|
@@ -188,7 +203,7 @@ class Shoptet
|
|
188
203
|
result.fetch('access_token')
|
189
204
|
end
|
190
205
|
|
191
|
-
def
|
206
|
+
def get url, api_params = {}, retry_on_token_error = true
|
192
207
|
url = URI(url)
|
193
208
|
url.query = URI.encode_www_form(api_params) if api_params.any?
|
194
209
|
|
@@ -201,7 +216,45 @@ class Shoptet
|
|
201
216
|
if token_errors.any?
|
202
217
|
if retry_on_token_error
|
203
218
|
@on_token_error.call(self)
|
204
|
-
|
219
|
+
get(url, api_params, false)
|
220
|
+
else
|
221
|
+
raise Error.new(result)
|
222
|
+
end
|
223
|
+
else
|
224
|
+
result
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
def post_binary(url, data, retry_on_token_error = true)
|
229
|
+
url = URI(url)
|
230
|
+
headers = { 'Shoptet-Access-Token' => @api_token,
|
231
|
+
'Content-Type' => 'application/vnd.shoptet.v1.0' }
|
232
|
+
result = Shoptet::Request.post_binary(url, data, headers)
|
233
|
+
token_errors = handle_errors(result)
|
234
|
+
|
235
|
+
if token_errors.any?
|
236
|
+
if retry_on_token_error
|
237
|
+
@on_token_error.call(self)
|
238
|
+
post_binary(url, data, false)
|
239
|
+
else
|
240
|
+
raise Error.new(result)
|
241
|
+
end
|
242
|
+
else
|
243
|
+
result
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
def delete(url, retry_on_token_error = true)
|
248
|
+
url = URI(url)
|
249
|
+
headers = { 'Shoptet-Access-Token' => @api_token,
|
250
|
+
'Content-Type' => 'application/vnd.shoptet.v1.0' }
|
251
|
+
result = Shoptet::Request.delete(url, headers)
|
252
|
+
token_errors = handle_errors(result)
|
253
|
+
|
254
|
+
if token_errors.any?
|
255
|
+
if retry_on_token_error
|
256
|
+
@on_token_error.call(self)
|
257
|
+
delete(url, false)
|
205
258
|
else
|
206
259
|
raise Error.new(result)
|
207
260
|
end
|
data/lib/shoptet/request.rb
CHANGED
@@ -38,6 +38,34 @@ class Shoptet
|
|
38
38
|
JSON.parse(response.body)
|
39
39
|
end
|
40
40
|
|
41
|
+
def self.post_binary(url, body, headers)
|
42
|
+
request = Net::HTTP::Post.new(url)
|
43
|
+
request.body = body
|
44
|
+
request.content_type = 'appliaction/octet-stream'
|
45
|
+
headers.each do |key, value|
|
46
|
+
request[key] = value
|
47
|
+
end
|
48
|
+
|
49
|
+
response = Net::HTTP.start(url.host, url.port, use_ssl: true) do |http|
|
50
|
+
handle_net_timeouts { http.request(request) }
|
51
|
+
end
|
52
|
+
|
53
|
+
JSON.parse(response.body)
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.delete(url, headers)
|
57
|
+
request = Net::HTTP::Delete.new(url)
|
58
|
+
headers.each do |key, value|
|
59
|
+
request[key] = value
|
60
|
+
end
|
61
|
+
|
62
|
+
response = Net::HTTP.start(url.host, url.port, use_ssl: true) do |http|
|
63
|
+
handle_net_timeouts { http.request(request) }
|
64
|
+
end
|
65
|
+
|
66
|
+
JSON.parse(response.body)
|
67
|
+
end
|
68
|
+
|
41
69
|
private
|
42
70
|
|
43
71
|
def self.handle_net_timeouts
|
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.35
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Premysl Donat
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: irb
|