hubrise_client 2.0.2 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7763aa9e092db7309780e3217dc381191e49141d8120a3dfd38791ff4af47e9c
4
- data.tar.gz: 3e8288142e201c52adf9ca05b3607f0f37c8a6ffad4a2df6c8c271395e226fff
3
+ metadata.gz: f10358d2bbba5919834bc9209feafaa301aee68fa07153aad77a5e31c3844a28
4
+ data.tar.gz: 4d881d4e77a8df23a4dfc784e3b8505db21859dee1f69bfcd18e2c683b5e1044
5
5
  SHA512:
6
- metadata.gz: f683839ae7f97389a8ff392d386587f6c47df0ab1b68da3c733dfd35516be74bdb20d51da1770b15b83bc08eee9bc234c09410bb845f8729f842996d9d3641e7
7
- data.tar.gz: fcefcc27355f4df841b4624506dafc25d2abd0399ef14779bb72b3c39d25ed27a922f4cd1a4d415533659104c6c4f27585b9f35a0a5266a537e8fa11d5e1ef44
6
+ metadata.gz: 865672a43693575a2493bd2b2edf3e2e1ef95268065bf6bfa9c5398045fda40537c501f0f74741f36443541491c84a4b10ccaabb9c3dafcb7e22c80e2bfb31fd
7
+ data.tar.gz: eeb709dfdb5216f72d15afe73f53913847744e54c70f6119bf24d2e5377d79bbc118536544b5b6a8a70b82b3ca115dbc1503b53b56bb16527bd5f7aa06e72439
data/README.md CHANGED
@@ -1,12 +1,80 @@
1
- # hubrise_client
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
- To upload the latest version to RubyGems.org:
3
+ # Installation
4
4
 
5
- 1. Increase version in `lib/hubrise_client/version.rb` and commit
5
+ Add `hubrise_client` to your `Gemfile`:
6
6
 
7
- 2. Build & publish (assuming the new version is `2.0.1`):
7
+ ```ruby
8
+ gem 'hubrise_client'
9
+ ```
10
+
11
+ Or install via [gem](http://rubygems.org/)
8
12
 
9
13
  ```bash
10
- gem build hubrise_client
11
- gem push hubrise_client-2.0.1.gem
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
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "rake"
2
3
  require "rake/testtask"
3
4
 
@@ -7,4 +8,4 @@ Rake::TestTask.new do |t|
7
8
  t.verbose = false
8
9
  end
9
10
 
10
- task default: :test
11
+ task(default: :test)
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
- - 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
- ```
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
- - 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
- ```
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
- - 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
- ```
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
- - 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
- ```
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
- - 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
- ```
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
- - 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
- ```
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
- - 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
- ```
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
- - 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
- ```
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
- - 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
- ```
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
- - 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
- ```
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
- - 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
- ```
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
- - 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
- ```
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
- - 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
- ```
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
- - 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
- ```
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
- - 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
- ```
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
- - 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
- ```
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
- - 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
- ```
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
- - 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
- ```
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
- - 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
- ```
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
- - 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
- ```
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
- - 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
- ```
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
- - 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
- ```
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
- - 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
- ```
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
- - 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
- ```
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
- - 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
- ```
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
- - 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
- ```
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
- - 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
- ```
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
- - 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
- ```
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
- - 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
- ```
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
- - 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
- ```
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
- - 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
- ```
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
+ ```
@@ -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".freeze
5
- DEFAULT_API_PORT = "443".freeze
6
- DEFAULT_OAUTH_HOST = "manager.hubrise.com".freeze
7
- DEFAULT_OAUTH_PORT = "443".freeze
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 = {}) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
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]) # rubocop:disable Style/GuardClause
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
- client_id: @app_id,
51
- client_secret: @app_secret,
52
- code: authorization_code)
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) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/AbcSize, Metrics/LineLength
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).perform(method, path, data, json: json,
82
- headers: headers,
83
- &@request_callback)
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
- delete: Net::HTTP::Delete
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: {}, callback: nil)
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)
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
- Response.new(http_response)
33
+ @response
30
34
  end
31
35
  rescue Errno::ECONNREFUSED
32
36
  raise HubriseError, "API is not reachable"
33
37
  ensure
34
- yield(http_request, http_response) if http_request && block_given?
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
- if data && data.count > 0
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
- alias failed? failed
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 StandardError
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 = false
21
+ @failed = false
21
22
  else
22
- @failed = true
23
+ @failed = true
23
24
  if json_body
24
25
  @errors = json_body["errors"]
25
26
  @error_type = json_body["error_type"]
@@ -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
- data: params)
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
- headers: { "Content-Type" => mime_type },
154
- json: false)
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)
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module HubriseClient
2
- VERSION = "2.0.2".freeze
3
+ VERSION = "2.0.3"
3
4
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "net/http"
2
3
  require "json"
3
4
  require "uri"
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.2
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: 2020-01-31 00:00:00.000000000 Z
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.0.3
105
+ rubygems_version: 3.1.2
106
106
  signing_key:
107
107
  specification_version: 4
108
108
  summary: HubRise Ruby client