square.rb 26.1.0.20230119 → 26.2.0.20230315

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/lib/square/api/apple_pay_api.rb +14 -30
  3. data/lib/square/api/bank_accounts_api.rb +40 -90
  4. data/lib/square/api/base_api.rb +42 -42
  5. data/lib/square/api/booking_custom_attributes_api.rb +164 -329
  6. data/lib/square/api/bookings_api.rb +135 -260
  7. data/lib/square/api/cards_api.rb +56 -118
  8. data/lib/square/api/cash_drawers_api.rb +47 -103
  9. data/lib/square/api/catalog_api.rb +197 -423
  10. data/lib/square/api/checkout_api.rb +85 -175
  11. data/lib/square/api/customer_custom_attributes_api.rb +150 -303
  12. data/lib/square/api/customer_groups_api.rb +69 -145
  13. data/lib/square/api/customer_segments_api.rb +26 -61
  14. data/lib/square/api/customers_api.rb +147 -294
  15. data/lib/square/api/devices_api.rb +42 -89
  16. data/lib/square/api/disputes_api.rb +130 -288
  17. data/lib/square/api/employees_api.rb +28 -63
  18. data/lib/square/api/gift_card_activities_api.rb +33 -65
  19. data/lib/square/api/gift_cards_api.rb +103 -202
  20. data/lib/square/api/inventory_api.rb +179 -366
  21. data/lib/square/api/invoices_api.rb +118 -237
  22. data/lib/square/api/labor_api.rb +223 -459
  23. data/lib/square/api/location_custom_attributes_api.rb +166 -331
  24. data/lib/square/api/locations_api.rb +54 -112
  25. data/lib/square/api/loyalty_api.rb +259 -512
  26. data/lib/square/api/merchants_api.rb +25 -60
  27. data/lib/square/api/mobile_authorization_api.rb +14 -30
  28. data/lib/square/api/o_auth_api.rb +54 -109
  29. data/lib/square/api/order_custom_attributes_api.rb +168 -333
  30. data/lib/square/api/orders_api.rb +115 -222
  31. data/lib/square/api/payments_api.rb +106 -208
  32. data/lib/square/api/payouts_api.rb +47 -100
  33. data/lib/square/api/refunds_api.rb +46 -93
  34. data/lib/square/api/sites_api.rb +11 -28
  35. data/lib/square/api/snippets_api.rb +42 -90
  36. data/lib/square/api/subscriptions_api.rb +150 -299
  37. data/lib/square/api/team_api.rb +114 -224
  38. data/lib/square/api/terminal_api.rb +162 -328
  39. data/lib/square/api/transactions_api.rb +62 -126
  40. data/lib/square/api/v1_transactions_api.rb +155 -296
  41. data/lib/square/api/vendors_api.rb +99 -192
  42. data/lib/square/api/webhook_subscriptions_api.rb +115 -235
  43. data/lib/square/api_helper.rb +1 -437
  44. data/lib/square/client.rb +77 -47
  45. data/lib/square/configuration.rb +28 -53
  46. data/lib/square/exceptions/api_exception.rb +1 -11
  47. data/lib/square/http/api_response.rb +13 -19
  48. data/lib/square/http/auth/o_auth2.rb +14 -7
  49. data/lib/square/http/http_call_back.rb +1 -15
  50. data/lib/square/http/http_method_enum.rb +1 -4
  51. data/lib/square/http/http_request.rb +1 -45
  52. data/lib/square/http/http_response.rb +1 -20
  53. data/lib/square/utilities/date_time_helper.rb +1 -146
  54. data/lib/square/utilities/file_wrapper.rb +5 -5
  55. data/lib/square.rb +6 -6
  56. data/spec/user_journey_spec.rb +2 -2
  57. data/test/api/api_test_base.rb +13 -5
  58. data/test/api/test_catalog_api.rb +5 -4
  59. data/test/api/test_customers_api.rb +3 -2
  60. data/test/api/test_employees_api.rb +4 -3
  61. data/test/api/test_labor_api.rb +6 -5
  62. data/test/api/test_locations_api.rb +3 -2
  63. data/test/api/test_merchants_api.rb +4 -3
  64. data/test/api/test_payments_api.rb +4 -3
  65. data/test/api/test_refunds_api.rb +4 -3
  66. metadata +11 -111
  67. data/lib/square/exceptions/validation_exception.rb +0 -13
  68. data/lib/square/http/faraday_client.rb +0 -93
  69. data/lib/square/http/http_client.rb +0 -118
  70. data/test/test_helper.rb +0 -89
@@ -1,10 +1,6 @@
1
1
  module Square
2
2
  # LocationCustomAttributesApi
3
3
  class LocationCustomAttributesApi < BaseApi
4
- def initialize(config, http_call_back: nil)
5
- super(config, http_call_back: http_call_back)
6
- end
7
-
8
4
  # Lists the location-related [custom attribute
9
5
  # definitions]($m/CustomAttributeDefinition) that belong to a Square seller
10
6
  # account.
@@ -32,36 +28,20 @@ module Square
32
28
  def list_location_custom_attribute_definitions(visibility_filter: nil,
33
29
  limit: nil,
34
30
  cursor: nil)
35
- # Prepare query url.
36
- _query_builder = config.get_base_uri
37
- _query_builder << '/v2/locations/custom-attribute-definitions'
38
- _query_builder = APIHelper.append_url_with_query_parameters(
39
- _query_builder,
40
- 'visibility_filter' => visibility_filter,
41
- 'limit' => limit,
42
- 'cursor' => cursor
43
- )
44
- _query_url = APIHelper.clean_url _query_builder
45
-
46
- # Prepare headers.
47
- _headers = {
48
- 'accept' => 'application/json'
49
- }
50
-
51
- # Prepare and execute HttpRequest.
52
- _request = config.http_client.get(
53
- _query_url,
54
- headers: _headers
55
- )
56
- OAuth2.apply(config, _request)
57
- _response = execute_request(_request)
58
-
59
- # Return appropriate response type.
60
- decoded = APIHelper.json_deserialize(_response.raw_body)
61
- _errors = APIHelper.map_response(decoded, ['errors'])
62
- ApiResponse.new(
63
- _response, data: decoded, errors: _errors
64
- )
31
+ new_api_call_builder
32
+ .request(new_request_builder(HttpMethodEnum::GET,
33
+ '/v2/locations/custom-attribute-definitions',
34
+ 'default')
35
+ .query_param(new_parameter(visibility_filter, key: 'visibility_filter'))
36
+ .query_param(new_parameter(limit, key: 'limit'))
37
+ .query_param(new_parameter(cursor, key: 'cursor'))
38
+ .header_param(new_parameter('application/json', key: 'accept'))
39
+ .auth(Single.new('global')))
40
+ .response(new_response_handler
41
+ .deserializer(APIHelper.method(:json_deserialize))
42
+ .is_api_response(true)
43
+ .convertor(ApiResponse.method(:create)))
44
+ .execute
65
45
  end
66
46
 
67
47
  # Creates a location-related [custom attribute
@@ -81,32 +61,20 @@ module Square
81
61
  # the corresponding object definition for field details.
82
62
  # @return [CreateLocationCustomAttributeDefinitionResponse Hash] response from the API call
83
63
  def create_location_custom_attribute_definition(body:)
84
- # Prepare query url.
85
- _query_builder = config.get_base_uri
86
- _query_builder << '/v2/locations/custom-attribute-definitions'
87
- _query_url = APIHelper.clean_url _query_builder
88
-
89
- # Prepare headers.
90
- _headers = {
91
- 'accept' => 'application/json',
92
- 'Content-Type' => 'application/json'
93
- }
94
-
95
- # Prepare and execute HttpRequest.
96
- _request = config.http_client.post(
97
- _query_url,
98
- headers: _headers,
99
- parameters: body.to_json
100
- )
101
- OAuth2.apply(config, _request)
102
- _response = execute_request(_request)
103
-
104
- # Return appropriate response type.
105
- decoded = APIHelper.json_deserialize(_response.raw_body)
106
- _errors = APIHelper.map_response(decoded, ['errors'])
107
- ApiResponse.new(
108
- _response, data: decoded, errors: _errors
109
- )
64
+ new_api_call_builder
65
+ .request(new_request_builder(HttpMethodEnum::POST,
66
+ '/v2/locations/custom-attribute-definitions',
67
+ 'default')
68
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
69
+ .body_param(new_parameter(body))
70
+ .header_param(new_parameter('application/json', key: 'accept'))
71
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
72
+ .auth(Single.new('global')))
73
+ .response(new_response_handler
74
+ .deserializer(APIHelper.method(:json_deserialize))
75
+ .is_api_response(true)
76
+ .convertor(ApiResponse.method(:create)))
77
+ .execute
110
78
  end
111
79
 
112
80
  # Deletes a location-related [custom attribute
@@ -119,34 +87,19 @@ module Square
119
87
  # definition to delete.
120
88
  # @return [DeleteLocationCustomAttributeDefinitionResponse Hash] response from the API call
121
89
  def delete_location_custom_attribute_definition(key:)
122
- # Prepare query url.
123
- _query_builder = config.get_base_uri
124
- _query_builder << '/v2/locations/custom-attribute-definitions/{key}'
125
- _query_builder = APIHelper.append_url_with_template_parameters(
126
- _query_builder,
127
- 'key' => { 'value' => key, 'encode' => true }
128
- )
129
- _query_url = APIHelper.clean_url _query_builder
130
-
131
- # Prepare headers.
132
- _headers = {
133
- 'accept' => 'application/json'
134
- }
135
-
136
- # Prepare and execute HttpRequest.
137
- _request = config.http_client.delete(
138
- _query_url,
139
- headers: _headers
140
- )
141
- OAuth2.apply(config, _request)
142
- _response = execute_request(_request)
143
-
144
- # Return appropriate response type.
145
- decoded = APIHelper.json_deserialize(_response.raw_body)
146
- _errors = APIHelper.map_response(decoded, ['errors'])
147
- ApiResponse.new(
148
- _response, data: decoded, errors: _errors
149
- )
90
+ new_api_call_builder
91
+ .request(new_request_builder(HttpMethodEnum::DELETE,
92
+ '/v2/locations/custom-attribute-definitions/{key}',
93
+ 'default')
94
+ .template_param(new_parameter(key, key: 'key')
95
+ .should_encode(true))
96
+ .header_param(new_parameter('application/json', key: 'accept'))
97
+ .auth(Single.new('global')))
98
+ .response(new_response_handler
99
+ .deserializer(APIHelper.method(:json_deserialize))
100
+ .is_api_response(true)
101
+ .convertor(ApiResponse.method(:create)))
102
+ .execute
150
103
  end
151
104
 
152
105
  # Retrieves a location-related [custom attribute
@@ -166,38 +119,20 @@ module Square
166
119
  # @return [RetrieveLocationCustomAttributeDefinitionResponse Hash] response from the API call
167
120
  def retrieve_location_custom_attribute_definition(key:,
168
121
  version: nil)
169
- # Prepare query url.
170
- _query_builder = config.get_base_uri
171
- _query_builder << '/v2/locations/custom-attribute-definitions/{key}'
172
- _query_builder = APIHelper.append_url_with_template_parameters(
173
- _query_builder,
174
- 'key' => { 'value' => key, 'encode' => true }
175
- )
176
- _query_builder = APIHelper.append_url_with_query_parameters(
177
- _query_builder,
178
- 'version' => version
179
- )
180
- _query_url = APIHelper.clean_url _query_builder
181
-
182
- # Prepare headers.
183
- _headers = {
184
- 'accept' => 'application/json'
185
- }
186
-
187
- # Prepare and execute HttpRequest.
188
- _request = config.http_client.get(
189
- _query_url,
190
- headers: _headers
191
- )
192
- OAuth2.apply(config, _request)
193
- _response = execute_request(_request)
194
-
195
- # Return appropriate response type.
196
- decoded = APIHelper.json_deserialize(_response.raw_body)
197
- _errors = APIHelper.map_response(decoded, ['errors'])
198
- ApiResponse.new(
199
- _response, data: decoded, errors: _errors
200
- )
122
+ new_api_call_builder
123
+ .request(new_request_builder(HttpMethodEnum::GET,
124
+ '/v2/locations/custom-attribute-definitions/{key}',
125
+ 'default')
126
+ .template_param(new_parameter(key, key: 'key')
127
+ .should_encode(true))
128
+ .query_param(new_parameter(version, key: 'version'))
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
201
136
  end
202
137
 
203
138
  # Updates a location-related [custom attribute
@@ -214,36 +149,22 @@ module Square
214
149
  # @return [UpdateLocationCustomAttributeDefinitionResponse Hash] response from the API call
215
150
  def update_location_custom_attribute_definition(key:,
216
151
  body:)
217
- # Prepare query url.
218
- _query_builder = config.get_base_uri
219
- _query_builder << '/v2/locations/custom-attribute-definitions/{key}'
220
- _query_builder = APIHelper.append_url_with_template_parameters(
221
- _query_builder,
222
- 'key' => { 'value' => key, 'encode' => true }
223
- )
224
- _query_url = APIHelper.clean_url _query_builder
225
-
226
- # Prepare headers.
227
- _headers = {
228
- 'accept' => 'application/json',
229
- 'Content-Type' => 'application/json'
230
- }
231
-
232
- # Prepare and execute HttpRequest.
233
- _request = config.http_client.put(
234
- _query_url,
235
- headers: _headers,
236
- parameters: body.to_json
237
- )
238
- OAuth2.apply(config, _request)
239
- _response = execute_request(_request)
240
-
241
- # Return appropriate response type.
242
- decoded = APIHelper.json_deserialize(_response.raw_body)
243
- _errors = APIHelper.map_response(decoded, ['errors'])
244
- ApiResponse.new(
245
- _response, data: decoded, errors: _errors
246
- )
152
+ new_api_call_builder
153
+ .request(new_request_builder(HttpMethodEnum::PUT,
154
+ '/v2/locations/custom-attribute-definitions/{key}',
155
+ 'default')
156
+ .template_param(new_parameter(key, key: 'key')
157
+ .should_encode(true))
158
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
159
+ .body_param(new_parameter(body))
160
+ .header_param(new_parameter('application/json', key: 'accept'))
161
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
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
247
168
  end
248
169
 
249
170
  # Deletes [custom attributes]($m/CustomAttribute) for locations as a bulk
@@ -256,32 +177,20 @@ module Square
256
177
  # the corresponding object definition for field details.
257
178
  # @return [BulkDeleteLocationCustomAttributesResponse Hash] response from the API call
258
179
  def bulk_delete_location_custom_attributes(body:)
259
- # Prepare query url.
260
- _query_builder = config.get_base_uri
261
- _query_builder << '/v2/locations/custom-attributes/bulk-delete'
262
- _query_url = APIHelper.clean_url _query_builder
263
-
264
- # Prepare headers.
265
- _headers = {
266
- 'accept' => 'application/json',
267
- 'Content-Type' => 'application/json'
268
- }
269
-
270
- # Prepare and execute HttpRequest.
271
- _request = config.http_client.post(
272
- _query_url,
273
- headers: _headers,
274
- parameters: body.to_json
275
- )
276
- OAuth2.apply(config, _request)
277
- _response = execute_request(_request)
278
-
279
- # Return appropriate response type.
280
- decoded = APIHelper.json_deserialize(_response.raw_body)
281
- _errors = APIHelper.map_response(decoded, ['errors'])
282
- ApiResponse.new(
283
- _response, data: decoded, errors: _errors
284
- )
180
+ new_api_call_builder
181
+ .request(new_request_builder(HttpMethodEnum::POST,
182
+ '/v2/locations/custom-attributes/bulk-delete',
183
+ 'default')
184
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
185
+ .body_param(new_parameter(body))
186
+ .header_param(new_parameter('application/json', key: 'accept'))
187
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
188
+ .auth(Single.new('global')))
189
+ .response(new_response_handler
190
+ .deserializer(APIHelper.method(:json_deserialize))
191
+ .is_api_response(true)
192
+ .convertor(ApiResponse.method(:create)))
193
+ .execute
285
194
  end
286
195
 
287
196
  # Creates or updates [custom attributes]($m/CustomAttribute) for locations
@@ -308,32 +217,20 @@ module Square
308
217
  # the corresponding object definition for field details.
309
218
  # @return [BulkUpsertLocationCustomAttributesResponse Hash] response from the API call
310
219
  def bulk_upsert_location_custom_attributes(body:)
311
- # Prepare query url.
312
- _query_builder = config.get_base_uri
313
- _query_builder << '/v2/locations/custom-attributes/bulk-upsert'
314
- _query_url = APIHelper.clean_url _query_builder
315
-
316
- # Prepare headers.
317
- _headers = {
318
- 'accept' => 'application/json',
319
- 'Content-Type' => 'application/json'
320
- }
321
-
322
- # Prepare and execute HttpRequest.
323
- _request = config.http_client.post(
324
- _query_url,
325
- headers: _headers,
326
- parameters: body.to_json
327
- )
328
- OAuth2.apply(config, _request)
329
- _response = execute_request(_request)
330
-
331
- # Return appropriate response type.
332
- decoded = APIHelper.json_deserialize(_response.raw_body)
333
- _errors = APIHelper.map_response(decoded, ['errors'])
334
- ApiResponse.new(
335
- _response, data: decoded, errors: _errors
336
- )
220
+ new_api_call_builder
221
+ .request(new_request_builder(HttpMethodEnum::POST,
222
+ '/v2/locations/custom-attributes/bulk-upsert',
223
+ 'default')
224
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
225
+ .body_param(new_parameter(body))
226
+ .header_param(new_parameter('application/json', key: 'accept'))
227
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
228
+ .auth(Single.new('global')))
229
+ .response(new_response_handler
230
+ .deserializer(APIHelper.method(:json_deserialize))
231
+ .is_api_response(true)
232
+ .convertor(ApiResponse.method(:create)))
233
+ .execute
337
234
  end
338
235
 
339
236
  # Lists the [custom attributes]($m/CustomAttribute) associated with a
@@ -374,41 +271,23 @@ module Square
374
271
  limit: nil,
375
272
  cursor: nil,
376
273
  with_definitions: false)
377
- # Prepare query url.
378
- _query_builder = config.get_base_uri
379
- _query_builder << '/v2/locations/{location_id}/custom-attributes'
380
- _query_builder = APIHelper.append_url_with_template_parameters(
381
- _query_builder,
382
- 'location_id' => { 'value' => location_id, 'encode' => true }
383
- )
384
- _query_builder = APIHelper.append_url_with_query_parameters(
385
- _query_builder,
386
- 'visibility_filter' => visibility_filter,
387
- 'limit' => limit,
388
- 'cursor' => cursor,
389
- 'with_definitions' => with_definitions
390
- )
391
- _query_url = APIHelper.clean_url _query_builder
392
-
393
- # Prepare headers.
394
- _headers = {
395
- 'accept' => 'application/json'
396
- }
397
-
398
- # Prepare and execute HttpRequest.
399
- _request = config.http_client.get(
400
- _query_url,
401
- headers: _headers
402
- )
403
- OAuth2.apply(config, _request)
404
- _response = execute_request(_request)
405
-
406
- # Return appropriate response type.
407
- decoded = APIHelper.json_deserialize(_response.raw_body)
408
- _errors = APIHelper.map_response(decoded, ['errors'])
409
- ApiResponse.new(
410
- _response, data: decoded, errors: _errors
411
- )
274
+ new_api_call_builder
275
+ .request(new_request_builder(HttpMethodEnum::GET,
276
+ '/v2/locations/{location_id}/custom-attributes',
277
+ 'default')
278
+ .template_param(new_parameter(location_id, key: 'location_id')
279
+ .should_encode(true))
280
+ .query_param(new_parameter(visibility_filter, key: 'visibility_filter'))
281
+ .query_param(new_parameter(limit, key: 'limit'))
282
+ .query_param(new_parameter(cursor, key: 'cursor'))
283
+ .query_param(new_parameter(with_definitions, key: 'with_definitions'))
284
+ .header_param(new_parameter('application/json', key: 'accept'))
285
+ .auth(Single.new('global')))
286
+ .response(new_response_handler
287
+ .deserializer(APIHelper.method(:json_deserialize))
288
+ .is_api_response(true)
289
+ .convertor(ApiResponse.method(:create)))
290
+ .execute
412
291
  end
413
292
 
414
293
  # Deletes a [custom attribute]($m/CustomAttribute) associated with a
@@ -425,35 +304,21 @@ module Square
425
304
  # @return [DeleteLocationCustomAttributeResponse Hash] response from the API call
426
305
  def delete_location_custom_attribute(location_id:,
427
306
  key:)
428
- # Prepare query url.
429
- _query_builder = config.get_base_uri
430
- _query_builder << '/v2/locations/{location_id}/custom-attributes/{key}'
431
- _query_builder = APIHelper.append_url_with_template_parameters(
432
- _query_builder,
433
- 'location_id' => { 'value' => location_id, 'encode' => true },
434
- 'key' => { 'value' => key, 'encode' => true }
435
- )
436
- _query_url = APIHelper.clean_url _query_builder
437
-
438
- # Prepare headers.
439
- _headers = {
440
- 'accept' => 'application/json'
441
- }
442
-
443
- # Prepare and execute HttpRequest.
444
- _request = config.http_client.delete(
445
- _query_url,
446
- headers: _headers
447
- )
448
- OAuth2.apply(config, _request)
449
- _response = execute_request(_request)
450
-
451
- # Return appropriate response type.
452
- decoded = APIHelper.json_deserialize(_response.raw_body)
453
- _errors = APIHelper.map_response(decoded, ['errors'])
454
- ApiResponse.new(
455
- _response, data: decoded, errors: _errors
456
- )
307
+ new_api_call_builder
308
+ .request(new_request_builder(HttpMethodEnum::DELETE,
309
+ '/v2/locations/{location_id}/custom-attributes/{key}',
310
+ 'default')
311
+ .template_param(new_parameter(location_id, key: 'location_id')
312
+ .should_encode(true))
313
+ .template_param(new_parameter(key, key: 'key')
314
+ .should_encode(true))
315
+ .header_param(new_parameter('application/json', key: 'accept'))
316
+ .auth(Single.new('global')))
317
+ .response(new_response_handler
318
+ .deserializer(APIHelper.method(:json_deserialize))
319
+ .is_api_response(true)
320
+ .convertor(ApiResponse.method(:create)))
321
+ .execute
457
322
  end
458
323
 
459
324
  # Retrieves a [custom attribute]($m/CustomAttribute) associated with a
@@ -487,40 +352,23 @@ module Square
487
352
  key:,
488
353
  with_definition: false,
489
354
  version: nil)
490
- # Prepare query url.
491
- _query_builder = config.get_base_uri
492
- _query_builder << '/v2/locations/{location_id}/custom-attributes/{key}'
493
- _query_builder = APIHelper.append_url_with_template_parameters(
494
- _query_builder,
495
- 'location_id' => { 'value' => location_id, 'encode' => true },
496
- 'key' => { 'value' => key, 'encode' => true }
497
- )
498
- _query_builder = APIHelper.append_url_with_query_parameters(
499
- _query_builder,
500
- 'with_definition' => with_definition,
501
- 'version' => version
502
- )
503
- _query_url = APIHelper.clean_url _query_builder
504
-
505
- # Prepare headers.
506
- _headers = {
507
- 'accept' => 'application/json'
508
- }
509
-
510
- # Prepare and execute HttpRequest.
511
- _request = config.http_client.get(
512
- _query_url,
513
- headers: _headers
514
- )
515
- OAuth2.apply(config, _request)
516
- _response = execute_request(_request)
517
-
518
- # Return appropriate response type.
519
- decoded = APIHelper.json_deserialize(_response.raw_body)
520
- _errors = APIHelper.map_response(decoded, ['errors'])
521
- ApiResponse.new(
522
- _response, data: decoded, errors: _errors
523
- )
355
+ new_api_call_builder
356
+ .request(new_request_builder(HttpMethodEnum::GET,
357
+ '/v2/locations/{location_id}/custom-attributes/{key}',
358
+ 'default')
359
+ .template_param(new_parameter(location_id, key: 'location_id')
360
+ .should_encode(true))
361
+ .template_param(new_parameter(key, key: 'key')
362
+ .should_encode(true))
363
+ .query_param(new_parameter(with_definition, key: 'with_definition'))
364
+ .query_param(new_parameter(version, key: 'version'))
365
+ .header_param(new_parameter('application/json', key: 'accept'))
366
+ .auth(Single.new('global')))
367
+ .response(new_response_handler
368
+ .deserializer(APIHelper.method(:json_deserialize))
369
+ .is_api_response(true)
370
+ .convertor(ApiResponse.method(:create)))
371
+ .execute
524
372
  end
525
373
 
526
374
  # Creates or updates a [custom attribute]($m/CustomAttribute) for a
@@ -548,37 +396,24 @@ module Square
548
396
  def upsert_location_custom_attribute(location_id:,
549
397
  key:,
550
398
  body:)
551
- # Prepare query url.
552
- _query_builder = config.get_base_uri
553
- _query_builder << '/v2/locations/{location_id}/custom-attributes/{key}'
554
- _query_builder = APIHelper.append_url_with_template_parameters(
555
- _query_builder,
556
- 'location_id' => { 'value' => location_id, 'encode' => true },
557
- 'key' => { 'value' => key, 'encode' => true }
558
- )
559
- _query_url = APIHelper.clean_url _query_builder
560
-
561
- # Prepare headers.
562
- _headers = {
563
- 'accept' => 'application/json',
564
- 'Content-Type' => 'application/json'
565
- }
566
-
567
- # Prepare and execute HttpRequest.
568
- _request = config.http_client.post(
569
- _query_url,
570
- headers: _headers,
571
- parameters: body.to_json
572
- )
573
- OAuth2.apply(config, _request)
574
- _response = execute_request(_request)
575
-
576
- # Return appropriate response type.
577
- decoded = APIHelper.json_deserialize(_response.raw_body)
578
- _errors = APIHelper.map_response(decoded, ['errors'])
579
- ApiResponse.new(
580
- _response, data: decoded, errors: _errors
581
- )
399
+ new_api_call_builder
400
+ .request(new_request_builder(HttpMethodEnum::POST,
401
+ '/v2/locations/{location_id}/custom-attributes/{key}',
402
+ 'default')
403
+ .template_param(new_parameter(location_id, key: 'location_id')
404
+ .should_encode(true))
405
+ .template_param(new_parameter(key, key: 'key')
406
+ .should_encode(true))
407
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
408
+ .body_param(new_parameter(body))
409
+ .header_param(new_parameter('application/json', key: 'accept'))
410
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
411
+ .auth(Single.new('global')))
412
+ .response(new_response_handler
413
+ .deserializer(APIHelper.method(:json_deserialize))
414
+ .is_api_response(true)
415
+ .convertor(ApiResponse.method(:create)))
416
+ .execute
582
417
  end
583
418
  end
584
419
  end