square.rb 26.1.0.20230119 → 27.0.0.20230419

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -0
  3. data/lib/square/api/apple_pay_api.rb +14 -30
  4. data/lib/square/api/bank_accounts_api.rb +40 -90
  5. data/lib/square/api/base_api.rb +42 -42
  6. data/lib/square/api/booking_custom_attributes_api.rb +171 -336
  7. data/lib/square/api/bookings_api.rb +140 -263
  8. data/lib/square/api/cards_api.rb +58 -120
  9. data/lib/square/api/cash_drawers_api.rb +47 -103
  10. data/lib/square/api/catalog_api.rb +200 -426
  11. data/lib/square/api/checkout_api.rb +86 -176
  12. data/lib/square/api/customer_custom_attributes_api.rb +157 -310
  13. data/lib/square/api/customer_groups_api.rb +69 -145
  14. data/lib/square/api/customer_segments_api.rb +26 -61
  15. data/lib/square/api/customers_api.rb +147 -294
  16. data/lib/square/api/devices_api.rb +42 -89
  17. data/lib/square/api/disputes_api.rb +132 -290
  18. data/lib/square/api/employees_api.rb +28 -63
  19. data/lib/square/api/gift_card_activities_api.rb +34 -66
  20. data/lib/square/api/gift_cards_api.rb +109 -207
  21. data/lib/square/api/inventory_api.rb +204 -391
  22. data/lib/square/api/invoices_api.rb +121 -240
  23. data/lib/square/api/labor_api.rb +223 -459
  24. data/lib/square/api/location_custom_attributes_api.rb +173 -338
  25. data/lib/square/api/locations_api.rb +54 -112
  26. data/lib/square/api/loyalty_api.rb +283 -535
  27. data/lib/square/api/merchants_api.rb +25 -60
  28. data/lib/square/api/mobile_authorization_api.rb +14 -30
  29. data/lib/square/api/o_auth_api.rb +54 -109
  30. data/lib/square/api/order_custom_attributes_api.rb +174 -339
  31. data/lib/square/api/orders_api.rb +115 -222
  32. data/lib/square/api/payments_api.rb +118 -217
  33. data/lib/square/api/payouts_api.rb +54 -107
  34. data/lib/square/api/refunds_api.rb +59 -104
  35. data/lib/square/api/sites_api.rb +11 -28
  36. data/lib/square/api/snippets_api.rb +42 -90
  37. data/lib/square/api/subscriptions_api.rb +150 -299
  38. data/lib/square/api/team_api.rb +114 -224
  39. data/lib/square/api/terminal_api.rb +162 -328
  40. data/lib/square/api/transactions_api.rb +64 -128
  41. data/lib/square/api/v1_transactions_api.rb +155 -296
  42. data/lib/square/api/vendors_api.rb +100 -193
  43. data/lib/square/api/webhook_subscriptions_api.rb +124 -244
  44. data/lib/square/api_helper.rb +1 -437
  45. data/lib/square/client.rb +77 -47
  46. data/lib/square/configuration.rb +28 -53
  47. data/lib/square/exceptions/api_exception.rb +1 -11
  48. data/lib/square/http/api_response.rb +13 -19
  49. data/lib/square/http/auth/o_auth2.rb +14 -7
  50. data/lib/square/http/http_call_back.rb +1 -15
  51. data/lib/square/http/http_method_enum.rb +1 -4
  52. data/lib/square/http/http_request.rb +1 -45
  53. data/lib/square/http/http_response.rb +1 -20
  54. data/lib/square/utilities/date_time_helper.rb +1 -146
  55. data/lib/square/utilities/file_wrapper.rb +5 -5
  56. data/lib/square.rb +6 -6
  57. data/spec/user_journey_spec.rb +2 -2
  58. data/test/api/api_test_base.rb +13 -5
  59. data/test/api/test_catalog_api.rb +5 -4
  60. data/test/api/test_customers_api.rb +3 -2
  61. data/test/api/test_employees_api.rb +4 -3
  62. data/test/api/test_labor_api.rb +6 -5
  63. data/test/api/test_locations_api.rb +3 -2
  64. data/test/api/test_merchants_api.rb +4 -3
  65. data/test/api/test_payments_api.rb +4 -3
  66. data/test/api/test_refunds_api.rb +4 -3
  67. metadata +11 -111
  68. data/lib/square/exceptions/validation_exception.rb +0 -13
  69. data/lib/square/http/faraday_client.rb +0 -93
  70. data/lib/square/http/http_client.rb +0 -118
  71. data/test/test_helper.rb +0 -89
@@ -1,89 +1,55 @@
1
1
  module Square
2
2
  # InventoryApi
3
3
  class InventoryApi < BaseApi
4
- def initialize(config, http_call_back: nil)
5
- super(config, http_call_back: http_call_back)
6
- end
7
-
8
4
  # Deprecated version of
9
- # [RetrieveInventoryAdjustment]($e/Inventory/RetrieveInventoryAdjustment)
10
- # after the endpoint URL
5
+ # [RetrieveInventoryAdjustment](api-endpoint:Inventory-RetrieveInventoryAdju
6
+ # stment) after the endpoint URL
11
7
  # is updated to conform to the standard convention.
12
8
  # @param [String] adjustment_id Required parameter: ID of the
13
- # [InventoryAdjustment]($m/InventoryAdjustment) to retrieve.
9
+ # [InventoryAdjustment](entity:InventoryAdjustment) to retrieve.
14
10
  # @return [RetrieveInventoryAdjustmentResponse Hash] response from the API call
15
11
  def deprecated_retrieve_inventory_adjustment(adjustment_id:)
16
12
  warn 'Endpoint deprecated_retrieve_inventory_adjustment in InventoryApi '\
17
13
  'is deprecated'
18
- # Prepare query url.
19
- _query_builder = config.get_base_uri
20
- _query_builder << '/v2/inventory/adjustment/{adjustment_id}'
21
- _query_builder = APIHelper.append_url_with_template_parameters(
22
- _query_builder,
23
- 'adjustment_id' => { 'value' => adjustment_id, 'encode' => true }
24
- )
25
- _query_url = APIHelper.clean_url _query_builder
26
-
27
- # Prepare headers.
28
- _headers = {
29
- 'accept' => 'application/json'
30
- }
31
-
32
- # Prepare and execute HttpRequest.
33
- _request = config.http_client.get(
34
- _query_url,
35
- headers: _headers
36
- )
37
- OAuth2.apply(config, _request)
38
- _response = execute_request(_request)
39
-
40
- # Return appropriate response type.
41
- decoded = APIHelper.json_deserialize(_response.raw_body)
42
- _errors = APIHelper.map_response(decoded, ['errors'])
43
- ApiResponse.new(
44
- _response, data: decoded, errors: _errors
45
- )
14
+ new_api_call_builder
15
+ .request(new_request_builder(HttpMethodEnum::GET,
16
+ '/v2/inventory/adjustment/{adjustment_id}',
17
+ 'default')
18
+ .template_param(new_parameter(adjustment_id, key: 'adjustment_id')
19
+ .should_encode(true))
20
+ .header_param(new_parameter('application/json', key: 'accept'))
21
+ .auth(Single.new('global')))
22
+ .response(new_response_handler
23
+ .deserializer(APIHelper.method(:json_deserialize))
24
+ .is_api_response(true)
25
+ .convertor(ApiResponse.method(:create)))
26
+ .execute
46
27
  end
47
28
 
48
29
  # Returns the [InventoryAdjustment]($m/InventoryAdjustment) object
49
30
  # with the provided `adjustment_id`.
50
31
  # @param [String] adjustment_id Required parameter: ID of the
51
- # [InventoryAdjustment]($m/InventoryAdjustment) to retrieve.
32
+ # [InventoryAdjustment](entity:InventoryAdjustment) to retrieve.
52
33
  # @return [RetrieveInventoryAdjustmentResponse Hash] response from the API call
53
34
  def retrieve_inventory_adjustment(adjustment_id:)
54
- # Prepare query url.
55
- _query_builder = config.get_base_uri
56
- _query_builder << '/v2/inventory/adjustments/{adjustment_id}'
57
- _query_builder = APIHelper.append_url_with_template_parameters(
58
- _query_builder,
59
- 'adjustment_id' => { 'value' => adjustment_id, 'encode' => true }
60
- )
61
- _query_url = APIHelper.clean_url _query_builder
62
-
63
- # Prepare headers.
64
- _headers = {
65
- 'accept' => 'application/json'
66
- }
67
-
68
- # Prepare and execute HttpRequest.
69
- _request = config.http_client.get(
70
- _query_url,
71
- headers: _headers
72
- )
73
- OAuth2.apply(config, _request)
74
- _response = execute_request(_request)
75
-
76
- # Return appropriate response type.
77
- decoded = APIHelper.json_deserialize(_response.raw_body)
78
- _errors = APIHelper.map_response(decoded, ['errors'])
79
- ApiResponse.new(
80
- _response, data: decoded, errors: _errors
81
- )
35
+ new_api_call_builder
36
+ .request(new_request_builder(HttpMethodEnum::GET,
37
+ '/v2/inventory/adjustments/{adjustment_id}',
38
+ 'default')
39
+ .template_param(new_parameter(adjustment_id, key: 'adjustment_id')
40
+ .should_encode(true))
41
+ .header_param(new_parameter('application/json', key: 'accept'))
42
+ .auth(Single.new('global')))
43
+ .response(new_response_handler
44
+ .deserializer(APIHelper.method(:json_deserialize))
45
+ .is_api_response(true)
46
+ .convertor(ApiResponse.method(:create)))
47
+ .execute
82
48
  end
83
49
 
84
50
  # Deprecated version of
85
- # [BatchChangeInventory]($e/Inventory/BatchChangeInventory) after the
86
- # endpoint URL
51
+ # [BatchChangeInventory](api-endpoint:Inventory-BatchChangeInventory) after
52
+ # the endpoint URL
87
53
  # is updated to conform to the standard convention.
88
54
  # @param [BatchChangeInventoryRequest] body Required parameter: An object
89
55
  # containing the fields to POST for the request. See the corresponding
@@ -92,37 +58,25 @@ module Square
92
58
  def deprecated_batch_change_inventory(body:)
93
59
  warn 'Endpoint deprecated_batch_change_inventory in InventoryApi is depr'\
94
60
  'ecated'
95
- # Prepare query url.
96
- _query_builder = config.get_base_uri
97
- _query_builder << '/v2/inventory/batch-change'
98
- _query_url = APIHelper.clean_url _query_builder
99
-
100
- # Prepare headers.
101
- _headers = {
102
- 'accept' => 'application/json',
103
- 'Content-Type' => 'application/json'
104
- }
105
-
106
- # Prepare and execute HttpRequest.
107
- _request = config.http_client.post(
108
- _query_url,
109
- headers: _headers,
110
- parameters: body.to_json
111
- )
112
- OAuth2.apply(config, _request)
113
- _response = execute_request(_request)
114
-
115
- # Return appropriate response type.
116
- decoded = APIHelper.json_deserialize(_response.raw_body)
117
- _errors = APIHelper.map_response(decoded, ['errors'])
118
- ApiResponse.new(
119
- _response, data: decoded, errors: _errors
120
- )
61
+ new_api_call_builder
62
+ .request(new_request_builder(HttpMethodEnum::POST,
63
+ '/v2/inventory/batch-change',
64
+ 'default')
65
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
66
+ .body_param(new_parameter(body))
67
+ .header_param(new_parameter('application/json', key: 'accept'))
68
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
69
+ .auth(Single.new('global')))
70
+ .response(new_response_handler
71
+ .deserializer(APIHelper.method(:json_deserialize))
72
+ .is_api_response(true)
73
+ .convertor(ApiResponse.method(:create)))
74
+ .execute
121
75
  end
122
76
 
123
77
  # Deprecated version of
124
- # [BatchRetrieveInventoryChanges]($e/Inventory/BatchRetrieveInventoryChanges
125
- # ) after the endpoint URL
78
+ # [BatchRetrieveInventoryChanges](api-endpoint:Inventory-BatchRetrieveInvent
79
+ # oryChanges) after the endpoint URL
126
80
  # is updated to conform to the standard convention.
127
81
  # @param [BatchRetrieveInventoryChangesRequest] body Required parameter: An
128
82
  # object containing the fields to POST for the request. See the
@@ -131,37 +85,25 @@ module Square
131
85
  def deprecated_batch_retrieve_inventory_changes(body:)
132
86
  warn 'Endpoint deprecated_batch_retrieve_inventory_changes in InventoryA'\
133
87
  'pi is deprecated'
134
- # Prepare query url.
135
- _query_builder = config.get_base_uri
136
- _query_builder << '/v2/inventory/batch-retrieve-changes'
137
- _query_url = APIHelper.clean_url _query_builder
138
-
139
- # Prepare headers.
140
- _headers = {
141
- 'accept' => 'application/json',
142
- 'Content-Type' => 'application/json'
143
- }
144
-
145
- # Prepare and execute HttpRequest.
146
- _request = config.http_client.post(
147
- _query_url,
148
- headers: _headers,
149
- parameters: body.to_json
150
- )
151
- OAuth2.apply(config, _request)
152
- _response = execute_request(_request)
153
-
154
- # Return appropriate response type.
155
- decoded = APIHelper.json_deserialize(_response.raw_body)
156
- _errors = APIHelper.map_response(decoded, ['errors'])
157
- ApiResponse.new(
158
- _response, data: decoded, errors: _errors
159
- )
88
+ new_api_call_builder
89
+ .request(new_request_builder(HttpMethodEnum::POST,
90
+ '/v2/inventory/batch-retrieve-changes',
91
+ 'default')
92
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
93
+ .body_param(new_parameter(body))
94
+ .header_param(new_parameter('application/json', key: 'accept'))
95
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
96
+ .auth(Single.new('global')))
97
+ .response(new_response_handler
98
+ .deserializer(APIHelper.method(:json_deserialize))
99
+ .is_api_response(true)
100
+ .convertor(ApiResponse.method(:create)))
101
+ .execute
160
102
  end
161
103
 
162
104
  # Deprecated version of
163
- # [BatchRetrieveInventoryCounts]($e/Inventory/BatchRetrieveInventoryCounts)
164
- # after the endpoint URL
105
+ # [BatchRetrieveInventoryCounts](api-endpoint:Inventory-BatchRetrieveInvento
106
+ # ryCounts) after the endpoint URL
165
107
  # is updated to conform to the standard convention.
166
108
  # @param [BatchRetrieveInventoryCountsRequest] body Required parameter: An
167
109
  # object containing the fields to POST for the request. See the
@@ -170,32 +112,20 @@ module Square
170
112
  def deprecated_batch_retrieve_inventory_counts(body:)
171
113
  warn 'Endpoint deprecated_batch_retrieve_inventory_counts in InventoryAp'\
172
114
  'i is deprecated'
173
- # Prepare query url.
174
- _query_builder = config.get_base_uri
175
- _query_builder << '/v2/inventory/batch-retrieve-counts'
176
- _query_url = APIHelper.clean_url _query_builder
177
-
178
- # Prepare headers.
179
- _headers = {
180
- 'accept' => 'application/json',
181
- 'Content-Type' => 'application/json'
182
- }
183
-
184
- # Prepare and execute HttpRequest.
185
- _request = config.http_client.post(
186
- _query_url,
187
- headers: _headers,
188
- parameters: body.to_json
189
- )
190
- OAuth2.apply(config, _request)
191
- _response = execute_request(_request)
192
-
193
- # Return appropriate response type.
194
- decoded = APIHelper.json_deserialize(_response.raw_body)
195
- _errors = APIHelper.map_response(decoded, ['errors'])
196
- ApiResponse.new(
197
- _response, data: decoded, errors: _errors
198
- )
115
+ new_api_call_builder
116
+ .request(new_request_builder(HttpMethodEnum::POST,
117
+ '/v2/inventory/batch-retrieve-counts',
118
+ 'default')
119
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
120
+ .body_param(new_parameter(body))
121
+ .header_param(new_parameter('application/json', key: 'accept'))
122
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
123
+ .auth(Single.new('global')))
124
+ .response(new_response_handler
125
+ .deserializer(APIHelper.method(:json_deserialize))
126
+ .is_api_response(true)
127
+ .convertor(ApiResponse.method(:create)))
128
+ .execute
199
129
  end
200
130
 
201
131
  # Applies adjustments and counts to the provided item quantities.
@@ -207,32 +137,20 @@ module Square
207
137
  # object definition for field details.
208
138
  # @return [BatchChangeInventoryResponse Hash] response from the API call
209
139
  def batch_change_inventory(body:)
210
- # Prepare query url.
211
- _query_builder = config.get_base_uri
212
- _query_builder << '/v2/inventory/changes/batch-create'
213
- _query_url = APIHelper.clean_url _query_builder
214
-
215
- # Prepare headers.
216
- _headers = {
217
- 'accept' => 'application/json',
218
- 'Content-Type' => 'application/json'
219
- }
220
-
221
- # Prepare and execute HttpRequest.
222
- _request = config.http_client.post(
223
- _query_url,
224
- headers: _headers,
225
- parameters: body.to_json
226
- )
227
- OAuth2.apply(config, _request)
228
- _response = execute_request(_request)
229
-
230
- # Return appropriate response type.
231
- decoded = APIHelper.json_deserialize(_response.raw_body)
232
- _errors = APIHelper.map_response(decoded, ['errors'])
233
- ApiResponse.new(
234
- _response, data: decoded, errors: _errors
235
- )
140
+ new_api_call_builder
141
+ .request(new_request_builder(HttpMethodEnum::POST,
142
+ '/v2/inventory/changes/batch-create',
143
+ 'default')
144
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
145
+ .body_param(new_parameter(body))
146
+ .header_param(new_parameter('application/json', key: 'accept'))
147
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
148
+ .auth(Single.new('global')))
149
+ .response(new_response_handler
150
+ .deserializer(APIHelper.method(:json_deserialize))
151
+ .is_api_response(true)
152
+ .convertor(ApiResponse.method(:create)))
153
+ .execute
236
154
  end
237
155
 
238
156
  # Returns historical physical counts and adjustments based on the
@@ -246,32 +164,20 @@ module Square
246
164
  # corresponding object definition for field details.
247
165
  # @return [BatchRetrieveInventoryChangesResponse Hash] response from the API call
248
166
  def batch_retrieve_inventory_changes(body:)
249
- # Prepare query url.
250
- _query_builder = config.get_base_uri
251
- _query_builder << '/v2/inventory/changes/batch-retrieve'
252
- _query_url = APIHelper.clean_url _query_builder
253
-
254
- # Prepare headers.
255
- _headers = {
256
- 'accept' => 'application/json',
257
- 'Content-Type' => 'application/json'
258
- }
259
-
260
- # Prepare and execute HttpRequest.
261
- _request = config.http_client.post(
262
- _query_url,
263
- headers: _headers,
264
- parameters: body.to_json
265
- )
266
- OAuth2.apply(config, _request)
267
- _response = execute_request(_request)
268
-
269
- # Return appropriate response type.
270
- decoded = APIHelper.json_deserialize(_response.raw_body)
271
- _errors = APIHelper.map_response(decoded, ['errors'])
272
- ApiResponse.new(
273
- _response, data: decoded, errors: _errors
274
- )
167
+ new_api_call_builder
168
+ .request(new_request_builder(HttpMethodEnum::POST,
169
+ '/v2/inventory/changes/batch-retrieve',
170
+ 'default')
171
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
172
+ .body_param(new_parameter(body))
173
+ .header_param(new_parameter('application/json', key: 'accept'))
174
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
175
+ .auth(Single.new('global')))
176
+ .response(new_response_handler
177
+ .deserializer(APIHelper.method(:json_deserialize))
178
+ .is_api_response(true)
179
+ .convertor(ApiResponse.method(:create)))
180
+ .execute
275
181
  end
276
182
 
277
183
  # Returns current counts for the provided
@@ -289,144 +195,87 @@ module Square
289
195
  # corresponding object definition for field details.
290
196
  # @return [BatchRetrieveInventoryCountsResponse Hash] response from the API call
291
197
  def batch_retrieve_inventory_counts(body:)
292
- # Prepare query url.
293
- _query_builder = config.get_base_uri
294
- _query_builder << '/v2/inventory/counts/batch-retrieve'
295
- _query_url = APIHelper.clean_url _query_builder
296
-
297
- # Prepare headers.
298
- _headers = {
299
- 'accept' => 'application/json',
300
- 'Content-Type' => 'application/json'
301
- }
302
-
303
- # Prepare and execute HttpRequest.
304
- _request = config.http_client.post(
305
- _query_url,
306
- headers: _headers,
307
- parameters: body.to_json
308
- )
309
- OAuth2.apply(config, _request)
310
- _response = execute_request(_request)
311
-
312
- # Return appropriate response type.
313
- decoded = APIHelper.json_deserialize(_response.raw_body)
314
- _errors = APIHelper.map_response(decoded, ['errors'])
315
- ApiResponse.new(
316
- _response, data: decoded, errors: _errors
317
- )
198
+ new_api_call_builder
199
+ .request(new_request_builder(HttpMethodEnum::POST,
200
+ '/v2/inventory/counts/batch-retrieve',
201
+ 'default')
202
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
203
+ .body_param(new_parameter(body))
204
+ .header_param(new_parameter('application/json', key: 'accept'))
205
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
206
+ .auth(Single.new('global')))
207
+ .response(new_response_handler
208
+ .deserializer(APIHelper.method(:json_deserialize))
209
+ .is_api_response(true)
210
+ .convertor(ApiResponse.method(:create)))
211
+ .execute
318
212
  end
319
213
 
320
214
  # Deprecated version of
321
- # [RetrieveInventoryPhysicalCount]($e/Inventory/RetrieveInventoryPhysicalCou
322
- # nt) after the endpoint URL
215
+ # [RetrieveInventoryPhysicalCount](api-endpoint:Inventory-RetrieveInventoryP
216
+ # hysicalCount) after the endpoint URL
323
217
  # is updated to conform to the standard convention.
324
218
  # @param [String] physical_count_id Required parameter: ID of the
325
- # [InventoryPhysicalCount]($m/InventoryPhysicalCount) to retrieve.
219
+ # [InventoryPhysicalCount](entity:InventoryPhysicalCount) to retrieve.
326
220
  # @return [RetrieveInventoryPhysicalCountResponse Hash] response from the API call
327
221
  def deprecated_retrieve_inventory_physical_count(physical_count_id:)
328
222
  warn 'Endpoint deprecated_retrieve_inventory_physical_count in Inventory'\
329
223
  'Api is deprecated'
330
- # Prepare query url.
331
- _query_builder = config.get_base_uri
332
- _query_builder << '/v2/inventory/physical-count/{physical_count_id}'
333
- _query_builder = APIHelper.append_url_with_template_parameters(
334
- _query_builder,
335
- 'physical_count_id' => { 'value' => physical_count_id, 'encode' => true }
336
- )
337
- _query_url = APIHelper.clean_url _query_builder
338
-
339
- # Prepare headers.
340
- _headers = {
341
- 'accept' => 'application/json'
342
- }
343
-
344
- # Prepare and execute HttpRequest.
345
- _request = config.http_client.get(
346
- _query_url,
347
- headers: _headers
348
- )
349
- OAuth2.apply(config, _request)
350
- _response = execute_request(_request)
351
-
352
- # Return appropriate response type.
353
- decoded = APIHelper.json_deserialize(_response.raw_body)
354
- _errors = APIHelper.map_response(decoded, ['errors'])
355
- ApiResponse.new(
356
- _response, data: decoded, errors: _errors
357
- )
224
+ new_api_call_builder
225
+ .request(new_request_builder(HttpMethodEnum::GET,
226
+ '/v2/inventory/physical-count/{physical_count_id}',
227
+ 'default')
228
+ .template_param(new_parameter(physical_count_id, key: 'physical_count_id')
229
+ .should_encode(true))
230
+ .header_param(new_parameter('application/json', key: 'accept'))
231
+ .auth(Single.new('global')))
232
+ .response(new_response_handler
233
+ .deserializer(APIHelper.method(:json_deserialize))
234
+ .is_api_response(true)
235
+ .convertor(ApiResponse.method(:create)))
236
+ .execute
358
237
  end
359
238
 
360
239
  # Returns the [InventoryPhysicalCount]($m/InventoryPhysicalCount)
361
240
  # object with the provided `physical_count_id`.
362
241
  # @param [String] physical_count_id Required parameter: ID of the
363
- # [InventoryPhysicalCount]($m/InventoryPhysicalCount) to retrieve.
242
+ # [InventoryPhysicalCount](entity:InventoryPhysicalCount) to retrieve.
364
243
  # @return [RetrieveInventoryPhysicalCountResponse Hash] response from the API call
365
244
  def retrieve_inventory_physical_count(physical_count_id:)
366
- # Prepare query url.
367
- _query_builder = config.get_base_uri
368
- _query_builder << '/v2/inventory/physical-counts/{physical_count_id}'
369
- _query_builder = APIHelper.append_url_with_template_parameters(
370
- _query_builder,
371
- 'physical_count_id' => { 'value' => physical_count_id, 'encode' => true }
372
- )
373
- _query_url = APIHelper.clean_url _query_builder
374
-
375
- # Prepare headers.
376
- _headers = {
377
- 'accept' => 'application/json'
378
- }
379
-
380
- # Prepare and execute HttpRequest.
381
- _request = config.http_client.get(
382
- _query_url,
383
- headers: _headers
384
- )
385
- OAuth2.apply(config, _request)
386
- _response = execute_request(_request)
387
-
388
- # Return appropriate response type.
389
- decoded = APIHelper.json_deserialize(_response.raw_body)
390
- _errors = APIHelper.map_response(decoded, ['errors'])
391
- ApiResponse.new(
392
- _response, data: decoded, errors: _errors
393
- )
245
+ new_api_call_builder
246
+ .request(new_request_builder(HttpMethodEnum::GET,
247
+ '/v2/inventory/physical-counts/{physical_count_id}',
248
+ 'default')
249
+ .template_param(new_parameter(physical_count_id, key: 'physical_count_id')
250
+ .should_encode(true))
251
+ .header_param(new_parameter('application/json', key: 'accept'))
252
+ .auth(Single.new('global')))
253
+ .response(new_response_handler
254
+ .deserializer(APIHelper.method(:json_deserialize))
255
+ .is_api_response(true)
256
+ .convertor(ApiResponse.method(:create)))
257
+ .execute
394
258
  end
395
259
 
396
260
  # Returns the [InventoryTransfer]($m/InventoryTransfer) object
397
261
  # with the provided `transfer_id`.
398
262
  # @param [String] transfer_id Required parameter: ID of the
399
- # [InventoryTransfer]($m/InventoryTransfer) to retrieve.
263
+ # [InventoryTransfer](entity:InventoryTransfer) to retrieve.
400
264
  # @return [RetrieveInventoryTransferResponse Hash] response from the API call
401
265
  def retrieve_inventory_transfer(transfer_id:)
402
- # Prepare query url.
403
- _query_builder = config.get_base_uri
404
- _query_builder << '/v2/inventory/transfers/{transfer_id}'
405
- _query_builder = APIHelper.append_url_with_template_parameters(
406
- _query_builder,
407
- 'transfer_id' => { 'value' => transfer_id, 'encode' => true }
408
- )
409
- _query_url = APIHelper.clean_url _query_builder
410
-
411
- # Prepare headers.
412
- _headers = {
413
- 'accept' => 'application/json'
414
- }
415
-
416
- # Prepare and execute HttpRequest.
417
- _request = config.http_client.get(
418
- _query_url,
419
- headers: _headers
420
- )
421
- OAuth2.apply(config, _request)
422
- _response = execute_request(_request)
423
-
424
- # Return appropriate response type.
425
- decoded = APIHelper.json_deserialize(_response.raw_body)
426
- _errors = APIHelper.map_response(decoded, ['errors'])
427
- ApiResponse.new(
428
- _response, data: decoded, errors: _errors
429
- )
266
+ new_api_call_builder
267
+ .request(new_request_builder(HttpMethodEnum::GET,
268
+ '/v2/inventory/transfers/{transfer_id}',
269
+ 'default')
270
+ .template_param(new_parameter(transfer_id, key: 'transfer_id')
271
+ .should_encode(true))
272
+ .header_param(new_parameter('application/json', key: 'accept'))
273
+ .auth(Single.new('global')))
274
+ .response(new_response_handler
275
+ .deserializer(APIHelper.method(:json_deserialize))
276
+ .is_api_response(true)
277
+ .convertor(ApiResponse.method(:create)))
278
+ .execute
430
279
  end
431
280
 
432
281
  # Retrieves the current calculated stock count for a given
@@ -434,10 +283,10 @@ module Square
434
283
  # [Location]($m/Location)s. Responses are paginated and unsorted.
435
284
  # For more sophisticated queries, use a batch endpoint.
436
285
  # @param [String] catalog_object_id Required parameter: ID of the
437
- # [CatalogObject]($m/CatalogObject) to retrieve.
286
+ # [CatalogObject](entity:CatalogObject) to retrieve.
438
287
  # @param [String] location_ids Optional parameter: The
439
- # [Location]($m/Location) IDs to look up as a comma-separated list. An empty
440
- # list queries all locations.
288
+ # [Location](entity:Location) IDs to look up as a comma-separated list. An
289
+ # empty list queries all locations.
441
290
  # @param [String] cursor Optional parameter: A pagination cursor returned by
442
291
  # a previous call to this endpoint. Provide this to retrieve the next set of
443
292
  # results for the original query. See the
@@ -447,47 +296,29 @@ module Square
447
296
  def retrieve_inventory_count(catalog_object_id:,
448
297
  location_ids: nil,
449
298
  cursor: nil)
450
- # Prepare query url.
451
- _query_builder = config.get_base_uri
452
- _query_builder << '/v2/inventory/{catalog_object_id}'
453
- _query_builder = APIHelper.append_url_with_template_parameters(
454
- _query_builder,
455
- 'catalog_object_id' => { 'value' => catalog_object_id, 'encode' => true }
456
- )
457
- _query_builder = APIHelper.append_url_with_query_parameters(
458
- _query_builder,
459
- 'location_ids' => location_ids,
460
- 'cursor' => cursor
461
- )
462
- _query_url = APIHelper.clean_url _query_builder
463
-
464
- # Prepare headers.
465
- _headers = {
466
- 'accept' => 'application/json'
467
- }
468
-
469
- # Prepare and execute HttpRequest.
470
- _request = config.http_client.get(
471
- _query_url,
472
- headers: _headers
473
- )
474
- OAuth2.apply(config, _request)
475
- _response = execute_request(_request)
476
-
477
- # Return appropriate response type.
478
- decoded = APIHelper.json_deserialize(_response.raw_body)
479
- _errors = APIHelper.map_response(decoded, ['errors'])
480
- ApiResponse.new(
481
- _response, data: decoded, errors: _errors
482
- )
299
+ new_api_call_builder
300
+ .request(new_request_builder(HttpMethodEnum::GET,
301
+ '/v2/inventory/{catalog_object_id}',
302
+ 'default')
303
+ .template_param(new_parameter(catalog_object_id, key: 'catalog_object_id')
304
+ .should_encode(true))
305
+ .query_param(new_parameter(location_ids, key: 'location_ids'))
306
+ .query_param(new_parameter(cursor, key: 'cursor'))
307
+ .header_param(new_parameter('application/json', key: 'accept'))
308
+ .auth(Single.new('global')))
309
+ .response(new_response_handler
310
+ .deserializer(APIHelper.method(:json_deserialize))
311
+ .is_api_response(true)
312
+ .convertor(ApiResponse.method(:create)))
313
+ .execute
483
314
  end
484
315
 
485
316
  # Returns a set of physical counts and inventory adjustments for the
486
- # provided [CatalogObject]($m/CatalogObject) at the requested
487
- # [Location]($m/Location)s.
317
+ # provided [CatalogObject](entity:CatalogObject) at the requested
318
+ # [Location](entity:Location)s.
488
319
  # You can achieve the same result by calling
489
- # [BatchRetrieveInventoryChanges]($e/Inventory/BatchRetrieveInventoryChanges
490
- # )
320
+ # [BatchRetrieveInventoryChanges](api-endpoint:Inventory-BatchRetrieveInvent
321
+ # oryChanges)
491
322
  # and having the `catalog_object_ids` list contain a single element of the
492
323
  # `CatalogObject` ID.
493
324
  # Results are paginated and sorted in descending order according to their
@@ -497,10 +328,10 @@ module Square
497
328
  # used to display recent changes for a specific item. For more
498
329
  # sophisticated queries, use a batch endpoint.
499
330
  # @param [String] catalog_object_id Required parameter: ID of the
500
- # [CatalogObject]($m/CatalogObject) to retrieve.
331
+ # [CatalogObject](entity:CatalogObject) to retrieve.
501
332
  # @param [String] location_ids Optional parameter: The
502
- # [Location]($m/Location) IDs to look up as a comma-separated list. An empty
503
- # list queries all locations.
333
+ # [Location](entity:Location) IDs to look up as a comma-separated list. An
334
+ # empty list queries all locations.
504
335
  # @param [String] cursor Optional parameter: A pagination cursor returned by
505
336
  # a previous call to this endpoint. Provide this to retrieve the next set of
506
337
  # results for the original query. See the
@@ -511,39 +342,21 @@ module Square
511
342
  location_ids: nil,
512
343
  cursor: nil)
513
344
  warn 'Endpoint retrieve_inventory_changes in InventoryApi is deprecated'
514
- # Prepare query url.
515
- _query_builder = config.get_base_uri
516
- _query_builder << '/v2/inventory/{catalog_object_id}/changes'
517
- _query_builder = APIHelper.append_url_with_template_parameters(
518
- _query_builder,
519
- 'catalog_object_id' => { 'value' => catalog_object_id, 'encode' => true }
520
- )
521
- _query_builder = APIHelper.append_url_with_query_parameters(
522
- _query_builder,
523
- 'location_ids' => location_ids,
524
- 'cursor' => cursor
525
- )
526
- _query_url = APIHelper.clean_url _query_builder
527
-
528
- # Prepare headers.
529
- _headers = {
530
- 'accept' => 'application/json'
531
- }
532
-
533
- # Prepare and execute HttpRequest.
534
- _request = config.http_client.get(
535
- _query_url,
536
- headers: _headers
537
- )
538
- OAuth2.apply(config, _request)
539
- _response = execute_request(_request)
540
-
541
- # Return appropriate response type.
542
- decoded = APIHelper.json_deserialize(_response.raw_body)
543
- _errors = APIHelper.map_response(decoded, ['errors'])
544
- ApiResponse.new(
545
- _response, data: decoded, errors: _errors
546
- )
345
+ new_api_call_builder
346
+ .request(new_request_builder(HttpMethodEnum::GET,
347
+ '/v2/inventory/{catalog_object_id}/changes',
348
+ 'default')
349
+ .template_param(new_parameter(catalog_object_id, key: 'catalog_object_id')
350
+ .should_encode(true))
351
+ .query_param(new_parameter(location_ids, key: 'location_ids'))
352
+ .query_param(new_parameter(cursor, key: 'cursor'))
353
+ .header_param(new_parameter('application/json', key: 'accept'))
354
+ .auth(Single.new('global')))
355
+ .response(new_response_handler
356
+ .deserializer(APIHelper.method(:json_deserialize))
357
+ .is_api_response(true)
358
+ .convertor(ApiResponse.method(:create)))
359
+ .execute
547
360
  end
548
361
  end
549
362
  end