hubrise_client 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +1 -0
- data/Rakefile +10 -0
- data/V1_ENDPOINTS.md +256 -0
- data/lib/hubrise_client.rb +16 -0
- data/lib/hubrise_client/base.rb +96 -0
- data/lib/hubrise_client/request.rb +65 -0
- data/lib/hubrise_client/response.rb +35 -0
- data/lib/hubrise_client/v1.rb +181 -0
- data/lib/hubrise_client/version.rb +3 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9d13b21870a62cf2806b60260400ca941bd7df8893fedcc34f5ce442ce9ad489
|
4
|
+
data.tar.gz: b761dba1b9b3894fbdd7bc560e770cbf33cdea19fc76d9ec3817ab56772d0e05
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3da0fbcc970d4c14f64dad2b56c70b9966d38adacee775a782add770acf9fa7b93bec7a25bac1fa2a86a5988221c786154dec41807f2495d2df3d5941b8d86f3
|
7
|
+
data.tar.gz: e61453b95a35b4c3f09f20bafbf7b6ec87cc41fbbfb7be96c527b510a1454a7bffed71c75a2382b55fd323e4357ace837a850331bb92457abcfaf8aade3780eb
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT LICENSE
|
2
|
+
|
3
|
+
Copyright (c) nsave <nick.saveljev@gmail.com>
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# hubrise_ruby_lib
|
data/Rakefile
ADDED
data/V1_ENDPOINTS.md
ADDED
@@ -0,0 +1,256 @@
|
|
1
|
+
### GET_ACCOUNT
|
2
|
+
- Initialized with `client_attrs = {:access_token=>"access_token1"}`
|
3
|
+
```
|
4
|
+
Hubrise::APIClients::V1.new(client_attrs).get_account("zrn61")
|
5
|
+
// => [GET] /accounts/zrn61 with {:headers=>{"X-Access-Token"=>"access_token1"}}
|
6
|
+
```
|
7
|
+
- Initialized with `client_attrs = {:access_token=>"access_token1"}`
|
8
|
+
```
|
9
|
+
Hubrise::APIClients::V1.new(client_attrs).get_account()
|
10
|
+
// => [GET] /account with {:headers=>{"X-Access-Token"=>"access_token1"}}
|
11
|
+
```
|
12
|
+
### GET_ACCOUNTS
|
13
|
+
- Initialized with `client_attrs = {:access_token=>"access_token1"}`
|
14
|
+
```
|
15
|
+
Hubrise::APIClients::V1.new(client_attrs).get_accounts()
|
16
|
+
// => [GET] /accounts with {:headers=>{"X-Access-Token"=>"access_token1"}}
|
17
|
+
```
|
18
|
+
### GET_USER
|
19
|
+
- Initialized with `client_attrs = {:access_token=>"access_token1"}`
|
20
|
+
```
|
21
|
+
Hubrise::APIClients::V1.new(client_attrs).get_user()
|
22
|
+
// => [GET] /user with {:headers=>{"X-Access-Token"=>"access_token1"}}
|
23
|
+
```
|
24
|
+
### GET_LOCATIONS
|
25
|
+
- Initialized with `client_attrs = {:access_token=>"access_token1"}`
|
26
|
+
```
|
27
|
+
Hubrise::APIClients::V1.new(client_attrs).get_locations()
|
28
|
+
// => [GET] /locations with {:headers=>{"X-Access-Token"=>"access_token1"}}
|
29
|
+
```
|
30
|
+
### GET_LOCATION
|
31
|
+
- Initialized with `client_attrs = {:access_token=>"access_token1"}`
|
32
|
+
```
|
33
|
+
Hubrise::APIClients::V1.new(client_attrs).get_location("zrn61")
|
34
|
+
// => [GET] /locations/zrn61 with {:headers=>{"X-Access-Token"=>"access_token1"}}
|
35
|
+
```
|
36
|
+
- Initialized with `client_attrs = {:access_token=>"access_token1"}`
|
37
|
+
```
|
38
|
+
Hubrise::APIClients::V1.new(client_attrs).get_location()
|
39
|
+
// => [GET] /location with {:headers=>{"X-Access-Token"=>"access_token1"}}
|
40
|
+
```
|
41
|
+
### GET_ORDERS
|
42
|
+
- Initialized with `client_attrs = {:access_token=>"access_token1"}`
|
43
|
+
```
|
44
|
+
Hubrise::APIClients::V1.new(client_attrs).get_orders("zrn61", {:status=>"new"})
|
45
|
+
// => [GET] /locations/zrn61/orders?status=new with {:headers=>{"X-Access-Token"=>"access_token1"}}
|
46
|
+
```
|
47
|
+
### GET_ORDER
|
48
|
+
- Initialized with `client_attrs = {:access_token=>"access_token1"}`
|
49
|
+
```
|
50
|
+
Hubrise::APIClients::V1.new(client_attrs).get_order("zrn61", "wy3xz")
|
51
|
+
// => [GET] /locations/zrn61/orders/wy3xz with {:headers=>{"X-Access-Token"=>"access_token1"}}
|
52
|
+
```
|
53
|
+
### CREATE_ORDER
|
54
|
+
- Initialized with `client_attrs = {:access_token=>"access_token1"}`
|
55
|
+
```
|
56
|
+
Hubrise::APIClients::V1.new(client_attrs).create_order("zrn61", {:status=>"new"})
|
57
|
+
// => [POST] /locations/zrn61/orders with {:headers=>{"Content-Type"=>"application/json"}, :body=>"{\"status\":\"new\"}"}
|
58
|
+
```
|
59
|
+
### UPDATE_ORDER
|
60
|
+
- Initialized with `client_attrs = {:access_token=>"access_token1"}`
|
61
|
+
```
|
62
|
+
Hubrise::APIClients::V1.new(client_attrs).update_order("zrn61", "wy3xz", {:status=>"delivered"})
|
63
|
+
// => [PUT] /locations/zrn61/orders/wy3xz with {:headers=>{"Content-Type"=>"application/json"}, :body=>"{\"status\":\"delivered\"}"}
|
64
|
+
```
|
65
|
+
### GET_CALLBACK
|
66
|
+
- Initialized with `client_attrs = {:access_token=>"access_token1"}`
|
67
|
+
```
|
68
|
+
Hubrise::APIClients::V1.new(client_attrs).get_callback()
|
69
|
+
// => [GET] /callback with {:headers=>{"X-Access-Token"=>"access_token1"}}
|
70
|
+
```
|
71
|
+
### GET_CALLBACK_EVENTS
|
72
|
+
- Initialized with `client_attrs = {:access_token=>"access_token1"}`
|
73
|
+
```
|
74
|
+
Hubrise::APIClients::V1.new(client_attrs).get_callback_events()
|
75
|
+
// => [GET] /callback/events with {:headers=>{"X-Access-Token"=>"access_token1"}}
|
76
|
+
```
|
77
|
+
### DELETE_EVENT
|
78
|
+
- Initialized with `client_attrs = {:access_token=>"access_token1"}`
|
79
|
+
```
|
80
|
+
Hubrise::APIClients::V1.new(client_attrs).delete_event("zrn61")
|
81
|
+
// => [DELETE] /callback/events/zrn61 with {:headers=>{"X-Access-Token"=>"access_token1"}}
|
82
|
+
```
|
83
|
+
### UPDATE_CALLBACK
|
84
|
+
- Initialized with `client_attrs = {:access_token=>"access_token1"}`
|
85
|
+
```
|
86
|
+
Hubrise::APIClients::V1.new(client_attrs).update_callback({"order"=>["create"]})
|
87
|
+
// => [POST] /callback with {:headers=>{"Content-Type"=>"application/json"}, :body=>"{\"order\":[\"create\"]}"}
|
88
|
+
```
|
89
|
+
### DELETE_CALLBACK
|
90
|
+
- Initialized with `client_attrs = {:access_token=>"access_token1"}`
|
91
|
+
```
|
92
|
+
Hubrise::APIClients::V1.new(client_attrs).delete_callback()
|
93
|
+
// => [DELETE] /callback with {:headers=>{"X-Access-Token"=>"access_token1"}}
|
94
|
+
```
|
95
|
+
### GET_LOCATION_CUSTOMER_LISTS
|
96
|
+
- Initialized with `client_attrs = {:access_token=>"access_token1"}`
|
97
|
+
```
|
98
|
+
Hubrise::APIClients::V1.new(client_attrs).get_location_customer_lists("zrn61")
|
99
|
+
// => [GET] /locations/zrn61/customer_lists with {:headers=>{"X-Access-Token"=>"access_token1"}}
|
100
|
+
```
|
101
|
+
### GET_ACCOUNT_CUSTOMER_LISTS
|
102
|
+
- Initialized with `client_attrs = {:access_token=>"access_token1"}`
|
103
|
+
```
|
104
|
+
Hubrise::APIClients::V1.new(client_attrs).get_account_customer_lists("zrn61")
|
105
|
+
// => [GET] /accounts/zrn61/customer_lists with {:headers=>{"X-Access-Token"=>"access_token1"}}
|
106
|
+
```
|
107
|
+
### GET_CUSTOMER_LIST
|
108
|
+
- Initialized with `client_attrs = {:access_token=>"access_token1"}`
|
109
|
+
```
|
110
|
+
Hubrise::APIClients::V1.new(client_attrs).get_customer_list("zrn61")
|
111
|
+
// => [GET] /customer_lists/zrn61 with {:headers=>{"X-Access-Token"=>"access_token1"}}
|
112
|
+
```
|
113
|
+
- Initialized with `client_attrs = {:access_token=>"access_token1", :customer_list_id=>"wy3xz"}`
|
114
|
+
```
|
115
|
+
Hubrise::APIClients::V1.new(client_attrs).get_customer_list()
|
116
|
+
// => [GET] /customer_lists/wy3xz with {:headers=>{"X-Access-Token"=>"access_token1"}}
|
117
|
+
```
|
118
|
+
### GET_ALL_CUSTOMERS
|
119
|
+
- Initialized with `client_attrs = {:access_token=>"access_token1"}`
|
120
|
+
```
|
121
|
+
Hubrise::APIClients::V1.new(client_attrs).get_all_customers("zrn61")
|
122
|
+
// => [GET] /customer_lists/zrn61/customers with {:headers=>{"X-Access-Token"=>"access_token1"}}
|
123
|
+
```
|
124
|
+
- Initialized with `client_attrs = {:access_token=>"access_token1", :customer_list_id=>"wy3xz"}`
|
125
|
+
```
|
126
|
+
Hubrise::APIClients::V1.new(client_attrs).get_all_customers()
|
127
|
+
// => [GET] /customer_lists/wy3xz/customers with {:headers=>{"X-Access-Token"=>"access_token1"}}
|
128
|
+
```
|
129
|
+
### SEARCH_CUSTOMERS
|
130
|
+
- Initialized with `client_attrs = {:access_token=>"access_token1", :customer_list_id=>"zrn61"}`
|
131
|
+
```
|
132
|
+
Hubrise::APIClients::V1.new(client_attrs).search_customers({:email=>"nsave@*"})
|
133
|
+
// => [GET] /customer_lists/zrn61/customers?email=nsave@* with {:headers=>{"X-Access-Token"=>"access_token1"}}
|
134
|
+
```
|
135
|
+
- Initialized with `client_attrs = {:access_token=>"access_token1"}`
|
136
|
+
```
|
137
|
+
Hubrise::APIClients::V1.new(client_attrs).search_customers({:email=>"nsave@*"}, "wy3xz")
|
138
|
+
// => [GET] /customer_lists/wy3xz/customers?email=nsave@* with {:headers=>{"X-Access-Token"=>"access_token1"}}
|
139
|
+
```
|
140
|
+
### GET_CUSTOMER
|
141
|
+
- Initialized with `client_attrs = {:access_token=>"access_token1", :customer_list_id=>"zrn61"}`
|
142
|
+
```
|
143
|
+
Hubrise::APIClients::V1.new(client_attrs).get_customer("zrk6b")
|
144
|
+
// => [GET] /customer_lists/zrn61/customers/zrk6b with {:headers=>{"X-Access-Token"=>"access_token1"}}
|
145
|
+
```
|
146
|
+
- Initialized with `client_attrs = {:access_token=>"access_token1"}`
|
147
|
+
```
|
148
|
+
Hubrise::APIClients::V1.new(client_attrs).get_customer("zrk6b", "wy3xz")
|
149
|
+
// => [GET] /customer_lists/wy3xz/customers/zrk6b with {:headers=>{"X-Access-Token"=>"access_token1"}}
|
150
|
+
```
|
151
|
+
### CREATE_CUSTOMER
|
152
|
+
- Initialized with `client_attrs = {:access_token=>"access_token1", :customer_list_id=>"zrn61"}`
|
153
|
+
```
|
154
|
+
Hubrise::APIClients::V1.new(client_attrs).create_customer({:first_name=>"nsave"})
|
155
|
+
// => [POST] /customer_lists/zrn61/customers with {:headers=>{"Content-Type"=>"application/json"}, :body=>"{\"first_name\":\"nsave\"}"}
|
156
|
+
```
|
157
|
+
- Initialized with `client_attrs = {:access_token=>"access_token1"}`
|
158
|
+
```
|
159
|
+
Hubrise::APIClients::V1.new(client_attrs).create_customer({:first_name=>"nsave"}, "wy3xz")
|
160
|
+
// => [POST] /customer_lists/wy3xz/customers with {:headers=>{"Content-Type"=>"application/json"}, :body=>"{\"first_name\":\"nsave\"}"}
|
161
|
+
```
|
162
|
+
### UPDATE_CUSTOMER
|
163
|
+
- Initialized with `client_attrs = {:access_token=>"access_token1", :customer_list_id=>"zrn61"}`
|
164
|
+
```
|
165
|
+
Hubrise::APIClients::V1.new(client_attrs).update_customer("zrk6b", {:first_name=>"nsave"})
|
166
|
+
// => [PUT] /customer_lists/zrn61/customers/zrk6b with {:headers=>{"Content-Type"=>"application/json"}, :body=>"{\"first_name\":\"nsave\"}"}
|
167
|
+
```
|
168
|
+
- Initialized with `client_attrs = {:access_token=>"access_token1"}`
|
169
|
+
```
|
170
|
+
Hubrise::APIClients::V1.new(client_attrs).update_customer("zrk6b", {:first_name=>"nsave"}, "wy3xz")
|
171
|
+
// => [PUT] /customer_lists/wy3xz/customers/zrk6b with {:headers=>{"Content-Type"=>"application/json"}, :body=>"{\"first_name\":\"nsave\"}"}
|
172
|
+
```
|
173
|
+
### GET_LOCATION_CATALOGS
|
174
|
+
- Initialized with `client_attrs = {:access_token=>"access_token1"}`
|
175
|
+
```
|
176
|
+
Hubrise::APIClients::V1.new(client_attrs).get_location_catalogs("zrn61")
|
177
|
+
// => [GET] /locations/zrn61/catalogs with {:headers=>{"X-Access-Token"=>"access_token1"}}
|
178
|
+
```
|
179
|
+
### GET_ACCOUNT_CATALOGS
|
180
|
+
- Initialized with `client_attrs = {:access_token=>"access_token1"}`
|
181
|
+
```
|
182
|
+
Hubrise::APIClients::V1.new(client_attrs).get_account_catalogs("zrn61")
|
183
|
+
// => [GET] /accounts/zrn61/catalogs with {:headers=>{"X-Access-Token"=>"access_token1"}}
|
184
|
+
```
|
185
|
+
### GET_CATALOG
|
186
|
+
- Initialized with `client_attrs = {:access_token=>"access_token1"}`
|
187
|
+
```
|
188
|
+
Hubrise::APIClients::V1.new(client_attrs).get_catalog("zrn61")
|
189
|
+
// => [GET] /catalogs/zrn61 with {:headers=>{"X-Access-Token"=>"access_token1"}}
|
190
|
+
```
|
191
|
+
- Initialized with `client_attrs = {:access_token=>"access_token1", :catalog_id=>"wy3xz"}`
|
192
|
+
```
|
193
|
+
Hubrise::APIClients::V1.new(client_attrs).get_catalog()
|
194
|
+
// => [GET] /catalogs/wy3xz with {:headers=>{"X-Access-Token"=>"access_token1"}}
|
195
|
+
```
|
196
|
+
### CREATE_ACCOUNT_CATALOG
|
197
|
+
- Initialized with `client_attrs = {:access_token=>"access_token1"}`
|
198
|
+
```
|
199
|
+
Hubrise::APIClients::V1.new(client_attrs).create_account_catalog({:name=>"Catalog1"})
|
200
|
+
// => [POST] /account/catalogs with {:headers=>{"Content-Type"=>"application/json"}, :body=>"{\"name\":\"Catalog1\"}"}
|
201
|
+
```
|
202
|
+
### CREATE_LOCATION_CATALOG
|
203
|
+
- Initialized with `client_attrs = {:access_token=>"access_token1"}`
|
204
|
+
```
|
205
|
+
Hubrise::APIClients::V1.new(client_attrs).create_location_catalog({:name=>"Catalog1"}, "zrn61")
|
206
|
+
// => [POST] /locations/zrn61/catalogs with {:headers=>{"Content-Type"=>"application/json"}, :body=>"{\"name\":\"Catalog1\"}"}
|
207
|
+
```
|
208
|
+
- Initialized with `client_attrs = {:access_token=>"access_token1"}`
|
209
|
+
```
|
210
|
+
Hubrise::APIClients::V1.new(client_attrs).create_location_catalog({:name=>"Catalog1"})
|
211
|
+
// => [POST] /location/catalogs with {:headers=>{"Content-Type"=>"application/json"}, :body=>"{\"name\":\"Catalog1\"}"}
|
212
|
+
```
|
213
|
+
### UPDATE_CATALOG
|
214
|
+
- Initialized with `client_attrs = {:access_token=>"access_token1"}`
|
215
|
+
```
|
216
|
+
Hubrise::APIClients::V1.new(client_attrs).update_catalog({:name=>"Catalog1"}, "zrn61")
|
217
|
+
// => [PUT] /catalogs/zrn61 with {:headers=>{"Content-Type"=>"application/json"}, :body=>"{\"name\":\"Catalog1\"}"}
|
218
|
+
```
|
219
|
+
- Initialized with `client_attrs = {:access_token=>"access_token1", :catalog_id=>"zrk6b"}`
|
220
|
+
```
|
221
|
+
Hubrise::APIClients::V1.new(client_attrs).update_catalog({:name=>"Catalog1"})
|
222
|
+
// => [PUT] /catalogs/zrk6b with {:headers=>{"Content-Type"=>"application/json"}, :body=>"{\"name\":\"Catalog1\"}"}
|
223
|
+
```
|
224
|
+
### CREATE_IMAGE
|
225
|
+
- Initialized with `client_attrs = {:access_token=>"access_token1"}`
|
226
|
+
```
|
227
|
+
Hubrise::APIClients::V1.new(client_attrs).create_image("bin1", "image/png", "zrn61")
|
228
|
+
// => [POST] /catalogs/zrn61/images with {:headers=>{"Content-Type"=>"image/png"}, :body=>"bin1"}
|
229
|
+
```
|
230
|
+
- Initialized with `client_attrs = {:access_token=>"access_token1", :catalog_id=>"zrk6b"}`
|
231
|
+
```
|
232
|
+
Hubrise::APIClients::V1.new(client_attrs).create_image("bin1", "image/png")
|
233
|
+
// => [POST] /catalogs/zrk6b/images with {:headers=>{"Content-Type"=>"image/png"}, :body=>"bin1"}
|
234
|
+
```
|
235
|
+
### GET_IMAGE
|
236
|
+
- Initialized with `client_attrs = {:access_token=>"access_token1"}`
|
237
|
+
```
|
238
|
+
Hubrise::APIClients::V1.new(client_attrs).get_image("zrn61", "wy3xz")
|
239
|
+
// => [GET] /catalogs/wy3xz/images/zrn61 with {:headers=>{"X-Access-Token"=>"access_token1"}}
|
240
|
+
```
|
241
|
+
- Initialized with `client_attrs = {:access_token=>"access_token1", :catalog_id=>"zrk6b"}`
|
242
|
+
```
|
243
|
+
Hubrise::APIClients::V1.new(client_attrs).get_image("zrn61")
|
244
|
+
// => [GET] /catalogs/zrk6b/images/zrn61 with {:headers=>{"X-Access-Token"=>"access_token1"}}
|
245
|
+
```
|
246
|
+
### GET_IMAGE_DATA
|
247
|
+
- Initialized with `client_attrs = {:access_token=>"access_token1"}`
|
248
|
+
```
|
249
|
+
Hubrise::APIClients::V1.new(client_attrs).get_image_data("zrn61", "wy3xz")
|
250
|
+
// => [GET] /catalogs/wy3xz/images/zrn61/data with {:headers=>{"X-Access-Token"=>"access_token1"}}
|
251
|
+
```
|
252
|
+
- Initialized with `client_attrs = {:access_token=>"access_token1", :catalog_id=>"zrk6b"}`
|
253
|
+
```
|
254
|
+
Hubrise::APIClients::V1.new(client_attrs).get_image_data("zrn61")
|
255
|
+
// => [GET] /catalogs/zrk6b/images/zrn61/data with {:headers=>{"X-Access-Token"=>"access_token1"}}
|
256
|
+
```
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "net/http"
|
2
|
+
require "json"
|
3
|
+
require "uri"
|
4
|
+
require "logger"
|
5
|
+
|
6
|
+
require_relative "hubrise_client/request"
|
7
|
+
require_relative "hubrise_client/response"
|
8
|
+
require_relative "hubrise_client/base"
|
9
|
+
require_relative "hubrise_client/v1"
|
10
|
+
|
11
|
+
module HubriseClient
|
12
|
+
class HubriseError < StandardError; end
|
13
|
+
class HubriseAccessTokenMissing < HubriseError; end
|
14
|
+
class InvalidHubriseGrantParams < HubriseError; end
|
15
|
+
class InvalidHubriseToken < HubriseError; end
|
16
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
module HubriseClient
|
2
|
+
class Base
|
3
|
+
USE_HTTPS = true
|
4
|
+
DEFAULT_API_HOST = "api.hubrise.com".freeze
|
5
|
+
DEFAULT_API_PORT = "433".freeze
|
6
|
+
DEFAULT_OAUTH_HOST = "manager.hubrise.com".freeze
|
7
|
+
DEFAULT_OAUTH_PORT = "433".freeze
|
8
|
+
|
9
|
+
attr_accessor :access_token,
|
10
|
+
:app_instance_id,
|
11
|
+
:user_id,
|
12
|
+
:account_id,
|
13
|
+
:location_id,
|
14
|
+
:catalog_id,
|
15
|
+
:customer_list_id,
|
16
|
+
:logger
|
17
|
+
|
18
|
+
def initialize(app_id, app_secret, params = {}) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
19
|
+
@app_id = app_id
|
20
|
+
@app_secret = app_secret
|
21
|
+
@api_host = params[:api_host] || DEFAULT_API_HOST
|
22
|
+
@api_port = params[:api_port] || DEFAULT_API_PORT
|
23
|
+
@oauth_host = params[:oauth_host] || DEFAULT_OAUTH_HOST
|
24
|
+
@oauth_port = params[:oauth_port] || DEFAULT_OAUTH_PORT
|
25
|
+
@use_https = !!params.fetch(:use_https, USE_HTTPS)
|
26
|
+
|
27
|
+
initialize_scope_params(params)
|
28
|
+
|
29
|
+
@verbous = !!params[:verbous]
|
30
|
+
unless (@logger = params[:logger]) # rubocop:disable Style/GuardClause
|
31
|
+
@logger = Logger.new(STDOUT)
|
32
|
+
@logger.level = @verbous ? Logger::DEBUG : Logger::WARN
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def build_authorization_url(redirect_uri, scope, params = {})
|
37
|
+
params = params.merge(
|
38
|
+
redirect_uri: redirect_uri,
|
39
|
+
scope: scope,
|
40
|
+
client_id: @app_id
|
41
|
+
)
|
42
|
+
|
43
|
+
(@use_https ? "https" : "http") + "://" + oauth2_hubrise_hostname_with_version + "/authorize?" + URI.encode_www_form(params) # rubocop:disable Metrics/LineLength
|
44
|
+
end
|
45
|
+
|
46
|
+
def authorize!(authorization_code)
|
47
|
+
api_response = api_request(oauth2_hubrise_hostname_with_version).perform(:post, "/token",
|
48
|
+
client_id: @app_id,
|
49
|
+
client_secret: @app_secret,
|
50
|
+
code: authorization_code)
|
51
|
+
|
52
|
+
case api_response.code
|
53
|
+
when "200"
|
54
|
+
initialize_scope_params(api_response.data)
|
55
|
+
when "404"
|
56
|
+
raise InvalidHubriseGrantParams
|
57
|
+
else
|
58
|
+
raise HubriseError, "Unexpected error: #{api_response.http_response.inspect}"
|
59
|
+
end
|
60
|
+
|
61
|
+
self
|
62
|
+
end
|
63
|
+
|
64
|
+
protected
|
65
|
+
|
66
|
+
def initialize_scope_params(params) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/AbcSize, Metrics/LineLength
|
67
|
+
@access_token = params[:access_token] || params["access_token"]
|
68
|
+
@app_instance_id = params[:app_instance_id] || params["app_instance_id"]
|
69
|
+
@user_id = params[:user_id] || params["user_id"]
|
70
|
+
@account_id = params[:account_id] || params["account_id"]
|
71
|
+
@location_id = params[:location_id] || params["location_id"]
|
72
|
+
@catalog_id = params[:catalog_id] || params["catalog_id"]
|
73
|
+
@customer_list_id = params[:customer_list_id] || params["customer_list_id"]
|
74
|
+
end
|
75
|
+
|
76
|
+
def call_api(path, method = :get, data: {}, headers: {}, json: true)
|
77
|
+
raise(HubriseAccessTokenMissing) if @access_token.nil?
|
78
|
+
|
79
|
+
api_request("#{@api_host}:#{@api_port}/#{version}", @access_token).perform(method, path, data, json: json,
|
80
|
+
headers: headers)
|
81
|
+
end
|
82
|
+
|
83
|
+
def api_request(hostname, access_token = nil)
|
84
|
+
Request.new(
|
85
|
+
hostname: hostname,
|
86
|
+
access_token: access_token,
|
87
|
+
use_https: @use_https,
|
88
|
+
logger: @logger
|
89
|
+
)
|
90
|
+
end
|
91
|
+
|
92
|
+
def oauth2_hubrise_hostname_with_version
|
93
|
+
"#{@oauth_host}:#{@oauth_port}/oauth2/#{version}"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module HubriseClient
|
2
|
+
class Request
|
3
|
+
REQUESTS_HASH = {
|
4
|
+
get: Net::HTTP::Get,
|
5
|
+
post: Net::HTTP::Post,
|
6
|
+
put: Net::HTTP::Put,
|
7
|
+
delete: Net::HTTP::Delete
|
8
|
+
}.freeze
|
9
|
+
|
10
|
+
def initialize(hostname:, access_token: nil, use_https: false, logger: nil)
|
11
|
+
@hostname = hostname
|
12
|
+
@access_token = access_token
|
13
|
+
@use_https = use_https
|
14
|
+
@protocol = use_https ? "https" : "http"
|
15
|
+
@logger = logger
|
16
|
+
end
|
17
|
+
|
18
|
+
def perform(method, path, data, json: true, headers: {})
|
19
|
+
uri = URI.parse(@protocol + "://" + @hostname + path)
|
20
|
+
http_request = build_request(uri, method, data, json: json, headers: headers)
|
21
|
+
http_response = perform_request(uri, http_request)
|
22
|
+
|
23
|
+
case http_response
|
24
|
+
when Net::HTTPUnauthorized
|
25
|
+
raise InvalidHubriseToken
|
26
|
+
else
|
27
|
+
raise(HubriseError, "Unexpected error") if http_response.code.start_with?("5")
|
28
|
+
|
29
|
+
Response.new(http_response)
|
30
|
+
end
|
31
|
+
rescue Errno::ECONNREFUSED
|
32
|
+
raise HubriseError, "API is not reachable"
|
33
|
+
end
|
34
|
+
|
35
|
+
protected
|
36
|
+
|
37
|
+
def build_request(uri, method, data, json:, headers:)
|
38
|
+
headers["X-Access-Token"] = @access_token if @access_token
|
39
|
+
|
40
|
+
if method == :get
|
41
|
+
uri = add_params_to_uri(uri, data)
|
42
|
+
data = nil
|
43
|
+
elsif json
|
44
|
+
headers["Content-Type"] ||= "application/json"
|
45
|
+
data = data.to_json
|
46
|
+
end
|
47
|
+
|
48
|
+
REQUESTS_HASH[method].new(uri, headers).tap do |request|
|
49
|
+
request.body = data
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def add_params_to_uri(uri, params)
|
54
|
+
uri.query = [uri.query, URI.encode_www_form(params)].compact.join("&")
|
55
|
+
uri
|
56
|
+
end
|
57
|
+
|
58
|
+
def perform_request(uri, request)
|
59
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
60
|
+
http.use_ssl = @use_https
|
61
|
+
http.set_debug_output(@logger) if @logger
|
62
|
+
http.request(request)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module HubriseClient
|
2
|
+
class Response
|
3
|
+
attr_reader :code, :failed, :data, :error_type, :error_message, :errors, :http_response
|
4
|
+
alias failed? failed
|
5
|
+
|
6
|
+
def initialize(http_response)
|
7
|
+
@http_response = http_response
|
8
|
+
@code = http_response.code
|
9
|
+
|
10
|
+
json_body = begin
|
11
|
+
JSON.parse(http_response.body)
|
12
|
+
rescue StandardError
|
13
|
+
nil
|
14
|
+
end
|
15
|
+
|
16
|
+
@data = json_body || http_response.body
|
17
|
+
|
18
|
+
case http_response
|
19
|
+
when Net::HTTPSuccess
|
20
|
+
@failed = false
|
21
|
+
else
|
22
|
+
@failed = true
|
23
|
+
if json_body
|
24
|
+
@errors = json_body["errors"]
|
25
|
+
@error_type = json_body["error_type"]
|
26
|
+
@error_message = json_body["message"]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def retry_after
|
32
|
+
http_response.is_a?(Net::HTTPTooManyRequests) && http_response["retry-after"].to_i
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,181 @@
|
|
1
|
+
# rubocop:disable Naming/AccessorMethodName
|
2
|
+
module HubriseClient
|
3
|
+
class V1 < Base
|
4
|
+
def version
|
5
|
+
:v1
|
6
|
+
end
|
7
|
+
|
8
|
+
# --------------------
|
9
|
+
# Accounts, locations, user
|
10
|
+
# --------------------
|
11
|
+
def get_account(account_id = nil)
|
12
|
+
if account_id
|
13
|
+
call_api("/accounts/#{account_id}")
|
14
|
+
else
|
15
|
+
call_api("/account")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def get_accounts
|
20
|
+
call_api("/accounts")
|
21
|
+
end
|
22
|
+
|
23
|
+
def get_user
|
24
|
+
call_api("/user")
|
25
|
+
end
|
26
|
+
|
27
|
+
def get_locations
|
28
|
+
call_api("/locations")
|
29
|
+
end
|
30
|
+
|
31
|
+
def get_location(location_id = nil)
|
32
|
+
if location_id
|
33
|
+
call_api("/locations/#{location_id}")
|
34
|
+
else
|
35
|
+
call_api("/location")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# --------------------
|
40
|
+
# Orders
|
41
|
+
# --------------------
|
42
|
+
def get_orders(location_id, search_params)
|
43
|
+
call_api("/locations/#{location_id}/orders", :get, data: search_params)
|
44
|
+
end
|
45
|
+
|
46
|
+
def get_order(location_id, order_id)
|
47
|
+
call_api("/locations/#{location_id}/orders/#{order_id}")
|
48
|
+
end
|
49
|
+
|
50
|
+
def create_order(location_id, params)
|
51
|
+
call_api("/locations/#{location_id}/orders", :post, data: params)
|
52
|
+
end
|
53
|
+
|
54
|
+
def update_order(location_id, order_id, params)
|
55
|
+
call_api("/locations/#{location_id}/orders/#{order_id}", :put, data: params)
|
56
|
+
end
|
57
|
+
|
58
|
+
# --------------------
|
59
|
+
# Callback, events
|
60
|
+
# --------------------
|
61
|
+
def get_callback
|
62
|
+
call_api("/callback")
|
63
|
+
end
|
64
|
+
|
65
|
+
def get_callback_events
|
66
|
+
call_api("/callback/events")
|
67
|
+
end
|
68
|
+
|
69
|
+
def delete_event(event_id)
|
70
|
+
call_api("/callback/events/#{event_id}", :delete)
|
71
|
+
end
|
72
|
+
|
73
|
+
def update_callback(params)
|
74
|
+
call_api("/callback", :post, data: params)
|
75
|
+
end
|
76
|
+
|
77
|
+
def delete_callback
|
78
|
+
call_api("/callback", :delete)
|
79
|
+
end
|
80
|
+
|
81
|
+
# --------------------
|
82
|
+
# Customer lists, customers
|
83
|
+
# --------------------
|
84
|
+
def get_location_customer_lists(location_id)
|
85
|
+
call_api("/locations/#{location_id}/customer_lists")
|
86
|
+
end
|
87
|
+
|
88
|
+
def get_account_customer_lists(account_id)
|
89
|
+
call_api("/accounts/#{account_id}/customer_lists")
|
90
|
+
end
|
91
|
+
|
92
|
+
def get_customer_list(customer_list_id = nil)
|
93
|
+
call_api("/customer_lists/#{customer_list_id_fallback(customer_list_id)}")
|
94
|
+
end
|
95
|
+
|
96
|
+
def get_all_customers(customer_list_id = nil)
|
97
|
+
search_customers({}, customer_list_id)
|
98
|
+
end
|
99
|
+
|
100
|
+
def search_customers(search_params, customer_list_id = nil)
|
101
|
+
call_api("/customer_lists/#{customer_list_id_fallback(customer_list_id)}/customers", :get, data: search_params)
|
102
|
+
end
|
103
|
+
|
104
|
+
def get_customer(customer_id, customer_list_id = nil)
|
105
|
+
call_api("/customer_lists/#{customer_list_id_fallback(customer_list_id)}/customers/#{customer_id}")
|
106
|
+
end
|
107
|
+
|
108
|
+
def create_customer(params, customer_list_id = nil)
|
109
|
+
call_api("/customer_lists/#{customer_list_id_fallback(customer_list_id)}/customers", :post, data: params)
|
110
|
+
end
|
111
|
+
|
112
|
+
def update_customer(customer_id, params, customer_list_id = nil)
|
113
|
+
call_api("/customer_lists/#{customer_list_id_fallback(customer_list_id)}/customers/#{customer_id}", :put,
|
114
|
+
data: params)
|
115
|
+
end
|
116
|
+
|
117
|
+
# --------------------
|
118
|
+
# Catalogs
|
119
|
+
# --------------------
|
120
|
+
def get_location_catalogs(location_id)
|
121
|
+
call_api("/locations/#{location_id}/catalogs")
|
122
|
+
end
|
123
|
+
|
124
|
+
def get_account_catalogs(account_id)
|
125
|
+
call_api("/accounts/#{account_id}/catalogs")
|
126
|
+
end
|
127
|
+
|
128
|
+
def get_catalog(catalog_id = nil)
|
129
|
+
call_api("/catalogs/#{catalog_id_fallback(catalog_id)}")
|
130
|
+
end
|
131
|
+
|
132
|
+
def create_account_catalog(params)
|
133
|
+
call_api("/account/catalogs", :post, data: params)
|
134
|
+
end
|
135
|
+
|
136
|
+
def create_location_catalog(params, location_id = nil)
|
137
|
+
if location_id
|
138
|
+
call_api("/locations/#{location_id}/catalogs", :post, data: params)
|
139
|
+
else
|
140
|
+
call_api("/location/catalogs", :post, data: params)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def update_catalog(params, catalog_id = nil)
|
145
|
+
call_api("/catalogs/#{catalog_id_fallback(catalog_id)}", :put, data: params)
|
146
|
+
end
|
147
|
+
|
148
|
+
# --------------------
|
149
|
+
# Images
|
150
|
+
# --------------------
|
151
|
+
def create_image(data, mime_type, catalog_id = nil)
|
152
|
+
call_api("/catalogs/#{catalog_id_fallback(catalog_id)}/images", :post, data: data,
|
153
|
+
headers: { "Content-Type" => mime_type },
|
154
|
+
json: false)
|
155
|
+
end
|
156
|
+
|
157
|
+
def get_image(image_id, catalog_id = nil)
|
158
|
+
call_api("/catalogs/#{catalog_id_fallback(catalog_id)}/images/#{image_id}")
|
159
|
+
end
|
160
|
+
|
161
|
+
def get_image_data(image_id, catalog_id = nil)
|
162
|
+
call_api("/catalogs/#{catalog_id_fallback(catalog_id)}/images/#{image_id}/data")
|
163
|
+
end
|
164
|
+
|
165
|
+
private
|
166
|
+
|
167
|
+
def customer_list_id_fallback(customer_list_id)
|
168
|
+
customer_list_id ||= @customer_list_id
|
169
|
+
raise("customer_list_id required") if customer_list_id.nil? || customer_list_id.empty?
|
170
|
+
|
171
|
+
customer_list_id
|
172
|
+
end
|
173
|
+
|
174
|
+
def catalog_id_fallback(catalog_id)
|
175
|
+
catalog_id ||= @catalog_id
|
176
|
+
raise("catalog_id required") if catalog_id.nil? || catalog_id.empty?
|
177
|
+
|
178
|
+
catalog_id
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hubrise_client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Antoine Monnier
|
8
|
+
- Nick Save
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2019-05-31 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rubocop
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: simplecov
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: webmock
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
description:
|
71
|
+
email:
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- LICENSE
|
77
|
+
- README.md
|
78
|
+
- Rakefile
|
79
|
+
- V1_ENDPOINTS.md
|
80
|
+
- lib/hubrise_client.rb
|
81
|
+
- lib/hubrise_client/base.rb
|
82
|
+
- lib/hubrise_client/request.rb
|
83
|
+
- lib/hubrise_client/response.rb
|
84
|
+
- lib/hubrise_client/v1.rb
|
85
|
+
- lib/hubrise_client/version.rb
|
86
|
+
homepage: https://github.com/HubRise/ruby-client
|
87
|
+
licenses:
|
88
|
+
- MIT
|
89
|
+
metadata: {}
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 2.7.6
|
107
|
+
signing_key:
|
108
|
+
specification_version: 4
|
109
|
+
summary: Hubrise Ruby client
|
110
|
+
test_files: []
|