square.rb 26.0.0.20221214 → 26.2.0.20230315

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/LICENSE +1 -1
  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 +164 -329
  7. data/lib/square/api/bookings_api.rb +135 -260
  8. data/lib/square/api/cards_api.rb +56 -118
  9. data/lib/square/api/cash_drawers_api.rb +47 -103
  10. data/lib/square/api/catalog_api.rb +197 -423
  11. data/lib/square/api/checkout_api.rb +85 -175
  12. data/lib/square/api/customer_custom_attributes_api.rb +150 -303
  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 +130 -288
  18. data/lib/square/api/employees_api.rb +28 -63
  19. data/lib/square/api/gift_card_activities_api.rb +33 -65
  20. data/lib/square/api/gift_cards_api.rb +103 -202
  21. data/lib/square/api/inventory_api.rb +179 -366
  22. data/lib/square/api/invoices_api.rb +118 -237
  23. data/lib/square/api/labor_api.rb +223 -459
  24. data/lib/square/api/location_custom_attributes_api.rb +419 -0
  25. data/lib/square/api/locations_api.rb +54 -112
  26. data/lib/square/api/loyalty_api.rb +259 -512
  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 +168 -333
  31. data/lib/square/api/orders_api.rb +115 -222
  32. data/lib/square/api/payments_api.rb +106 -208
  33. data/lib/square/api/payouts_api.rb +47 -100
  34. data/lib/square/api/refunds_api.rb +46 -93
  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 +62 -126
  41. data/lib/square/api/v1_transactions_api.rb +155 -296
  42. data/lib/square/api/vendors_api.rb +99 -192
  43. data/lib/square/api/webhook_subscriptions_api.rb +115 -235
  44. data/lib/square/api_helper.rb +1 -437
  45. data/lib/square/client.rb +82 -46
  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 +7 -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 +12 -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,10 +1,6 @@
1
1
  module Square
2
2
  # CatalogApi
3
3
  class CatalogApi < BaseApi
4
- def initialize(config, http_call_back: nil)
5
- super(config, http_call_back: http_call_back)
6
- end
7
-
8
4
  # Deletes a set of [CatalogItem]($m/CatalogItem)s based on the
9
5
  # provided list of target IDs and returns a set of successfully deleted IDs
10
6
  # in
@@ -26,32 +22,20 @@ module Square
26
22
  # corresponding object definition for field details.
27
23
  # @return [BatchDeleteCatalogObjectsResponse Hash] response from the API call
28
24
  def batch_delete_catalog_objects(body:)
29
- # Prepare query url.
30
- _query_builder = config.get_base_uri
31
- _query_builder << '/v2/catalog/batch-delete'
32
- _query_url = APIHelper.clean_url _query_builder
33
-
34
- # Prepare headers.
35
- _headers = {
36
- 'accept' => 'application/json',
37
- 'Content-Type' => 'application/json'
38
- }
39
-
40
- # Prepare and execute HttpRequest.
41
- _request = config.http_client.post(
42
- _query_url,
43
- headers: _headers,
44
- parameters: body.to_json
45
- )
46
- OAuth2.apply(config, _request)
47
- _response = execute_request(_request)
48
-
49
- # Return appropriate response type.
50
- decoded = APIHelper.json_deserialize(_response.raw_body)
51
- _errors = APIHelper.map_response(decoded, ['errors'])
52
- ApiResponse.new(
53
- _response, data: decoded, errors: _errors
54
- )
25
+ new_api_call_builder
26
+ .request(new_request_builder(HttpMethodEnum::POST,
27
+ '/v2/catalog/batch-delete',
28
+ 'default')
29
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
30
+ .body_param(new_parameter(body))
31
+ .header_param(new_parameter('application/json', key: 'accept'))
32
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
33
+ .auth(Single.new('global')))
34
+ .response(new_response_handler
35
+ .deserializer(APIHelper.method(:json_deserialize))
36
+ .is_api_response(true)
37
+ .convertor(ApiResponse.method(:create)))
38
+ .execute
55
39
  end
56
40
 
57
41
  # Returns a set of objects based on the provided ID.
@@ -65,32 +49,20 @@ module Square
65
49
  # corresponding object definition for field details.
66
50
  # @return [BatchRetrieveCatalogObjectsResponse Hash] response from the API call
67
51
  def batch_retrieve_catalog_objects(body:)
68
- # Prepare query url.
69
- _query_builder = config.get_base_uri
70
- _query_builder << '/v2/catalog/batch-retrieve'
71
- _query_url = APIHelper.clean_url _query_builder
72
-
73
- # Prepare headers.
74
- _headers = {
75
- 'accept' => 'application/json',
76
- 'Content-Type' => 'application/json'
77
- }
78
-
79
- # Prepare and execute HttpRequest.
80
- _request = config.http_client.post(
81
- _query_url,
82
- headers: _headers,
83
- parameters: body.to_json
84
- )
85
- OAuth2.apply(config, _request)
86
- _response = execute_request(_request)
87
-
88
- # Return appropriate response type.
89
- decoded = APIHelper.json_deserialize(_response.raw_body)
90
- _errors = APIHelper.map_response(decoded, ['errors'])
91
- ApiResponse.new(
92
- _response, data: decoded, errors: _errors
93
- )
52
+ new_api_call_builder
53
+ .request(new_request_builder(HttpMethodEnum::POST,
54
+ '/v2/catalog/batch-retrieve',
55
+ 'default')
56
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
57
+ .body_param(new_parameter(body))
58
+ .header_param(new_parameter('application/json', key: 'accept'))
59
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
60
+ .auth(Single.new('global')))
61
+ .response(new_response_handler
62
+ .deserializer(APIHelper.method(:json_deserialize))
63
+ .is_api_response(true)
64
+ .convertor(ApiResponse.method(:create)))
65
+ .execute
94
66
  end
95
67
 
96
68
  # Creates or updates up to 10,000 target objects based on the provided
@@ -117,32 +89,20 @@ module Square
117
89
  # corresponding object definition for field details.
118
90
  # @return [BatchUpsertCatalogObjectsResponse Hash] response from the API call
119
91
  def batch_upsert_catalog_objects(body:)
120
- # Prepare query url.
121
- _query_builder = config.get_base_uri
122
- _query_builder << '/v2/catalog/batch-upsert'
123
- _query_url = APIHelper.clean_url _query_builder
124
-
125
- # Prepare headers.
126
- _headers = {
127
- 'accept' => 'application/json',
128
- 'Content-Type' => 'application/json'
129
- }
130
-
131
- # Prepare and execute HttpRequest.
132
- _request = config.http_client.post(
133
- _query_url,
134
- headers: _headers,
135
- parameters: body.to_json
136
- )
137
- OAuth2.apply(config, _request)
138
- _response = execute_request(_request)
139
-
140
- # Return appropriate response type.
141
- decoded = APIHelper.json_deserialize(_response.raw_body)
142
- _errors = APIHelper.map_response(decoded, ['errors'])
143
- ApiResponse.new(
144
- _response, data: decoded, errors: _errors
145
- )
92
+ new_api_call_builder
93
+ .request(new_request_builder(HttpMethodEnum::POST,
94
+ '/v2/catalog/batch-upsert',
95
+ 'default')
96
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
97
+ .body_param(new_parameter(body))
98
+ .header_param(new_parameter('application/json', key: 'accept'))
99
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
100
+ .auth(Single.new('global')))
101
+ .response(new_response_handler
102
+ .deserializer(APIHelper.method(:json_deserialize))
103
+ .is_api_response(true)
104
+ .convertor(ApiResponse.method(:create)))
105
+ .execute
146
106
  end
147
107
 
148
108
  # Uploads an image file to be represented by a
@@ -158,52 +118,21 @@ module Square
158
118
  # @return [CreateCatalogImageResponse Hash] response from the API call
159
119
  def create_catalog_image(request: nil,
160
120
  image_file: nil)
161
- # Prepare query url.
162
- _query_builder = config.get_base_uri
163
- _query_builder << '/v2/catalog/images'
164
- _query_url = APIHelper.clean_url _query_builder
165
-
166
- if image_file.is_a? FileWrapper
167
- image_file_wrapper = image_file.file
168
- image_file_content_type = image_file.content_type
169
- else
170
- image_file_wrapper = image_file
171
- image_file_content_type = 'image/jpeg'
172
- end
173
-
174
- # Prepare headers.
175
- _headers = {
176
- 'accept' => 'application/json'
177
- }
178
-
179
- # Prepare form parameters.
180
- _parameters = {
181
- 'request' => Faraday::UploadIO.new(
182
- StringIO.new(request.to_json),
183
- 'application/json'
184
- ),
185
- 'image_file' => Faraday::UploadIO.new(
186
- image_file_wrapper,
187
- image_file_content_type
188
- )
189
- }
190
- _parameters = APIHelper.form_encode_parameters(_parameters)
191
-
192
- # Prepare and execute HttpRequest.
193
- _request = config.http_client.post(
194
- _query_url,
195
- headers: _headers,
196
- parameters: _parameters
197
- )
198
- OAuth2.apply(config, _request)
199
- _response = execute_request(_request)
200
-
201
- # Return appropriate response type.
202
- decoded = APIHelper.json_deserialize(_response.raw_body)
203
- _errors = APIHelper.map_response(decoded, ['errors'])
204
- ApiResponse.new(
205
- _response, data: decoded, errors: _errors
206
- )
121
+ new_api_call_builder
122
+ .request(new_request_builder(HttpMethodEnum::POST,
123
+ '/v2/catalog/images',
124
+ 'default')
125
+ .multipart_param(new_parameter(StringIO.new(request.to_json), key: 'request')
126
+ .default_content_type('application/json; charset=utf-8'))
127
+ .multipart_param(new_parameter(image_file, key: 'image_file')
128
+ .default_content_type('image/jpeg'))
129
+ .header_param(new_parameter('application/json', key: 'accept'))
130
+ .auth(Single.new('global')))
131
+ .response(new_response_handler
132
+ .deserializer(APIHelper.method(:json_deserialize))
133
+ .is_api_response(true)
134
+ .convertor(ApiResponse.method(:create)))
135
+ .execute
207
136
  end
208
137
 
209
138
  # Uploads a new image file to replace the existing one in the specified
@@ -219,86 +148,40 @@ module Square
219
148
  def update_catalog_image(image_id:,
220
149
  request: nil,
221
150
  image_file: nil)
222
- # Prepare query url.
223
- _query_builder = config.get_base_uri
224
- _query_builder << '/v2/catalog/images/{image_id}'
225
- _query_builder = APIHelper.append_url_with_template_parameters(
226
- _query_builder,
227
- 'image_id' => { 'value' => image_id, 'encode' => true }
228
- )
229
- _query_url = APIHelper.clean_url _query_builder
230
-
231
- if image_file.is_a? FileWrapper
232
- image_file_wrapper = image_file.file
233
- image_file_content_type = image_file.content_type
234
- else
235
- image_file_wrapper = image_file
236
- image_file_content_type = 'image/jpeg'
237
- end
238
-
239
- # Prepare headers.
240
- _headers = {
241
- 'accept' => 'application/json'
242
- }
243
-
244
- # Prepare form parameters.
245
- _parameters = {
246
- 'request' => Faraday::UploadIO.new(
247
- StringIO.new(request.to_json),
248
- 'application/json'
249
- ),
250
- 'image_file' => Faraday::UploadIO.new(
251
- image_file_wrapper,
252
- image_file_content_type
253
- )
254
- }
255
- _parameters = APIHelper.form_encode_parameters(_parameters)
256
-
257
- # Prepare and execute HttpRequest.
258
- _request = config.http_client.put(
259
- _query_url,
260
- headers: _headers,
261
- parameters: _parameters
262
- )
263
- OAuth2.apply(config, _request)
264
- _response = execute_request(_request)
265
-
266
- # Return appropriate response type.
267
- decoded = APIHelper.json_deserialize(_response.raw_body)
268
- _errors = APIHelper.map_response(decoded, ['errors'])
269
- ApiResponse.new(
270
- _response, data: decoded, errors: _errors
271
- )
151
+ new_api_call_builder
152
+ .request(new_request_builder(HttpMethodEnum::PUT,
153
+ '/v2/catalog/images/{image_id}',
154
+ 'default')
155
+ .template_param(new_parameter(image_id, key: 'image_id')
156
+ .should_encode(true))
157
+ .multipart_param(new_parameter(StringIO.new(request.to_json), key: 'request')
158
+ .default_content_type('application/json; charset=utf-8'))
159
+ .multipart_param(new_parameter(image_file, key: 'image_file')
160
+ .default_content_type('image/jpeg'))
161
+ .header_param(new_parameter('application/json', key: 'accept'))
162
+ .auth(Single.new('global')))
163
+ .response(new_response_handler
164
+ .deserializer(APIHelper.method(:json_deserialize))
165
+ .is_api_response(true)
166
+ .convertor(ApiResponse.method(:create)))
167
+ .execute
272
168
  end
273
169
 
274
170
  # Retrieves information about the Square Catalog API, such as batch size
275
171
  # limits that can be used by the `BatchUpsertCatalogObjects` endpoint.
276
172
  # @return [CatalogInfoResponse Hash] response from the API call
277
173
  def catalog_info
278
- # Prepare query url.
279
- _query_builder = config.get_base_uri
280
- _query_builder << '/v2/catalog/info'
281
- _query_url = APIHelper.clean_url _query_builder
282
-
283
- # Prepare headers.
284
- _headers = {
285
- 'accept' => 'application/json'
286
- }
287
-
288
- # Prepare and execute HttpRequest.
289
- _request = config.http_client.get(
290
- _query_url,
291
- headers: _headers
292
- )
293
- OAuth2.apply(config, _request)
294
- _response = execute_request(_request)
295
-
296
- # Return appropriate response type.
297
- decoded = APIHelper.json_deserialize(_response.raw_body)
298
- _errors = APIHelper.map_response(decoded, ['errors'])
299
- ApiResponse.new(
300
- _response, data: decoded, errors: _errors
301
- )
174
+ new_api_call_builder
175
+ .request(new_request_builder(HttpMethodEnum::GET,
176
+ '/v2/catalog/info',
177
+ 'default')
178
+ .header_param(new_parameter('application/json', key: 'accept'))
179
+ .auth(Single.new('global')))
180
+ .response(new_response_handler
181
+ .deserializer(APIHelper.method(:json_deserialize))
182
+ .is_api_response(true)
183
+ .convertor(ApiResponse.method(:create)))
184
+ .execute
302
185
  end
303
186
 
304
187
  # Returns a list of all [CatalogObject]($m/CatalogObject)s of the specified
@@ -339,36 +222,20 @@ module Square
339
222
  def list_catalog(cursor: nil,
340
223
  types: nil,
341
224
  catalog_version: nil)
342
- # Prepare query url.
343
- _query_builder = config.get_base_uri
344
- _query_builder << '/v2/catalog/list'
345
- _query_builder = APIHelper.append_url_with_query_parameters(
346
- _query_builder,
347
- 'cursor' => cursor,
348
- 'types' => types,
349
- 'catalog_version' => catalog_version
350
- )
351
- _query_url = APIHelper.clean_url _query_builder
352
-
353
- # Prepare headers.
354
- _headers = {
355
- 'accept' => 'application/json'
356
- }
357
-
358
- # Prepare and execute HttpRequest.
359
- _request = config.http_client.get(
360
- _query_url,
361
- headers: _headers
362
- )
363
- OAuth2.apply(config, _request)
364
- _response = execute_request(_request)
365
-
366
- # Return appropriate response type.
367
- decoded = APIHelper.json_deserialize(_response.raw_body)
368
- _errors = APIHelper.map_response(decoded, ['errors'])
369
- ApiResponse.new(
370
- _response, data: decoded, errors: _errors
371
- )
225
+ new_api_call_builder
226
+ .request(new_request_builder(HttpMethodEnum::GET,
227
+ '/v2/catalog/list',
228
+ 'default')
229
+ .query_param(new_parameter(cursor, key: 'cursor'))
230
+ .query_param(new_parameter(types, key: 'types'))
231
+ .query_param(new_parameter(catalog_version, key: 'catalog_version'))
232
+ .header_param(new_parameter('application/json', key: 'accept'))
233
+ .auth(Single.new('global')))
234
+ .response(new_response_handler
235
+ .deserializer(APIHelper.method(:json_deserialize))
236
+ .is_api_response(true)
237
+ .convertor(ApiResponse.method(:create)))
238
+ .execute
372
239
  end
373
240
 
374
241
  # Creates a new or updates the specified [CatalogObject]($m/CatalogObject).
@@ -382,32 +249,20 @@ module Square
382
249
  # object definition for field details.
383
250
  # @return [UpsertCatalogObjectResponse Hash] response from the API call
384
251
  def upsert_catalog_object(body:)
385
- # Prepare query url.
386
- _query_builder = config.get_base_uri
387
- _query_builder << '/v2/catalog/object'
388
- _query_url = APIHelper.clean_url _query_builder
389
-
390
- # Prepare headers.
391
- _headers = {
392
- 'accept' => 'application/json',
393
- 'Content-Type' => 'application/json'
394
- }
395
-
396
- # Prepare and execute HttpRequest.
397
- _request = config.http_client.post(
398
- _query_url,
399
- headers: _headers,
400
- parameters: body.to_json
401
- )
402
- OAuth2.apply(config, _request)
403
- _response = execute_request(_request)
404
-
405
- # Return appropriate response type.
406
- decoded = APIHelper.json_deserialize(_response.raw_body)
407
- _errors = APIHelper.map_response(decoded, ['errors'])
408
- ApiResponse.new(
409
- _response, data: decoded, errors: _errors
410
- )
252
+ new_api_call_builder
253
+ .request(new_request_builder(HttpMethodEnum::POST,
254
+ '/v2/catalog/object',
255
+ 'default')
256
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
257
+ .body_param(new_parameter(body))
258
+ .header_param(new_parameter('application/json', key: 'accept'))
259
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
260
+ .auth(Single.new('global')))
261
+ .response(new_response_handler
262
+ .deserializer(APIHelper.method(:json_deserialize))
263
+ .is_api_response(true)
264
+ .convertor(ApiResponse.method(:create)))
265
+ .execute
411
266
  end
412
267
 
413
268
  # Deletes a single [CatalogObject]($m/CatalogObject) based on the
@@ -429,34 +284,19 @@ module Square
429
284
  # catalog item will delete its catalog item variations).
430
285
  # @return [DeleteCatalogObjectResponse Hash] response from the API call
431
286
  def delete_catalog_object(object_id:)
432
- # Prepare query url.
433
- _query_builder = config.get_base_uri
434
- _query_builder << '/v2/catalog/object/{object_id}'
435
- _query_builder = APIHelper.append_url_with_template_parameters(
436
- _query_builder,
437
- 'object_id' => { 'value' => object_id, 'encode' => true }
438
- )
439
- _query_url = APIHelper.clean_url _query_builder
440
-
441
- # Prepare headers.
442
- _headers = {
443
- 'accept' => 'application/json'
444
- }
445
-
446
- # Prepare and execute HttpRequest.
447
- _request = config.http_client.delete(
448
- _query_url,
449
- headers: _headers
450
- )
451
- OAuth2.apply(config, _request)
452
- _response = execute_request(_request)
453
-
454
- # Return appropriate response type.
455
- decoded = APIHelper.json_deserialize(_response.raw_body)
456
- _errors = APIHelper.map_response(decoded, ['errors'])
457
- ApiResponse.new(
458
- _response, data: decoded, errors: _errors
459
- )
287
+ new_api_call_builder
288
+ .request(new_request_builder(HttpMethodEnum::DELETE,
289
+ '/v2/catalog/object/{object_id}',
290
+ 'default')
291
+ .template_param(new_parameter(object_id, key: 'object_id')
292
+ .should_encode(true))
293
+ .header_param(new_parameter('application/json', key: 'accept'))
294
+ .auth(Single.new('global')))
295
+ .response(new_response_handler
296
+ .deserializer(APIHelper.method(:json_deserialize))
297
+ .is_api_response(true)
298
+ .convertor(ApiResponse.method(:create)))
299
+ .execute
460
300
  end
461
301
 
462
302
  # Returns a single [CatalogItem]($m/CatalogItem) as a
@@ -492,39 +332,21 @@ module Square
492
332
  def retrieve_catalog_object(object_id:,
493
333
  include_related_objects: false,
494
334
  catalog_version: nil)
495
- # Prepare query url.
496
- _query_builder = config.get_base_uri
497
- _query_builder << '/v2/catalog/object/{object_id}'
498
- _query_builder = APIHelper.append_url_with_template_parameters(
499
- _query_builder,
500
- 'object_id' => { 'value' => object_id, 'encode' => true }
501
- )
502
- _query_builder = APIHelper.append_url_with_query_parameters(
503
- _query_builder,
504
- 'include_related_objects' => include_related_objects,
505
- 'catalog_version' => catalog_version
506
- )
507
- _query_url = APIHelper.clean_url _query_builder
508
-
509
- # Prepare headers.
510
- _headers = {
511
- 'accept' => 'application/json'
512
- }
513
-
514
- # Prepare and execute HttpRequest.
515
- _request = config.http_client.get(
516
- _query_url,
517
- headers: _headers
518
- )
519
- OAuth2.apply(config, _request)
520
- _response = execute_request(_request)
521
-
522
- # Return appropriate response type.
523
- decoded = APIHelper.json_deserialize(_response.raw_body)
524
- _errors = APIHelper.map_response(decoded, ['errors'])
525
- ApiResponse.new(
526
- _response, data: decoded, errors: _errors
527
- )
335
+ new_api_call_builder
336
+ .request(new_request_builder(HttpMethodEnum::GET,
337
+ '/v2/catalog/object/{object_id}',
338
+ 'default')
339
+ .template_param(new_parameter(object_id, key: 'object_id')
340
+ .should_encode(true))
341
+ .query_param(new_parameter(include_related_objects, key: 'include_related_objects'))
342
+ .query_param(new_parameter(catalog_version, key: 'catalog_version'))
343
+ .header_param(new_parameter('application/json', key: 'accept'))
344
+ .auth(Single.new('global')))
345
+ .response(new_response_handler
346
+ .deserializer(APIHelper.method(:json_deserialize))
347
+ .is_api_response(true)
348
+ .convertor(ApiResponse.method(:create)))
349
+ .execute
528
350
  end
529
351
 
530
352
  # Searches for [CatalogObject]($m/CatalogObject) of any type by matching
@@ -549,32 +371,20 @@ module Square
549
371
  # object definition for field details.
550
372
  # @return [SearchCatalogObjectsResponse Hash] response from the API call
551
373
  def search_catalog_objects(body:)
552
- # Prepare query url.
553
- _query_builder = config.get_base_uri
554
- _query_builder << '/v2/catalog/search'
555
- _query_url = APIHelper.clean_url _query_builder
556
-
557
- # Prepare headers.
558
- _headers = {
559
- 'accept' => 'application/json',
560
- 'Content-Type' => 'application/json'
561
- }
562
-
563
- # Prepare and execute HttpRequest.
564
- _request = config.http_client.post(
565
- _query_url,
566
- headers: _headers,
567
- parameters: body.to_json
568
- )
569
- OAuth2.apply(config, _request)
570
- _response = execute_request(_request)
571
-
572
- # Return appropriate response type.
573
- decoded = APIHelper.json_deserialize(_response.raw_body)
574
- _errors = APIHelper.map_response(decoded, ['errors'])
575
- ApiResponse.new(
576
- _response, data: decoded, errors: _errors
577
- )
374
+ new_api_call_builder
375
+ .request(new_request_builder(HttpMethodEnum::POST,
376
+ '/v2/catalog/search',
377
+ 'default')
378
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
379
+ .body_param(new_parameter(body))
380
+ .header_param(new_parameter('application/json', key: 'accept'))
381
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
382
+ .auth(Single.new('global')))
383
+ .response(new_response_handler
384
+ .deserializer(APIHelper.method(:json_deserialize))
385
+ .is_api_response(true)
386
+ .convertor(ApiResponse.method(:create)))
387
+ .execute
578
388
  end
579
389
 
580
390
  # Searches for catalog items or item variations by matching supported search
@@ -599,32 +409,20 @@ module Square
599
409
  # object definition for field details.
600
410
  # @return [SearchCatalogItemsResponse Hash] response from the API call
601
411
  def search_catalog_items(body:)
602
- # Prepare query url.
603
- _query_builder = config.get_base_uri
604
- _query_builder << '/v2/catalog/search-catalog-items'
605
- _query_url = APIHelper.clean_url _query_builder
606
-
607
- # Prepare headers.
608
- _headers = {
609
- 'accept' => 'application/json',
610
- 'Content-Type' => 'application/json'
611
- }
612
-
613
- # Prepare and execute HttpRequest.
614
- _request = config.http_client.post(
615
- _query_url,
616
- headers: _headers,
617
- parameters: body.to_json
618
- )
619
- OAuth2.apply(config, _request)
620
- _response = execute_request(_request)
621
-
622
- # Return appropriate response type.
623
- decoded = APIHelper.json_deserialize(_response.raw_body)
624
- _errors = APIHelper.map_response(decoded, ['errors'])
625
- ApiResponse.new(
626
- _response, data: decoded, errors: _errors
627
- )
412
+ new_api_call_builder
413
+ .request(new_request_builder(HttpMethodEnum::POST,
414
+ '/v2/catalog/search-catalog-items',
415
+ 'default')
416
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
417
+ .body_param(new_parameter(body))
418
+ .header_param(new_parameter('application/json', key: 'accept'))
419
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
420
+ .auth(Single.new('global')))
421
+ .response(new_response_handler
422
+ .deserializer(APIHelper.method(:json_deserialize))
423
+ .is_api_response(true)
424
+ .convertor(ApiResponse.method(:create)))
425
+ .execute
628
426
  end
629
427
 
630
428
  # Updates the [CatalogModifierList]($m/CatalogModifierList) objects
@@ -635,32 +433,20 @@ module Square
635
433
  # object definition for field details.
636
434
  # @return [UpdateItemModifierListsResponse Hash] response from the API call
637
435
  def update_item_modifier_lists(body:)
638
- # Prepare query url.
639
- _query_builder = config.get_base_uri
640
- _query_builder << '/v2/catalog/update-item-modifier-lists'
641
- _query_url = APIHelper.clean_url _query_builder
642
-
643
- # Prepare headers.
644
- _headers = {
645
- 'accept' => 'application/json',
646
- 'Content-Type' => 'application/json'
647
- }
648
-
649
- # Prepare and execute HttpRequest.
650
- _request = config.http_client.post(
651
- _query_url,
652
- headers: _headers,
653
- parameters: body.to_json
654
- )
655
- OAuth2.apply(config, _request)
656
- _response = execute_request(_request)
657
-
658
- # Return appropriate response type.
659
- decoded = APIHelper.json_deserialize(_response.raw_body)
660
- _errors = APIHelper.map_response(decoded, ['errors'])
661
- ApiResponse.new(
662
- _response, data: decoded, errors: _errors
663
- )
436
+ new_api_call_builder
437
+ .request(new_request_builder(HttpMethodEnum::POST,
438
+ '/v2/catalog/update-item-modifier-lists',
439
+ 'default')
440
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
441
+ .body_param(new_parameter(body))
442
+ .header_param(new_parameter('application/json', key: 'accept'))
443
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
444
+ .auth(Single.new('global')))
445
+ .response(new_response_handler
446
+ .deserializer(APIHelper.method(:json_deserialize))
447
+ .is_api_response(true)
448
+ .convertor(ApiResponse.method(:create)))
449
+ .execute
664
450
  end
665
451
 
666
452
  # Updates the [CatalogTax]($m/CatalogTax) objects that apply to the
@@ -671,32 +457,20 @@ module Square
671
457
  # object definition for field details.
672
458
  # @return [UpdateItemTaxesResponse Hash] response from the API call
673
459
  def update_item_taxes(body:)
674
- # Prepare query url.
675
- _query_builder = config.get_base_uri
676
- _query_builder << '/v2/catalog/update-item-taxes'
677
- _query_url = APIHelper.clean_url _query_builder
678
-
679
- # Prepare headers.
680
- _headers = {
681
- 'accept' => 'application/json',
682
- 'Content-Type' => 'application/json'
683
- }
684
-
685
- # Prepare and execute HttpRequest.
686
- _request = config.http_client.post(
687
- _query_url,
688
- headers: _headers,
689
- parameters: body.to_json
690
- )
691
- OAuth2.apply(config, _request)
692
- _response = execute_request(_request)
693
-
694
- # Return appropriate response type.
695
- decoded = APIHelper.json_deserialize(_response.raw_body)
696
- _errors = APIHelper.map_response(decoded, ['errors'])
697
- ApiResponse.new(
698
- _response, data: decoded, errors: _errors
699
- )
460
+ new_api_call_builder
461
+ .request(new_request_builder(HttpMethodEnum::POST,
462
+ '/v2/catalog/update-item-taxes',
463
+ 'default')
464
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
465
+ .body_param(new_parameter(body))
466
+ .header_param(new_parameter('application/json', key: 'accept'))
467
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
468
+ .auth(Single.new('global')))
469
+ .response(new_response_handler
470
+ .deserializer(APIHelper.method(:json_deserialize))
471
+ .is_api_response(true)
472
+ .convertor(ApiResponse.method(:create)))
473
+ .execute
700
474
  end
701
475
  end
702
476
  end