shoptet 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -3
- data/lib/shoptet.rb +29 -34
- data/lib/shoptet/request.rb +11 -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: 6d9c548dd730e3b59fb8ae843dab0fdae19b4779c27042c0aa5f01bed576cc88
|
4
|
+
data.tar.gz: 610aee2527b42a799c771b172a1fa54b942b5d0823080f2f2761271ce8efd6dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 334fc975ad12a81db120372b3478369db2ed4c67df97e7bbc6cd62f2fe875e1f39f2366ee8f82330edd80e517eb592cf3962491d5328aeaf9cb67a72b3d41352
|
7
|
+
data.tar.gz: c627078af8708d7ad6beec828d1e19ff22e6e088042e1fd09d67c4ae86307e4e76093499e7041ac096d0326400157681121ffb5c8e5618f9de9299e824701ff1
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# Shoptet
|
2
2
|
|
3
|
-
This is Ruby API wrapper for [Shoptet API](https://
|
4
|
-
|
5
|
-
This is currently under development and hasn't been released to Rubygems yet.
|
3
|
+
This is Ruby API wrapper for [Shoptet API](https://shoptet.docs.apiary.io) which provides access to e-shop data for addon developers.
|
6
4
|
|
7
5
|
# How to install
|
8
6
|
|
@@ -82,6 +80,7 @@ Also they accept hash with params which will be passed to Shoptet api. Through t
|
|
82
80
|
## Other
|
83
81
|
|
84
82
|
* `Shoptet#new_api_token` - this returns new api token created with oauth token
|
83
|
+
* `Shoptet::install` - TODO
|
85
84
|
|
86
85
|
## License
|
87
86
|
|
data/lib/shoptet.rb
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
require_relative 'shoptet/request'
|
2
2
|
|
3
3
|
class Shoptet
|
4
|
-
class Error < StandardError
|
5
|
-
#TODO: check that this works
|
6
|
-
attr_reader :additional_data
|
7
|
-
|
8
|
-
def initialize message, additional_data = {}
|
9
|
-
super(message)
|
10
|
-
@additional_data = additional_data
|
11
|
-
end
|
12
|
-
end
|
4
|
+
class Error < StandardError; end
|
13
5
|
class AddonSuspended < StandardError; end
|
14
6
|
class AddonNotInstalled < StandardError; end
|
15
7
|
class InvalidTokenNoRights < StandardError; end
|
@@ -19,7 +11,7 @@ class Shoptet
|
|
19
11
|
end
|
20
12
|
|
21
13
|
def self.version
|
22
|
-
'0.0.
|
14
|
+
'0.0.6'
|
23
15
|
end
|
24
16
|
|
25
17
|
def self.ar_on_token_error(model)
|
@@ -39,6 +31,19 @@ class Shoptet
|
|
39
31
|
end
|
40
32
|
end
|
41
33
|
|
34
|
+
def self.install uri, redirect_uri, client_id, client_secret, code
|
35
|
+
data = {
|
36
|
+
'redirect_uri' => redirect_uri,
|
37
|
+
'client_id' => client_id,
|
38
|
+
'client_secret' => client_secret,
|
39
|
+
'code' => code,
|
40
|
+
'grant_type' => 'authorization_code',
|
41
|
+
'scope' => 'api'
|
42
|
+
}
|
43
|
+
|
44
|
+
Shoptet::Request.post uri, data
|
45
|
+
end
|
46
|
+
|
42
47
|
attr_accessor :api_token
|
43
48
|
|
44
49
|
def initialize(oauth_url, oauth_token, api_token = nil, on_token_error = nil)
|
@@ -50,14 +55,17 @@ class Shoptet
|
|
50
55
|
|
51
56
|
#TODO: return ['data'] already
|
52
57
|
def shop_info api_params = {}
|
53
|
-
request 'https://api.myshoptet.com/api/eshop'
|
58
|
+
result = request 'https://api.myshoptet.com/api/eshop'
|
59
|
+
result['data']
|
54
60
|
end
|
55
61
|
|
56
62
|
def design_info api_params = {}
|
57
|
-
request 'https://api.myshoptet.com/api/eshop/design'
|
63
|
+
result = request 'https://api.myshoptet.com/api/eshop/design'
|
64
|
+
|
65
|
+
result['data']
|
58
66
|
end
|
59
67
|
|
60
|
-
def
|
68
|
+
def stocks api_params = {}
|
61
69
|
enumerize 'https://api.myshoptet.com/api/stocks', api_params
|
62
70
|
end
|
63
71
|
|
@@ -70,6 +78,11 @@ class Shoptet
|
|
70
78
|
enumerize uri, api_params
|
71
79
|
end
|
72
80
|
|
81
|
+
def stocks_movements warehouse_id, api_params = {}
|
82
|
+
uri = "https://api.myshoptet.com/api/stocks/#{warehouse_id}/movements"
|
83
|
+
enumerize uri, api_params
|
84
|
+
end
|
85
|
+
|
73
86
|
def product_categories api_params = {}
|
74
87
|
enumerize 'https://api.myshoptet.com/api/categories', api_params
|
75
88
|
end
|
@@ -100,13 +113,13 @@ class Shoptet
|
|
100
113
|
def order code, api_params = {}
|
101
114
|
uri = "https://api.myshoptet.com/api/orders/#{code}"
|
102
115
|
result = request assemble_uri(uri, api_params)
|
103
|
-
result.dig
|
116
|
+
result.dig 'data', 'order'
|
104
117
|
end
|
105
118
|
|
106
119
|
def product guid, api_params = {}
|
107
120
|
uri = "https://api.myshoptet.com/api/products/#{guid}"
|
108
121
|
result = request assemble_uri(uri, api_params)
|
109
|
-
result
|
122
|
+
result['data']
|
110
123
|
end
|
111
124
|
|
112
125
|
def new_api_token
|
@@ -179,28 +192,10 @@ class Shoptet
|
|
179
192
|
elsif errors.any? { |err| err["errorCode"] == 'invalid-token-no-rights' }
|
180
193
|
raise InvalidTokenNoRights
|
181
194
|
else
|
182
|
-
|
183
|
-
uri: uri,
|
184
|
-
headers: scrub_sensitive_headers(headers)
|
185
|
-
}
|
186
|
-
|
187
|
-
raise Error.new result, additional_data
|
195
|
+
raise Error.new result
|
188
196
|
end
|
189
197
|
end
|
190
198
|
|
191
199
|
token_errors
|
192
200
|
end
|
193
|
-
|
194
|
-
def scrub_sensitive_headers headers
|
195
|
-
scrubbed = {}
|
196
|
-
|
197
|
-
to_scrub = ['Shoptet-Access-Token', 'Authorization']
|
198
|
-
to_scrub.each do |header|
|
199
|
-
if headers[header]
|
200
|
-
scrubbed[header] = "#{headers[header][0..20]}..."
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
headers.merge scrubbed
|
205
|
-
end
|
206
201
|
end
|
data/lib/shoptet/request.rb
CHANGED
@@ -28,5 +28,16 @@ class Shoptet
|
|
28
28
|
rescue Net::OpenTimeout
|
29
29
|
retry if attempt < 4
|
30
30
|
end
|
31
|
+
|
32
|
+
def self.post uri, body
|
33
|
+
req = Net::HTTP::Post.new uri
|
34
|
+
req.set_form_data body
|
35
|
+
|
36
|
+
res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
|
37
|
+
http.request req
|
38
|
+
end
|
39
|
+
|
40
|
+
JSON.parse res.body
|
41
|
+
end
|
31
42
|
end
|
32
43
|
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.6
|
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-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: irb
|