hubrise_client 2.0.2 → 2.0.3
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/README.md +75 -7
- data/Rakefile +2 -1
- data/V1_ENDPOINTS.md +372 -225
- data/lib/hubrise_client/base.rb +19 -14
- data/lib/hubrise_client/request.rb +14 -12
- data/lib/hubrise_client/response.rb +5 -4
- data/lib/hubrise_client/v1.rb +47 -3
- data/lib/hubrise_client/version.rb +2 -1
- data/lib/hubrise_client.rb +1 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f10358d2bbba5919834bc9209feafaa301aee68fa07153aad77a5e31c3844a28
|
4
|
+
data.tar.gz: 4d881d4e77a8df23a4dfc784e3b8505db21859dee1f69bfcd18e2c683b5e1044
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 865672a43693575a2493bd2b2edf3e2e1ef95268065bf6bfa9c5398045fda40537c501f0f74741f36443541491c84a4b10ccaabb9c3dafcb7e22c80e2bfb31fd
|
7
|
+
data.tar.gz: eeb709dfdb5216f72d15afe73f53913847744e54c70f6119bf24d2e5377d79bbc118536544b5b6a8a70b82b3ca115dbc1503b53b56bb16527bd5f7aa06e72439
|
data/README.md
CHANGED
@@ -1,12 +1,80 @@
|
|
1
|
-
|
1
|
+
This gem is a Ruby SDK for [Hubrise API](https://www.hubrise.com/developers). It is maintained by the HubRise development team.
|
2
2
|
|
3
|
-
|
3
|
+
# Installation
|
4
4
|
|
5
|
-
|
5
|
+
Add `hubrise_client` to your `Gemfile`:
|
6
6
|
|
7
|
-
|
7
|
+
```ruby
|
8
|
+
gem 'hubrise_client'
|
9
|
+
```
|
10
|
+
|
11
|
+
Or install via [gem](http://rubygems.org/)
|
8
12
|
|
9
13
|
```bash
|
10
|
-
gem
|
11
|
-
|
12
|
-
|
14
|
+
gem install hubrise_client
|
15
|
+
```
|
16
|
+
|
17
|
+
|
18
|
+
# Prerequisites
|
19
|
+
|
20
|
+
1) Read the [docs](https://www.hubrise.com/developers)
|
21
|
+
|
22
|
+
2) [Create a Hubrise Client](https://www.hubrise.com/developers/quick-start#create-the-oauth-client) to get your `CLIENT_ID` and `CLIENT_SECRET`.
|
23
|
+
|
24
|
+
|
25
|
+
# Get an access token
|
26
|
+
|
27
|
+
1. Initialize anonymous `HubriseClient`
|
28
|
+
```ruby
|
29
|
+
client = HubriseClient::V1.new(CLIENT_ID, CLIENT_SECRET)
|
30
|
+
```
|
31
|
+
|
32
|
+
2. Prepare a route to handle `REDIRECT_URI` callback
|
33
|
+
```ruby
|
34
|
+
# routes.rb
|
35
|
+
namespace :hubrise_oauth do
|
36
|
+
get :authorize_callback
|
37
|
+
# => creates hubrise_oauth_authorize_callback_url helper
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
41
|
+
|
42
|
+
3. Initiate an OAuth flow by redirecting a user to [OAuth Authorization URL](https://www.hubrise.com/developers/authentication#request-authorisation)
|
43
|
+
```ruby
|
44
|
+
oauth_scope = "location[orders.read]" # adjust to your needs
|
45
|
+
authorization_url = client.build_authorization_url(hubrise_oauth_authorize_callback_url, oauth_scope)
|
46
|
+
...
|
47
|
+
redirect_to(authorization_url)
|
48
|
+
```
|
49
|
+
|
50
|
+
4. Complete the OAuth flow
|
51
|
+
|
52
|
+
Once the user accepts your request he or she will be redirected to the REDIRECT_URI
|
53
|
+
At this step you need to [exchange](https://www.hubrise.com/developers/authentication#get-an-access-token) the `authorization_code` (received as a query param) for a new `access_token`
|
54
|
+
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
# controllers/hubrise_oauth_controller.rb
|
58
|
+
|
59
|
+
def authorize_callback
|
60
|
+
client.authorize!(params[:code])
|
61
|
+
|
62
|
+
current_user.update!(hubrise_access_token: client.access_token)
|
63
|
+
# account_id = client.account_id
|
64
|
+
# location_id = client.location_id
|
65
|
+
end
|
66
|
+
```
|
67
|
+
|
68
|
+
The `access_token` reffers to this specific user's permission so it should be securely persisted and not shared with other users.
|
69
|
+
|
70
|
+
|
71
|
+
# Use the access token
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
client = HubriseClient::V1.new(CLIENT_ID, CLIENT_SECRET, access_token: current_user.hubrise_access_token)
|
75
|
+
```
|
76
|
+
|
77
|
+
Now you can call the [helper methods](https://github.com/HubRise/ruby-client/blob/master/V1_ENDPOINTS.md) on behalf of the user
|
78
|
+
```ruby
|
79
|
+
client.get_account
|
80
|
+
```
|
data/Rakefile
CHANGED
data/V1_ENDPOINTS.md
CHANGED
@@ -1,256 +1,403 @@
|
|
1
|
+
# Full list of available methods to access the API
|
2
|
+
|
3
|
+
```ruby
|
4
|
+
client = HubriseClient::V1.new(CLIENT_ID, CLIENT_SECRET, client_attrs)
|
5
|
+
```
|
6
|
+
|
1
7
|
### GET_ACCOUNT
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
|
9
|
+
- Initialized with `client_attrs = { access_token: "access_token1" }`
|
10
|
+
```ruby
|
11
|
+
client.get_account("zrn61")
|
12
|
+
# [GET] /accounts/zrn61 with { headers: { "X-Access-Token": "access_token1" }}
|
13
|
+
```
|
14
|
+
- Initialized with `client_attrs = { access_token: "access_token1" }`
|
15
|
+
```ruby
|
16
|
+
client.get_account
|
17
|
+
# [GET] /account with { headers: { "X-Access-Token": "access_token1" }}
|
18
|
+
```
|
19
|
+
|
12
20
|
### GET_ACCOUNTS
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
21
|
+
|
22
|
+
- Initialized with `client_attrs = { access_token: "access_token1" }`
|
23
|
+
```ruby
|
24
|
+
client.get_accounts
|
25
|
+
# [GET] /accounts with { headers: { "X-Access-Token": "access_token1" }}
|
26
|
+
```
|
27
|
+
|
18
28
|
### GET_USER
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
29
|
+
|
30
|
+
- Initialized with `client_attrs = { access_token: "access_token1" }`
|
31
|
+
```ruby
|
32
|
+
client.get_user
|
33
|
+
# [GET] /user with { headers: { "X-Access-Token": "access_token1" }}
|
34
|
+
```
|
35
|
+
|
24
36
|
### GET_LOCATIONS
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
37
|
+
|
38
|
+
- Initialized with `client_attrs = { access_token: "access_token1" }`
|
39
|
+
```ruby
|
40
|
+
client.get_locations
|
41
|
+
# [GET] /locations with { headers: { "X-Access-Token": "access_token1" }}
|
42
|
+
```
|
43
|
+
|
30
44
|
### GET_LOCATION
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
45
|
+
|
46
|
+
- Initialized with `client_attrs = { access_token: "access_token1" }`
|
47
|
+
```ruby
|
48
|
+
client.get_location("zrn61")
|
49
|
+
# [GET] /locations/zrn61 with { headers: { "X-Access-Token": "access_token1" }}
|
50
|
+
```
|
51
|
+
- Initialized with `client_attrs = { access_token: "access_token1" }`
|
52
|
+
```ruby
|
53
|
+
client.get_location
|
54
|
+
# [GET] /location with { headers: { "X-Access-Token": "access_token1" }}
|
55
|
+
```
|
56
|
+
|
41
57
|
### GET_ORDERS
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
58
|
+
|
59
|
+
- Initialized with `client_attrs = { access_token: "access_token1" }`
|
60
|
+
```ruby
|
61
|
+
client.get_orders("zrn61", { status: "new" })
|
62
|
+
# [GET] /locations/zrn61/orders?status=new with { headers: { "X-Access-Token": "access_token1" }}
|
63
|
+
```
|
64
|
+
|
47
65
|
### GET_ORDER
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
66
|
+
|
67
|
+
- Initialized with `client_attrs = { access_token: "access_token1" }`
|
68
|
+
```ruby
|
69
|
+
client.get_order("zrn61", "wy3xz")
|
70
|
+
# [GET] /locations/zrn61/orders/wy3xz with { headers: { "X-Access-Token": "access_token1" }}
|
71
|
+
```
|
72
|
+
|
53
73
|
### CREATE_ORDER
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
74
|
+
|
75
|
+
- Initialized with `client_attrs = { access_token: "access_token1" }`
|
76
|
+
```ruby
|
77
|
+
client.create_order("zrn61", { status: "new" })
|
78
|
+
# [POST] /locations/zrn61/orders with { headers: { "Content-Type": "application/json" }, body: "{\"status\":\"new\" }" }
|
79
|
+
```
|
80
|
+
|
59
81
|
### UPDATE_ORDER
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
82
|
+
|
83
|
+
- Initialized with `client_attrs = { access_token: "access_token1" }`
|
84
|
+
```ruby
|
85
|
+
client.update_order("zrn61", "wy3xz", { status: "delivered" })
|
86
|
+
# [PUT] /locations/zrn61/orders/wy3xz with { headers: { "Content-Type": "application/json" }, body: "{\"status\":\"delivered\" }" }
|
87
|
+
```
|
88
|
+
|
65
89
|
### GET_CALLBACK
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
90
|
+
|
91
|
+
- Initialized with `client_attrs = { access_token: "access_token1" }`
|
92
|
+
```ruby
|
93
|
+
client.get_callback
|
94
|
+
# [GET] /callback with { headers: { "X-Access-Token": "access_token1" }}
|
95
|
+
```
|
96
|
+
|
71
97
|
### GET_CALLBACK_EVENTS
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
98
|
+
|
99
|
+
- Initialized with `client_attrs = { access_token: "access_token1" }`
|
100
|
+
```ruby
|
101
|
+
client.get_callback_events
|
102
|
+
# [GET] /callback/events with { headers: { "X-Access-Token": "access_token1" }}
|
103
|
+
```
|
104
|
+
|
77
105
|
### DELETE_EVENT
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
106
|
+
|
107
|
+
- Initialized with `client_attrs = { access_token: "access_token1" }`
|
108
|
+
```ruby
|
109
|
+
client.delete_event("zrn61")
|
110
|
+
# [DELETE] /callback/events/zrn61 with { headers: { "X-Access-Token": "access_token1" }}
|
111
|
+
```
|
112
|
+
|
83
113
|
### UPDATE_CALLBACK
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
114
|
+
|
115
|
+
- Initialized with `client_attrs = { access_token: "access_token1" }`
|
116
|
+
```ruby
|
117
|
+
client.update_callback({ "order": ["create"]})
|
118
|
+
# [POST] /callback with { headers: { "Content-Type": "application/json" }, body: "{\"order\":[\"create\"]}" }
|
119
|
+
```
|
120
|
+
|
89
121
|
### DELETE_CALLBACK
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
122
|
+
|
123
|
+
- Initialized with `client_attrs = { access_token: "access_token1" }`
|
124
|
+
```ruby
|
125
|
+
client.delete_callback
|
126
|
+
# [DELETE] /callback with { headers: { "X-Access-Token": "access_token1" }}
|
127
|
+
```
|
128
|
+
|
95
129
|
### GET_LOCATION_CUSTOMER_LISTS
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
130
|
+
|
131
|
+
- Initialized with `client_attrs = { access_token: "access_token1" }`
|
132
|
+
```ruby
|
133
|
+
client.get_location_customer_lists("zrn61")
|
134
|
+
# [GET] /locations/zrn61/customer_lists with { headers: { "X-Access-Token": "access_token1" }}
|
135
|
+
```
|
136
|
+
|
101
137
|
### GET_ACCOUNT_CUSTOMER_LISTS
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
138
|
+
|
139
|
+
- Initialized with `client_attrs = { access_token: "access_token1" }`
|
140
|
+
```ruby
|
141
|
+
client.get_account_customer_lists("zrn61")
|
142
|
+
# [GET] /accounts/zrn61/customer_lists with { headers: { "X-Access-Token": "access_token1" }}
|
143
|
+
```
|
144
|
+
|
107
145
|
### GET_CUSTOMER_LIST
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
146
|
+
|
147
|
+
- Initialized with `client_attrs = { access_token: "access_token1" }`
|
148
|
+
```ruby
|
149
|
+
client.get_customer_list("zrn61")
|
150
|
+
# [GET] /customer_lists/zrn61 with { headers: { "X-Access-Token": "access_token1" }}
|
151
|
+
```
|
152
|
+
- Initialized with `client_attrs = { access_token: "access_token1", customer_list_id: "wy3xz" }`
|
153
|
+
```ruby
|
154
|
+
client.get_customer_list
|
155
|
+
# [GET] /customer_lists/wy3xz with { headers: { "X-Access-Token": "access_token1" }}
|
156
|
+
```
|
157
|
+
|
118
158
|
### GET_ALL_CUSTOMERS
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
159
|
+
|
160
|
+
- Initialized with `client_attrs = { access_token: "access_token1" }`
|
161
|
+
```ruby
|
162
|
+
client.get_all_customers("zrn61")
|
163
|
+
# [GET] /customer_lists/zrn61/customers with { headers: { "X-Access-Token": "access_token1" }}
|
164
|
+
```
|
165
|
+
- Initialized with `client_attrs = { access_token: "access_token1", customer_list_id: "wy3xz" }`
|
166
|
+
```ruby
|
167
|
+
client.get_all_customers
|
168
|
+
# [GET] /customer_lists/wy3xz/customers with { headers: { "X-Access-Token": "access_token1" }}
|
169
|
+
```
|
170
|
+
|
129
171
|
### SEARCH_CUSTOMERS
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
172
|
+
|
173
|
+
- Initialized with `client_attrs = { access_token: "access_token1", customer_list_id: "zrn61" }`
|
174
|
+
```ruby
|
175
|
+
client.search_customers({ email: "nsave@*" })
|
176
|
+
# [GET] /customer_lists/zrn61/customers?email=nsave@* with { headers: { "X-Access-Token": "access_token1" }}
|
177
|
+
```
|
178
|
+
- Initialized with `client_attrs = { access_token: "access_token1" }`
|
179
|
+
```ruby
|
180
|
+
client.search_customers({ email: "nsave@*" }, "wy3xz")
|
181
|
+
# [GET] /customer_lists/wy3xz/customers?email=nsave@* with { headers: { "X-Access-Token": "access_token1" }}
|
182
|
+
```
|
183
|
+
|
140
184
|
### GET_CUSTOMER
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
185
|
+
|
186
|
+
- Initialized with `client_attrs = { access_token: "access_token1", customer_list_id: "zrn61" }`
|
187
|
+
```ruby
|
188
|
+
client.get_customer("zrk6b")
|
189
|
+
# [GET] /customer_lists/zrn61/customers/zrk6b with { headers: { "X-Access-Token": "access_token1" }}
|
190
|
+
```
|
191
|
+
- Initialized with `client_attrs = { access_token: "access_token1" }`
|
192
|
+
```ruby
|
193
|
+
client.get_customer("zrk6b", "wy3xz")
|
194
|
+
# [GET] /customer_lists/wy3xz/customers/zrk6b with { headers: { "X-Access-Token": "access_token1" }}
|
195
|
+
```
|
196
|
+
|
151
197
|
### CREATE_CUSTOMER
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
198
|
+
|
199
|
+
- Initialized with `client_attrs = { access_token: "access_token1", customer_list_id: "zrn61" }`
|
200
|
+
```ruby
|
201
|
+
client.create_customer({ first_name: "nsave" })
|
202
|
+
# [POST] /customer_lists/zrn61/customers with { headers: { "Content-Type": "application/json" }, body: "{\"first_name\":\"nsave\" }" }
|
203
|
+
```
|
204
|
+
- Initialized with `client_attrs = { access_token: "access_token1" }`
|
205
|
+
```ruby
|
206
|
+
client.create_customer({ first_name: "nsave" }, "wy3xz")
|
207
|
+
# [POST] /customer_lists/wy3xz/customers with { headers: { "Content-Type": "application/json" }, body: "{\"first_name\":\"nsave\" }" }
|
208
|
+
```
|
209
|
+
|
162
210
|
### UPDATE_CUSTOMER
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
211
|
+
|
212
|
+
- Initialized with `client_attrs = { access_token: "access_token1", customer_list_id: "zrn61" }`
|
213
|
+
```ruby
|
214
|
+
client.update_customer("zrk6b", { first_name: "nsave" })
|
215
|
+
# [PUT] /customer_lists/zrn61/customers/zrk6b with { headers: { "Content-Type": "application/json" }, body: "{\"first_name\":\"nsave\" }" }
|
216
|
+
```
|
217
|
+
- Initialized with `client_attrs = { access_token: "access_token1" }`
|
218
|
+
```ruby
|
219
|
+
client.update_customer("zrk6b", { first_name: "nsave" }, "wy3xz")
|
220
|
+
# [PUT] /customer_lists/wy3xz/customers/zrk6b with { headers: { "Content-Type": "application/json" }, body: "{\"first_name\":\"nsave\" }" }
|
221
|
+
```
|
222
|
+
|
173
223
|
### GET_LOCATION_CATALOGS
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
224
|
+
|
225
|
+
- Initialized with `client_attrs = { access_token: "access_token1" }`
|
226
|
+
```ruby
|
227
|
+
client.get_location_catalogs("zrn61")
|
228
|
+
# [GET] /locations/zrn61/catalogs with { headers: { "X-Access-Token": "access_token1" }}
|
229
|
+
```
|
230
|
+
|
179
231
|
### GET_ACCOUNT_CATALOGS
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
232
|
+
|
233
|
+
- Initialized with `client_attrs = { access_token: "access_token1" }`
|
234
|
+
```ruby
|
235
|
+
client.get_account_catalogs("zrn61")
|
236
|
+
# [GET] /accounts/zrn61/catalogs with { headers: { "X-Access-Token": "access_token1" }}
|
237
|
+
```
|
238
|
+
|
185
239
|
### GET_CATALOG
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
240
|
+
|
241
|
+
- Initialized with `client_attrs = { access_token: "access_token1" }`
|
242
|
+
```ruby
|
243
|
+
client.get_catalog("zrn61")
|
244
|
+
# [GET] /catalogs/zrn61 with { headers: { "X-Access-Token": "access_token1" }}
|
245
|
+
```
|
246
|
+
- Initialized with `client_attrs = { access_token: "access_token1", catalog_id: "wy3xz" }`
|
247
|
+
```ruby
|
248
|
+
client.get_catalog
|
249
|
+
# [GET] /catalogs/wy3xz with { headers: { "X-Access-Token": "access_token1" }}
|
250
|
+
```
|
251
|
+
|
196
252
|
### CREATE_ACCOUNT_CATALOG
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
253
|
+
|
254
|
+
- Initialized with `client_attrs = { access_token: "access_token1" }`
|
255
|
+
```ruby
|
256
|
+
client.create_account_catalog({ name: "Catalog1" })
|
257
|
+
# [POST] /account/catalogs with { headers: { "Content-Type": "application/json" }, body: "{\"name\":\"Catalog1\" }" }
|
258
|
+
```
|
259
|
+
|
202
260
|
### CREATE_LOCATION_CATALOG
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
261
|
+
|
262
|
+
- Initialized with `client_attrs = { access_token: "access_token1" }`
|
263
|
+
```ruby
|
264
|
+
client.create_location_catalog({ name: "Catalog1" }, "zrn61")
|
265
|
+
# [POST] /locations/zrn61/catalogs with { headers: { "Content-Type": "application/json" }, body: "{\"name\":\"Catalog1\" }" }
|
266
|
+
```
|
267
|
+
- Initialized with `client_attrs = { access_token: "access_token1" }`
|
268
|
+
```ruby
|
269
|
+
client.create_location_catalog({ name: "Catalog1" })
|
270
|
+
# [POST] /location/catalogs with { headers: { "Content-Type": "application/json" }, body: "{\"name\":\"Catalog1\" }" }
|
271
|
+
```
|
272
|
+
|
213
273
|
### UPDATE_CATALOG
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
274
|
+
|
275
|
+
- Initialized with `client_attrs = { access_token: "access_token1" }`
|
276
|
+
```ruby
|
277
|
+
client.update_catalog({ name: "Catalog1" }, "zrn61")
|
278
|
+
# [PUT] /catalogs/zrn61 with { headers: { "Content-Type": "application/json" }, body: "{\"name\":\"Catalog1\" }" }
|
279
|
+
```
|
280
|
+
- Initialized with `client_attrs = { access_token: "access_token1", catalog_id: "zrk6b" }`
|
281
|
+
```ruby
|
282
|
+
client.update_catalog({ name: "Catalog1" })
|
283
|
+
# [PUT] /catalogs/zrk6b with { headers: { "Content-Type": "application/json" }, body: "{\"name\":\"Catalog1\" }" }
|
284
|
+
```
|
285
|
+
|
224
286
|
### CREATE_IMAGE
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
287
|
+
|
288
|
+
- Initialized with `client_attrs = { access_token: "access_token1" }`
|
289
|
+
```ruby
|
290
|
+
client.create_image("bin1", "image/png", "zrn61")
|
291
|
+
# [POST] /catalogs/zrn61/images with { headers: { "Content-Type": "image/png" }, body: "bin1" }
|
292
|
+
```
|
293
|
+
- Initialized with `client_attrs = { access_token: "access_token1", catalog_id: "zrk6b" }`
|
294
|
+
```ruby
|
295
|
+
client.create_image("bin1", "image/png")
|
296
|
+
# [POST] /catalogs/zrk6b/images with { headers: { "Content-Type": "image/png" }, body: "bin1" }
|
297
|
+
```
|
298
|
+
|
235
299
|
### GET_IMAGE
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
300
|
+
|
301
|
+
- Initialized with `client_attrs = { access_token: "access_token1" }`
|
302
|
+
```ruby
|
303
|
+
client.get_image("zrn61", "wy3xz")
|
304
|
+
# [GET] /catalogs/wy3xz/images/zrn61 with { headers: { "X-Access-Token": "access_token1" }}
|
305
|
+
```
|
306
|
+
- Initialized with `client_attrs = { access_token: "access_token1", catalog_id: "zrk6b" }`
|
307
|
+
```ruby
|
308
|
+
client.get_image("zrn61")
|
309
|
+
# [GET] /catalogs/zrk6b/images/zrn61 with { headers: { "X-Access-Token": "access_token1" }}
|
310
|
+
```
|
311
|
+
|
246
312
|
### GET_IMAGE_DATA
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
313
|
+
|
314
|
+
- Initialized with `client_attrs = { access_token: "access_token1" }`
|
315
|
+
```ruby
|
316
|
+
client.get_image_data("zrn61", "wy3xz")
|
317
|
+
# [GET] /catalogs/wy3xz/images/zrn61/data with { headers: { "X-Access-Token": "access_token1" }}
|
318
|
+
```
|
319
|
+
- Initialized with `client_attrs = { access_token: "access_token1", catalog_id: "zrk6b" }`
|
320
|
+
```ruby
|
321
|
+
client.get_image_data("zrn61")
|
322
|
+
# [GET] /catalogs/zrk6b/images/zrn61/data with { headers: { "X-Access-Token": "access_token1" }}
|
323
|
+
```
|
324
|
+
|
325
|
+
### GET_INVENTORY
|
326
|
+
|
327
|
+
- Initialized with `client_attrs = { access_token: "access_token1" }`
|
328
|
+
```ruby
|
329
|
+
client.get_inventory("zrn61", "wy3xz")
|
330
|
+
# [GET] /catalogs/zrn61/locations/wy3xz/inventory with { headers: { "X-Access-Token": "access_token1" }}
|
331
|
+
```
|
332
|
+
- Initialized with `client_attrs = { access_token: "access_token1" }`
|
333
|
+
```ruby
|
334
|
+
client.get_inventory("zrn61")
|
335
|
+
# [GET] /catalogs/zrn61/location/inventory with { headers: { "X-Access-Token": "access_token1" }}
|
336
|
+
```
|
337
|
+
- Initialized with `client_attrs = { access_token: "access_token1", catalog_id: "zrn61" }`
|
338
|
+
```ruby
|
339
|
+
client.get_inventory
|
340
|
+
# [GET] /catalogs/zrn61/location/inventory with { headers: { "X-Access-Token": "access_token1" }}
|
341
|
+
```
|
342
|
+
|
343
|
+
### UPDATE_INVENTORY
|
344
|
+
|
345
|
+
- Initialized with `client_attrs = { access_token: "access_token1" }`
|
346
|
+
```ruby
|
347
|
+
client.update_inventory([{sku_ref: "m9qqs"}], "zrn61", "wy3xz")
|
348
|
+
# [PUT] /catalogs/zrn61/locations/wy3xz/inventory with { headers: { "X-Access-Token": "access_token1" }, body: "[{\"sku_ref\":\"m9qqs\"}]"}
|
349
|
+
```
|
350
|
+
- Initialized with `client_attrs = { access_token: "access_token1" }`
|
351
|
+
```ruby
|
352
|
+
client.update_inventory([{sku_ref: "m9qqs"}], "zrn61")
|
353
|
+
# [PUT] /catalogs/zrn61/location/inventory with { headers: { "X-Access-Token": "access_token1" }, body: "[{\"sku_ref\":\"m9qqs\"}]"}
|
354
|
+
```
|
355
|
+
- Initialized with `client_attrs = { access_token: "access_token1", catalog_id: "zrn61" }`
|
356
|
+
```ruby
|
357
|
+
client.update_inventory([{sku_ref: "m9qqs"}])
|
358
|
+
# [PUT] /catalogs/zrn61/location/inventory with { headers: { "X-Access-Token": "access_token1" }, body: "[{\"sku_ref\":\"m9qqs\"}]"}
|
359
|
+
```
|
360
|
+
|
361
|
+
### PATCH_INVENTORY
|
362
|
+
|
363
|
+
- Initialized with `client_attrs = { access_token: "access_token1" }`
|
364
|
+
```ruby
|
365
|
+
client.patch_inventory([{sku_ref: "m9qqs"}], "zrn61", "wy3xz")
|
366
|
+
# [PATCH] /catalogs/zrn61/locations/wy3xz/inventory with { headers: { "X-Access-Token": "access_token1" }, body: "[{\"sku_ref\":\"m9qqs\"}]"}
|
367
|
+
```
|
368
|
+
- Initialized with `client_attrs = { access_token: "access_token1" }`
|
369
|
+
```ruby
|
370
|
+
client.patch_inventory([{sku_ref: "m9qqs"}], "zrn61")
|
371
|
+
# [PATCH] /catalogs/zrn61/location/inventory with { headers: { "X-Access-Token": "access_token1" }, body: "[{\"sku_ref\":\"m9qqs\"}]"}
|
372
|
+
```
|
373
|
+
- Initialized with `client_attrs = { access_token: "access_token1", catalog_id: "zrn61" }`
|
374
|
+
```ruby
|
375
|
+
client.patch_inventory([{sku_ref: "m9qqs"}])
|
376
|
+
# [PATCH] /catalogs/zrn61/location/inventory with { headers: { "X-Access-Token": "access_token1" }, body: "[{\"sku_ref\":\"m9qqs\"}]"}
|
377
|
+
```
|
378
|
+
|
379
|
+
### CREATE_LOYALTY_CARD
|
380
|
+
|
381
|
+
- Initialized with `client_attrs = { access_token: "access_token1" }`
|
382
|
+
```ruby
|
383
|
+
client.create_loyalty_card({ name: "bonus" }, "wy3xz")
|
384
|
+
# [POST] /customer_lists/wy3xz/loyalty_cards with { headers: { "X-Access-Token": "access_token1" }, body: { name: "bonus" } }
|
385
|
+
```
|
386
|
+
- Initialized with `client_attrs = { access_token: "access_token1", customer_list_id: "zrk6b" }`
|
387
|
+
```ruby
|
388
|
+
client.create_loyalty_card({ name: "bonus" })
|
389
|
+
# [POST] /customer_lists/zrk6b/loyalty_cards with { headers: { "X-Access-Token": "access_token1" }, body: { name: "bonus" } }
|
390
|
+
```
|
391
|
+
|
392
|
+
### CREATE_LOYALTY_OPERATION
|
393
|
+
|
394
|
+
- Initialized with `client_attrs = { access_token: "access_token1" }`
|
395
|
+
```ruby
|
396
|
+
client.create_loyalty_operation("zrk6b", { delta: "4.2" }, "wy3xz")
|
397
|
+
# [POST] /customer_lists/wy3xz/loyalty_cards/zrk6b/operations with { headers: { "X-Access-Token": "access_token1" }, body: { delta: "4.2" } }
|
398
|
+
```
|
399
|
+
- Initialized with `client_attrs = { access_token: "access_token1", customer_list_id: "q2brk" }`
|
400
|
+
```ruby
|
401
|
+
client.create_loyalty_operation("zrk6b", { delta: "4.2" })
|
402
|
+
# [POST] /customer_lists/q2brk/loyalty_cards/zrk6b/operations with { headers: { "X-Access-Token": "access_token1" }, body: { delta: "4.2" } }
|
403
|
+
```
|
data/lib/hubrise_client/base.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module HubriseClient
|
2
3
|
class Base
|
3
4
|
USE_HTTPS = true
|
4
|
-
DEFAULT_API_HOST = "api.hubrise.com"
|
5
|
-
DEFAULT_API_PORT = "443"
|
6
|
-
DEFAULT_OAUTH_HOST = "manager.hubrise.com"
|
7
|
-
DEFAULT_OAUTH_PORT = "443"
|
5
|
+
DEFAULT_API_HOST = "api.hubrise.com"
|
6
|
+
DEFAULT_API_PORT = "443"
|
7
|
+
DEFAULT_OAUTH_HOST = "manager.hubrise.com"
|
8
|
+
DEFAULT_OAUTH_PORT = "443"
|
8
9
|
|
9
10
|
attr_accessor :access_token,
|
10
11
|
:app_instance_id,
|
@@ -16,7 +17,7 @@ module HubriseClient
|
|
16
17
|
:logger,
|
17
18
|
:request_callback
|
18
19
|
|
19
|
-
def initialize(app_id, app_secret, params = {})
|
20
|
+
def initialize(app_id, app_secret, params = {})
|
20
21
|
@app_id = app_id
|
21
22
|
@app_secret = app_secret
|
22
23
|
@api_host = params[:api_host] || DEFAULT_API_HOST
|
@@ -29,7 +30,7 @@ module HubriseClient
|
|
29
30
|
initialize_scope_params(params)
|
30
31
|
|
31
32
|
@verbous = !!params[:verbous]
|
32
|
-
unless (@logger = params[:logger])
|
33
|
+
unless (@logger = params[:logger])
|
33
34
|
@logger = Logger.new(STDOUT)
|
34
35
|
@logger.level = @verbous ? Logger::DEBUG : Logger::WARN
|
35
36
|
end
|
@@ -47,9 +48,9 @@ module HubriseClient
|
|
47
48
|
|
48
49
|
def authorize!(authorization_code)
|
49
50
|
api_response = api_request(oauth2_hubrise_hostname_with_version).perform(:post, "/token",
|
50
|
-
|
51
|
-
|
52
|
-
|
51
|
+
client_id: @app_id,
|
52
|
+
client_secret: @app_secret,
|
53
|
+
code: authorization_code)
|
53
54
|
|
54
55
|
case api_response.code
|
55
56
|
when "200"
|
@@ -65,7 +66,7 @@ module HubriseClient
|
|
65
66
|
|
66
67
|
protected
|
67
68
|
|
68
|
-
def initialize_scope_params(params)
|
69
|
+
def initialize_scope_params(params)
|
69
70
|
@access_token = params[:access_token] || params["access_token"]
|
70
71
|
@app_instance_id = params[:app_instance_id] || params["app_instance_id"]
|
71
72
|
@user_id = params[:user_id] || params["user_id"]
|
@@ -78,9 +79,13 @@ module HubriseClient
|
|
78
79
|
def call_api(path, method = :get, data: {}, headers: {}, json: true)
|
79
80
|
raise(HubriseAccessTokenMissing) if @access_token.nil?
|
80
81
|
|
81
|
-
api_request("#{@api_host}:#{@api_port}/#{version}", @access_token)
|
82
|
-
|
83
|
-
|
82
|
+
api_request("#{@api_host}:#{@api_port}/#{version}", @access_token)
|
83
|
+
.perform(method,
|
84
|
+
path,
|
85
|
+
data,
|
86
|
+
json: json,
|
87
|
+
headers: headers,
|
88
|
+
&@request_callback)
|
84
89
|
end
|
85
90
|
|
86
91
|
def api_request(hostname, access_token = nil)
|
@@ -88,7 +93,7 @@ module HubriseClient
|
|
88
93
|
hostname: hostname,
|
89
94
|
access_token: access_token,
|
90
95
|
use_https: @use_https,
|
91
|
-
logger: @logger
|
96
|
+
logger: @verbous && @logger
|
92
97
|
)
|
93
98
|
end
|
94
99
|
|
@@ -1,12 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module HubriseClient
|
2
3
|
class Request
|
3
4
|
REQUESTS_HASH = {
|
4
5
|
get: Net::HTTP::Get,
|
5
6
|
post: Net::HTTP::Post,
|
6
7
|
put: Net::HTTP::Put,
|
7
|
-
|
8
|
+
patch: Net::HTTP::Patch,
|
9
|
+
delete: Net::HTTP::Delete,
|
8
10
|
}.freeze
|
9
11
|
|
12
|
+
attr_reader :http_request
|
10
13
|
def initialize(hostname:, access_token: nil, use_https: false, logger: nil)
|
11
14
|
@hostname = hostname
|
12
15
|
@access_token = access_token
|
@@ -15,23 +18,24 @@ module HubriseClient
|
|
15
18
|
@logger = logger
|
16
19
|
end
|
17
20
|
|
18
|
-
def perform(method, path, data, json: true, headers: {}
|
19
|
-
uri
|
20
|
-
http_request
|
21
|
-
http_response = perform_request(uri, http_request)
|
21
|
+
def perform(method, path, data, json: true, headers: {})
|
22
|
+
uri = URI.parse(@protocol + "://" + @hostname + path)
|
23
|
+
@http_request = build_request(uri, method, data, json: json, headers: headers)
|
24
|
+
@http_response = perform_request(uri, @http_request)
|
25
|
+
@response = Response.new(@http_response)
|
22
26
|
|
23
|
-
case http_response
|
27
|
+
case @http_response
|
24
28
|
when Net::HTTPUnauthorized
|
25
29
|
raise InvalidHubriseToken
|
26
30
|
else
|
27
|
-
raise(HubriseError, "Unexpected error") if http_response.code.start_with?("5")
|
31
|
+
raise(HubriseError, "Unexpected error") if @http_response.code.start_with?("5")
|
28
32
|
|
29
|
-
|
33
|
+
@response
|
30
34
|
end
|
31
35
|
rescue Errno::ECONNREFUSED
|
32
36
|
raise HubriseError, "API is not reachable"
|
33
37
|
ensure
|
34
|
-
yield(
|
38
|
+
yield(self, @response) if @http_request && block_given?
|
35
39
|
end
|
36
40
|
|
37
41
|
protected
|
@@ -40,9 +44,7 @@ module HubriseClient
|
|
40
44
|
headers["X-Access-Token"] = @access_token if @access_token
|
41
45
|
|
42
46
|
if method == :get
|
43
|
-
|
44
|
-
uri = add_params_to_uri(uri, data)
|
45
|
-
end
|
47
|
+
uri = add_params_to_uri(uri, data) if data&.count&.positive?
|
46
48
|
|
47
49
|
data = nil
|
48
50
|
elsif json
|
@@ -1,7 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module HubriseClient
|
2
3
|
class Response
|
3
4
|
attr_reader :code, :failed, :data, :error_type, :error_message, :errors, :http_response
|
4
|
-
|
5
|
+
alias_method :failed?, :failed
|
5
6
|
|
6
7
|
def initialize(http_response)
|
7
8
|
@http_response = http_response
|
@@ -9,7 +10,7 @@ module HubriseClient
|
|
9
10
|
|
10
11
|
json_body = begin
|
11
12
|
JSON.parse(http_response.body)
|
12
|
-
rescue
|
13
|
+
rescue JSON::ParserError
|
13
14
|
nil
|
14
15
|
end
|
15
16
|
|
@@ -17,9 +18,9 @@ module HubriseClient
|
|
17
18
|
|
18
19
|
case http_response
|
19
20
|
when Net::HTTPSuccess
|
20
|
-
@failed
|
21
|
+
@failed = false
|
21
22
|
else
|
22
|
-
@failed
|
23
|
+
@failed = true
|
23
24
|
if json_body
|
24
25
|
@errors = json_body["errors"]
|
25
26
|
@error_type = json_body["error_type"]
|
data/lib/hubrise_client/v1.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# rubocop:disable Naming/AccessorMethodName
|
2
3
|
module HubriseClient
|
3
4
|
class V1 < Base
|
@@ -111,7 +112,7 @@ module HubriseClient
|
|
111
112
|
|
112
113
|
def update_customer(customer_id, params, customer_list_id = nil)
|
113
114
|
call_api("/customer_lists/#{customer_list_id_fallback(customer_list_id)}/customers/#{customer_id}", :put,
|
114
|
-
|
115
|
+
data: params)
|
115
116
|
end
|
116
117
|
|
117
118
|
# --------------------
|
@@ -150,8 +151,8 @@ module HubriseClient
|
|
150
151
|
# --------------------
|
151
152
|
def create_image(data, mime_type, catalog_id = nil)
|
152
153
|
call_api("/catalogs/#{catalog_id_fallback(catalog_id)}/images", :post, data: data,
|
153
|
-
|
154
|
-
|
154
|
+
headers: { "Content-Type" => mime_type },
|
155
|
+
json: false)
|
155
156
|
end
|
156
157
|
|
157
158
|
def get_image(image_id, catalog_id = nil)
|
@@ -162,6 +163,49 @@ module HubriseClient
|
|
162
163
|
call_api("/catalogs/#{catalog_id_fallback(catalog_id)}/images/#{image_id}/data")
|
163
164
|
end
|
164
165
|
|
166
|
+
# --------------------
|
167
|
+
# Inventory
|
168
|
+
# --------------------
|
169
|
+
def get_inventory(catalog_id = nil, location_id = nil)
|
170
|
+
endpoint = inventory_endpoint(catalog_id, location_id)
|
171
|
+
call_api(endpoint)
|
172
|
+
end
|
173
|
+
|
174
|
+
def update_inventory(params, catalog_id = nil, location_id = nil)
|
175
|
+
endpoint = inventory_endpoint(catalog_id, location_id)
|
176
|
+
call_api(endpoint, :put, data: params)
|
177
|
+
end
|
178
|
+
|
179
|
+
def patch_inventory(params, catalog_id = nil, location_id = nil)
|
180
|
+
endpoint = inventory_endpoint(catalog_id, location_id)
|
181
|
+
call_api(endpoint, :patch, data: params)
|
182
|
+
end
|
183
|
+
|
184
|
+
def inventory_endpoint(catalog_id = nil, location_id = nil)
|
185
|
+
if location_id
|
186
|
+
"/catalogs/#{catalog_id_fallback(catalog_id)}/locations/#{location_id}/inventory"
|
187
|
+
else
|
188
|
+
"/catalogs/#{catalog_id_fallback(catalog_id)}/location/inventory"
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
private :inventory_endpoint
|
193
|
+
|
194
|
+
# --------------------
|
195
|
+
# Loyalty cards
|
196
|
+
# --------------------
|
197
|
+
def create_loyalty_card(params, customer_list_id = nil)
|
198
|
+
call_api("/customer_lists/#{customer_list_id_fallback(customer_list_id)}/loyalty_cards", :post, data: params)
|
199
|
+
end
|
200
|
+
|
201
|
+
def create_loyalty_operation(loyalty_card_id, params, customer_list_id = nil)
|
202
|
+
call_api(
|
203
|
+
"/customer_lists/#{customer_list_id_fallback(customer_list_id)}/loyalty_cards/#{loyalty_card_id}/operations",
|
204
|
+
:post,
|
205
|
+
data: params
|
206
|
+
)
|
207
|
+
end
|
208
|
+
|
165
209
|
private
|
166
210
|
|
167
211
|
def customer_list_id_fallback(customer_list_id)
|
data/lib/hubrise_client.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hubrise_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Antoine Monnier
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2021-12-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -102,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '0'
|
104
104
|
requirements: []
|
105
|
-
rubygems_version: 3.
|
105
|
+
rubygems_version: 3.1.2
|
106
106
|
signing_key:
|
107
107
|
specification_version: 4
|
108
108
|
summary: HubRise Ruby client
|