shoptet 0.0.48 → 0.0.50
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/request.rb +17 -0
- data/lib/shoptet.rb +29 -1
- 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: e950945e05fb23d88082c56b466624842bcef6ea73cfe7c6361869c3eff56f12
|
4
|
+
data.tar.gz: eddb00b718bf01161700e9cb0cdd55e0cecea5f9c4ac6e5dd4bb7d3cd258ff38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77d6ae85a1959efc9f569112f69b3b5f4af5bff2e2a2f75f63f7c00293721908e0312b2a8c861d52a3c8160701df07fd27308ba99fd95fbca08f69190cefb713
|
7
|
+
data.tar.gz: 2f624576b2c244ba832c6bf176c23b6c9ad82c096a275c45dae0d6f863f89cc4e4a78d63cddd484c78010451f9b59b770b84b15b350dd73f05bc7c0b918fecb0
|
data/lib/shoptet/request.rb
CHANGED
@@ -56,6 +56,23 @@ class Shoptet
|
|
56
56
|
JSON.parse(response.body)
|
57
57
|
end
|
58
58
|
|
59
|
+
def self.patch(url, body, headers)
|
60
|
+
request = Net::HTTP::Patch.new(url)
|
61
|
+
request.body = body.to_json
|
62
|
+
headers.each do |key, value|
|
63
|
+
request[key] = value
|
64
|
+
end
|
65
|
+
|
66
|
+
response = Net::HTTP.start(url.host, url.port, use_ssl: true) do |http|
|
67
|
+
handle_connection_errors { http.request(request) }
|
68
|
+
end
|
69
|
+
|
70
|
+
JSON.parse(response.body)
|
71
|
+
rescue JSON::ParserError => e
|
72
|
+
message = "Original message: #{e.message}, response body: #{response.body}, code :#{response.code}, headers: #{response.to_hash.to_s}"
|
73
|
+
fail Shoptet::NonJSONResponse.new(message)
|
74
|
+
end
|
75
|
+
|
59
76
|
def self.delete(url, headers)
|
60
77
|
request = Net::HTTP::Delete.new(url)
|
61
78
|
headers.each do |key, value|
|
data/lib/shoptet.rb
CHANGED
@@ -28,7 +28,7 @@ class Shoptet
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def self.version
|
31
|
-
'0.0.
|
31
|
+
'0.0.50'
|
32
32
|
end
|
33
33
|
|
34
34
|
def self.ar_on_token_error(model)
|
@@ -205,6 +205,15 @@ class Shoptet
|
|
205
205
|
result['data']['article']
|
206
206
|
end
|
207
207
|
|
208
|
+
def update_article(id, api_params = {})
|
209
|
+
result = patch("https://api.myshoptet.com/api/articles/#{id}", api_params)
|
210
|
+
result['data']['article']
|
211
|
+
end
|
212
|
+
|
213
|
+
def article_sections(api_params = {})
|
214
|
+
enumerize("https://api.myshoptet.com/api/articles/sections", api_params)
|
215
|
+
end
|
216
|
+
|
208
217
|
def new_api_token
|
209
218
|
headers = { 'Authorization' => "Bearer #{@oauth_token}" }
|
210
219
|
|
@@ -236,6 +245,25 @@ class Shoptet
|
|
236
245
|
end
|
237
246
|
end
|
238
247
|
|
248
|
+
def patch(url, data, retry_on_token_error = true)
|
249
|
+
url = URI(url)
|
250
|
+
headers = { 'Shoptet-Access-Token' => @api_token,
|
251
|
+
'Content-Type' => 'application/vnd.shoptet.v1.0' }
|
252
|
+
result = Shoptet::Request.patch(url, data, headers)
|
253
|
+
token_errors = handle_errors(result)
|
254
|
+
|
255
|
+
if token_errors.any?
|
256
|
+
if retry_on_token_error
|
257
|
+
@on_token_error.call(self)
|
258
|
+
patch(url, data, false)
|
259
|
+
else
|
260
|
+
raise Error.new(result)
|
261
|
+
end
|
262
|
+
else
|
263
|
+
result
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
239
267
|
def post_binary(url, data, retry_on_token_error = true)
|
240
268
|
url = URI(url)
|
241
269
|
headers = { 'Shoptet-Access-Token' => @api_token,
|
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.50
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Premysl Donat
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-08-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: irb
|