hubrise_client 2.0.1 → 2.0.4
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 +94 -4
- data/Rakefile +2 -1
- data/V1_ENDPOINTS.md +372 -225
- data/lib/hubrise_client/base.rb +45 -30
- data/lib/hubrise_client/request.rb +59 -27
- data/lib/hubrise_client/response.rb +33 -7
- 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: 58aebdf2e9ba790c1303eacf547aaaf5ccdf92f360a63195e6a6e9db1e200b42
|
4
|
+
data.tar.gz: 3776550d4ef358b832c1e4f02094da4ef352b8fddb5ce2d174ae092c6f6ce504
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38787fe30bacac00daae63823a52d69f10347380276afb7b8e9c87386560aed7d97300c66a9abe29dcc03c3ccb3de43f11b9cfca14b3c2d432fd8426ab8ffe4c
|
7
|
+
data.tar.gz: c8304210fb9fcb47b574d131b690f3e3ac11e7be4ce3633e37ef64aa320a3fcf3a1615066789558aa331bd18b5e61c54651d2e2ecbb6fd0fc681e9e6fa777934
|
data/README.md
CHANGED
@@ -1,8 +1,98 @@
|
|
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
|
+
```
|
8
10
|
|
11
|
+
Or install via [gem](http://rubygems.org/)
|
12
|
+
|
13
|
+
```bash
|
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
|
+
```
|
81
|
+
|
82
|
+
## Pagination
|
83
|
+
|
84
|
+
`#next_page?`, `#next_page` and `#each_page` might be helpful when working with paginated [endpoints](https://www.hubrise.com/developers/api/general-concepts/#pagination)
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
response = client.get_all_customers
|
88
|
+
|
89
|
+
response.next_page?
|
90
|
+
# => true
|
91
|
+
|
92
|
+
response.next_page.data
|
93
|
+
# => [{ first_name:... }]
|
94
|
+
|
95
|
+
response.each_page do |page_response|
|
96
|
+
page_response.data
|
97
|
+
# => [{ first_name:... }]
|
98
|
+
end
|
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,
|
@@ -13,21 +14,23 @@ module HubriseClient
|
|
13
14
|
:location_id,
|
14
15
|
:catalog_id,
|
15
16
|
:customer_list_id,
|
16
|
-
:logger
|
17
|
+
:logger,
|
18
|
+
:request_callback
|
17
19
|
|
18
|
-
def initialize(app_id, app_secret, params = {})
|
19
|
-
@app_id
|
20
|
+
def initialize(app_id, app_secret, params = {})
|
21
|
+
@app_id = app_id
|
20
22
|
@app_secret = app_secret
|
21
|
-
@api_host
|
22
|
-
@api_port
|
23
|
+
@api_host = params[:api_host] || DEFAULT_API_HOST
|
24
|
+
@api_port = params[:api_port] || DEFAULT_API_PORT
|
23
25
|
@oauth_host = params[:oauth_host] || DEFAULT_OAUTH_HOST
|
24
26
|
@oauth_port = params[:oauth_port] || DEFAULT_OAUTH_PORT
|
25
|
-
@use_https
|
27
|
+
@use_https = !!params.fetch(:use_https, USE_HTTPS)
|
28
|
+
@request_callback = params[:request_callback]
|
26
29
|
|
27
30
|
initialize_scope_params(params)
|
28
31
|
|
29
32
|
@verbous = !!params[:verbous]
|
30
|
-
unless (@logger = params[:logger])
|
33
|
+
unless (@logger = params[:logger])
|
31
34
|
@logger = Logger.new(STDOUT)
|
32
35
|
@logger.level = @verbous ? Logger::DEBUG : Logger::WARN
|
33
36
|
end
|
@@ -44,10 +47,13 @@ module HubriseClient
|
|
44
47
|
end
|
45
48
|
|
46
49
|
def authorize!(authorization_code)
|
47
|
-
api_response = api_request(
|
48
|
-
|
49
|
-
|
50
|
-
|
50
|
+
api_response = api_request(
|
51
|
+
oauth2_hubrise_hostname_with_version, "/token", :post, data: {
|
52
|
+
client_id: @app_id,
|
53
|
+
client_secret: @app_secret,
|
54
|
+
code: authorization_code,
|
55
|
+
}
|
56
|
+
).perform
|
51
57
|
|
52
58
|
case api_response.code
|
53
59
|
when "200"
|
@@ -63,29 +69,38 @@ module HubriseClient
|
|
63
69
|
|
64
70
|
protected
|
65
71
|
|
66
|
-
def initialize_scope_params(params)
|
67
|
-
@access_token
|
68
|
-
@app_instance_id
|
69
|
-
@user_id
|
70
|
-
@account_id
|
71
|
-
@location_id
|
72
|
-
@catalog_id
|
72
|
+
def initialize_scope_params(params)
|
73
|
+
@access_token = params[:access_token] || params["access_token"]
|
74
|
+
@app_instance_id = params[:app_instance_id] || params["app_instance_id"]
|
75
|
+
@user_id = params[:user_id] || params["user_id"]
|
76
|
+
@account_id = params[:account_id] || params["account_id"]
|
77
|
+
@location_id = params[:location_id] || params["location_id"]
|
78
|
+
@catalog_id = params[:catalog_id] || params["catalog_id"]
|
73
79
|
@customer_list_id = params[:customer_list_id] || params["customer_list_id"]
|
74
80
|
end
|
75
81
|
|
76
82
|
def call_api(path, method = :get, data: {}, headers: {}, json: true)
|
77
83
|
raise(HubriseAccessTokenMissing) if @access_token.nil?
|
78
84
|
|
79
|
-
api_request(
|
80
|
-
|
85
|
+
api_request(
|
86
|
+
"#{@api_host}:#{@api_port}/#{version}", path, method, data: data,
|
87
|
+
json: json,
|
88
|
+
headers: headers,
|
89
|
+
access_token: @access_token,
|
90
|
+
callback: @request_callback
|
91
|
+
).perform
|
81
92
|
end
|
82
93
|
|
83
|
-
def api_request(hostname,
|
84
|
-
Request.
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
94
|
+
def api_request(hostname, path, method, attrs = {})
|
95
|
+
Request.from_h(
|
96
|
+
{
|
97
|
+
hostname: hostname,
|
98
|
+
path: path,
|
99
|
+
method: method,
|
100
|
+
use_https: @use_https,
|
101
|
+
logger: @verbous && @logger,
|
102
|
+
json: true,
|
103
|
+
}.merge(attrs)
|
89
104
|
)
|
90
105
|
end
|
91
106
|
|
@@ -1,52 +1,82 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module HubriseClient
|
2
|
-
class Request
|
3
|
+
class Request < Struct.new(:hostname,
|
4
|
+
:path,
|
5
|
+
:method,
|
6
|
+
:data,
|
7
|
+
:access_token,
|
8
|
+
:use_https,
|
9
|
+
:logger,
|
10
|
+
:json,
|
11
|
+
:headers,
|
12
|
+
:callback)
|
13
|
+
|
3
14
|
REQUESTS_HASH = {
|
4
15
|
get: Net::HTTP::Get,
|
5
16
|
post: Net::HTTP::Post,
|
6
17
|
put: Net::HTTP::Put,
|
7
|
-
|
18
|
+
patch: Net::HTTP::Patch,
|
19
|
+
delete: Net::HTTP::Delete,
|
8
20
|
}.freeze
|
9
21
|
|
10
|
-
def
|
11
|
-
|
12
|
-
@access_token = access_token
|
13
|
-
@use_https = use_https
|
14
|
-
@protocol = use_https ? "https" : "http"
|
15
|
-
@logger = logger
|
22
|
+
def self.from_h(hash)
|
23
|
+
new(*hash.values_at(*members))
|
16
24
|
end
|
17
25
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
26
|
+
attr_reader :http_request
|
27
|
+
|
28
|
+
def perform
|
29
|
+
@http_request = build_request
|
30
|
+
|
31
|
+
@http_response = perform_request(@http_request)
|
32
|
+
@response = Response.new(@http_response, self)
|
22
33
|
|
23
|
-
case http_response
|
34
|
+
case @http_response
|
24
35
|
when Net::HTTPUnauthorized
|
25
36
|
raise InvalidHubriseToken
|
26
37
|
else
|
27
|
-
raise(HubriseError, "Unexpected error") if http_response.code.start_with?("5")
|
38
|
+
raise(HubriseError, "Unexpected error") if @http_response.code.start_with?("5")
|
28
39
|
|
29
|
-
|
40
|
+
@response
|
30
41
|
end
|
31
42
|
rescue Errno::ECONNREFUSED
|
32
43
|
raise HubriseError, "API is not reachable"
|
44
|
+
ensure
|
45
|
+
callback.call(self, @response) if @http_request && callback
|
46
|
+
end
|
47
|
+
|
48
|
+
def next_page_request(new_cursor)
|
49
|
+
new_data = data || {}
|
50
|
+
new_data[:cursor] = new_cursor
|
51
|
+
|
52
|
+
Request.from_h(to_h.merge(data: new_data))
|
33
53
|
end
|
34
54
|
|
35
55
|
protected
|
36
56
|
|
37
|
-
def
|
38
|
-
|
57
|
+
def protocol
|
58
|
+
use_https ? "https" : "http"
|
59
|
+
end
|
60
|
+
|
61
|
+
def build_request
|
62
|
+
request_uri = URI.parse(protocol + "://" + hostname + path)
|
63
|
+
|
64
|
+
request_headers = headers || {}
|
65
|
+
request_headers["X-Access-Token"] = access_token if access_token
|
66
|
+
|
67
|
+
request_body_data = nil
|
39
68
|
|
40
69
|
if method == :get
|
41
|
-
|
42
|
-
data = nil
|
70
|
+
request_uri = add_params_to_uri(request_uri, data) if data && !data.empty?
|
43
71
|
elsif json
|
44
|
-
|
45
|
-
|
72
|
+
request_headers["Content-Type"] ||= "application/json"
|
73
|
+
request_body_data = data.to_json
|
74
|
+
else
|
75
|
+
request_body_data = data
|
46
76
|
end
|
47
77
|
|
48
|
-
REQUESTS_HASH[method].new(
|
49
|
-
request.body =
|
78
|
+
REQUESTS_HASH[method].new(request_uri, request_headers).tap do |request|
|
79
|
+
request.body = request_body_data
|
50
80
|
end
|
51
81
|
end
|
52
82
|
|
@@ -55,10 +85,12 @@ module HubriseClient
|
|
55
85
|
uri
|
56
86
|
end
|
57
87
|
|
58
|
-
def perform_request(
|
59
|
-
|
60
|
-
|
61
|
-
http.
|
88
|
+
def perform_request(request)
|
89
|
+
uri = request.uri
|
90
|
+
|
91
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
92
|
+
http.use_ssl = use_https
|
93
|
+
http.set_debug_output(logger) if logger
|
62
94
|
http.request(request)
|
63
95
|
end
|
64
96
|
end
|
@@ -1,15 +1,17 @@
|
|
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
|
-
def initialize(http_response)
|
7
|
-
@http_response
|
8
|
-
@
|
7
|
+
def initialize(http_response, request)
|
8
|
+
@http_response = http_response
|
9
|
+
@request = request
|
10
|
+
@code = http_response.code
|
9
11
|
|
10
12
|
json_body = begin
|
11
13
|
JSON.parse(http_response.body)
|
12
|
-
rescue
|
14
|
+
rescue JSON::ParserError
|
13
15
|
nil
|
14
16
|
end
|
15
17
|
|
@@ -17,9 +19,9 @@ module HubriseClient
|
|
17
19
|
|
18
20
|
case http_response
|
19
21
|
when Net::HTTPSuccess
|
20
|
-
@failed
|
22
|
+
@failed = false
|
21
23
|
else
|
22
|
-
@failed
|
24
|
+
@failed = true
|
23
25
|
if json_body
|
24
26
|
@errors = json_body["errors"]
|
25
27
|
@error_type = json_body["error_type"]
|
@@ -31,5 +33,29 @@ module HubriseClient
|
|
31
33
|
def retry_after
|
32
34
|
http_response.is_a?(Net::HTTPTooManyRequests) && http_response["retry-after"].to_i
|
33
35
|
end
|
36
|
+
|
37
|
+
def each_page
|
38
|
+
return enum_for(:each_page) unless block_given?
|
39
|
+
|
40
|
+
yield(self)
|
41
|
+
|
42
|
+
response = self
|
43
|
+
while response.next_page?
|
44
|
+
response = response.next_page
|
45
|
+
yield(response)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def next_page?
|
50
|
+
!!cursor_next
|
51
|
+
end
|
52
|
+
|
53
|
+
def next_page
|
54
|
+
@request.next_page_request(cursor_next).perform
|
55
|
+
end
|
56
|
+
|
57
|
+
def cursor_next
|
58
|
+
http_response["X-Cursor-Next"]
|
59
|
+
end
|
34
60
|
end
|
35
61
|
end
|
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.4
|
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: 2022-04-21 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
|