square.rb 26.1.0.20230119 → 27.0.0.20230419

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,10 +1,6 @@
1
1
  module Square
2
2
  # OrderCustomAttributesApi
3
3
  class OrderCustomAttributesApi < 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 order-related [custom attribute
9
5
  # definitions]($m/CustomAttributeDefinition) that belong to a Square seller
10
6
  # account.
@@ -21,7 +17,7 @@ module Square
21
17
  # read-only or read-write.
22
18
  # @param [String] cursor Optional parameter: The cursor returned in the
23
19
  # paged response from the previous call to this endpoint. Provide this
24
- # cursor to retrieve the next page of results for your original request.
20
+ # cursor to retrieve the next page of results for your original request.
25
21
  # For more information, see
26
22
  # [Pagination](https://developer.squareup.com/docs/working-with-apis/paginat
27
23
  # ion).
@@ -36,36 +32,20 @@ module Square
36
32
  def list_order_custom_attribute_definitions(visibility_filter: nil,
37
33
  cursor: nil,
38
34
  limit: nil)
39
- # Prepare query url.
40
- _query_builder = config.get_base_uri
41
- _query_builder << '/v2/orders/custom-attribute-definitions'
42
- _query_builder = APIHelper.append_url_with_query_parameters(
43
- _query_builder,
44
- 'visibility_filter' => visibility_filter,
45
- 'cursor' => cursor,
46
- 'limit' => limit
47
- )
48
- _query_url = APIHelper.clean_url _query_builder
49
-
50
- # Prepare headers.
51
- _headers = {
52
- 'accept' => 'application/json'
53
- }
54
-
55
- # Prepare and execute HttpRequest.
56
- _request = config.http_client.get(
57
- _query_url,
58
- headers: _headers
59
- )
60
- OAuth2.apply(config, _request)
61
- _response = execute_request(_request)
62
-
63
- # Return appropriate response type.
64
- decoded = APIHelper.json_deserialize(_response.raw_body)
65
- _errors = APIHelper.map_response(decoded, ['errors'])
66
- ApiResponse.new(
67
- _response, data: decoded, errors: _errors
68
- )
35
+ new_api_call_builder
36
+ .request(new_request_builder(HttpMethodEnum::GET,
37
+ '/v2/orders/custom-attribute-definitions',
38
+ 'default')
39
+ .query_param(new_parameter(visibility_filter, key: 'visibility_filter'))
40
+ .query_param(new_parameter(cursor, key: 'cursor'))
41
+ .query_param(new_parameter(limit, key: 'limit'))
42
+ .header_param(new_parameter('application/json', key: 'accept'))
43
+ .auth(Single.new('global')))
44
+ .response(new_response_handler
45
+ .deserializer(APIHelper.method(:json_deserialize))
46
+ .is_api_response(true)
47
+ .convertor(ApiResponse.method(:create)))
48
+ .execute
69
49
  end
70
50
 
71
51
  # Creates an order-related custom attribute definition. Use this endpoint
@@ -79,32 +59,20 @@ module Square
79
59
  # the corresponding object definition for field details.
80
60
  # @return [CreateOrderCustomAttributeDefinitionResponse Hash] response from the API call
81
61
  def create_order_custom_attribute_definition(body:)
82
- # Prepare query url.
83
- _query_builder = config.get_base_uri
84
- _query_builder << '/v2/orders/custom-attribute-definitions'
85
- _query_url = APIHelper.clean_url _query_builder
86
-
87
- # Prepare headers.
88
- _headers = {
89
- 'accept' => 'application/json',
90
- 'Content-Type' => 'application/json'
91
- }
92
-
93
- # Prepare and execute HttpRequest.
94
- _request = config.http_client.post(
95
- _query_url,
96
- headers: _headers,
97
- parameters: body.to_json
98
- )
99
- OAuth2.apply(config, _request)
100
- _response = execute_request(_request)
101
-
102
- # Return appropriate response type.
103
- decoded = APIHelper.json_deserialize(_response.raw_body)
104
- _errors = APIHelper.map_response(decoded, ['errors'])
105
- ApiResponse.new(
106
- _response, data: decoded, errors: _errors
107
- )
62
+ new_api_call_builder
63
+ .request(new_request_builder(HttpMethodEnum::POST,
64
+ '/v2/orders/custom-attribute-definitions',
65
+ 'default')
66
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
67
+ .body_param(new_parameter(body))
68
+ .header_param(new_parameter('application/json', key: 'accept'))
69
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
70
+ .auth(Single.new('global')))
71
+ .response(new_response_handler
72
+ .deserializer(APIHelper.method(:json_deserialize))
73
+ .is_api_response(true)
74
+ .convertor(ApiResponse.method(:create)))
75
+ .execute
108
76
  end
109
77
 
110
78
  # Deletes an order-related [custom attribute
@@ -114,34 +82,19 @@ module Square
114
82
  # definition to delete.
115
83
  # @return [DeleteOrderCustomAttributeDefinitionResponse Hash] response from the API call
116
84
  def delete_order_custom_attribute_definition(key:)
117
- # Prepare query url.
118
- _query_builder = config.get_base_uri
119
- _query_builder << '/v2/orders/custom-attribute-definitions/{key}'
120
- _query_builder = APIHelper.append_url_with_template_parameters(
121
- _query_builder,
122
- 'key' => { 'value' => key, 'encode' => true }
123
- )
124
- _query_url = APIHelper.clean_url _query_builder
125
-
126
- # Prepare headers.
127
- _headers = {
128
- 'accept' => 'application/json'
129
- }
130
-
131
- # Prepare and execute HttpRequest.
132
- _request = config.http_client.delete(
133
- _query_url,
134
- headers: _headers
135
- )
136
- OAuth2.apply(config, _request)
137
- _response = execute_request(_request)
138
-
139
- # Return appropriate response type.
140
- decoded = APIHelper.json_deserialize(_response.raw_body)
141
- _errors = APIHelper.map_response(decoded, ['errors'])
142
- ApiResponse.new(
143
- _response, data: decoded, errors: _errors
144
- )
85
+ new_api_call_builder
86
+ .request(new_request_builder(HttpMethodEnum::DELETE,
87
+ '/v2/orders/custom-attribute-definitions/{key}',
88
+ 'default')
89
+ .template_param(new_parameter(key, key: 'key')
90
+ .should_encode(true))
91
+ .header_param(new_parameter('application/json', key: 'accept'))
92
+ .auth(Single.new('global')))
93
+ .response(new_response_handler
94
+ .deserializer(APIHelper.method(:json_deserialize))
95
+ .is_api_response(true)
96
+ .convertor(ApiResponse.method(:create)))
97
+ .execute
145
98
  end
146
99
 
147
100
  # Retrieves an order-related [custom attribute
@@ -161,38 +114,20 @@ module Square
161
114
  # @return [RetrieveOrderCustomAttributeDefinitionResponse Hash] response from the API call
162
115
  def retrieve_order_custom_attribute_definition(key:,
163
116
  version: nil)
164
- # Prepare query url.
165
- _query_builder = config.get_base_uri
166
- _query_builder << '/v2/orders/custom-attribute-definitions/{key}'
167
- _query_builder = APIHelper.append_url_with_template_parameters(
168
- _query_builder,
169
- 'key' => { 'value' => key, 'encode' => true }
170
- )
171
- _query_builder = APIHelper.append_url_with_query_parameters(
172
- _query_builder,
173
- 'version' => version
174
- )
175
- _query_url = APIHelper.clean_url _query_builder
176
-
177
- # Prepare headers.
178
- _headers = {
179
- 'accept' => 'application/json'
180
- }
181
-
182
- # Prepare and execute HttpRequest.
183
- _request = config.http_client.get(
184
- _query_url,
185
- headers: _headers
186
- )
187
- OAuth2.apply(config, _request)
188
- _response = execute_request(_request)
189
-
190
- # Return appropriate response type.
191
- decoded = APIHelper.json_deserialize(_response.raw_body)
192
- _errors = APIHelper.map_response(decoded, ['errors'])
193
- ApiResponse.new(
194
- _response, data: decoded, errors: _errors
195
- )
117
+ new_api_call_builder
118
+ .request(new_request_builder(HttpMethodEnum::GET,
119
+ '/v2/orders/custom-attribute-definitions/{key}',
120
+ 'default')
121
+ .template_param(new_parameter(key, key: 'key')
122
+ .should_encode(true))
123
+ .query_param(new_parameter(version, key: 'version'))
124
+ .header_param(new_parameter('application/json', key: 'accept'))
125
+ .auth(Single.new('global')))
126
+ .response(new_response_handler
127
+ .deserializer(APIHelper.method(:json_deserialize))
128
+ .is_api_response(true)
129
+ .convertor(ApiResponse.method(:create)))
130
+ .execute
196
131
  end
197
132
 
198
133
  # Updates an order-related custom attribute definition for a Square seller
@@ -208,36 +143,22 @@ module Square
208
143
  # @return [UpdateOrderCustomAttributeDefinitionResponse Hash] response from the API call
209
144
  def update_order_custom_attribute_definition(key:,
210
145
  body:)
211
- # Prepare query url.
212
- _query_builder = config.get_base_uri
213
- _query_builder << '/v2/orders/custom-attribute-definitions/{key}'
214
- _query_builder = APIHelper.append_url_with_template_parameters(
215
- _query_builder,
216
- 'key' => { 'value' => key, 'encode' => true }
217
- )
218
- _query_url = APIHelper.clean_url _query_builder
219
-
220
- # Prepare headers.
221
- _headers = {
222
- 'accept' => 'application/json',
223
- 'Content-Type' => 'application/json'
224
- }
225
-
226
- # Prepare and execute HttpRequest.
227
- _request = config.http_client.put(
228
- _query_url,
229
- headers: _headers,
230
- parameters: body.to_json
231
- )
232
- OAuth2.apply(config, _request)
233
- _response = execute_request(_request)
234
-
235
- # Return appropriate response type.
236
- decoded = APIHelper.json_deserialize(_response.raw_body)
237
- _errors = APIHelper.map_response(decoded, ['errors'])
238
- ApiResponse.new(
239
- _response, data: decoded, errors: _errors
240
- )
146
+ new_api_call_builder
147
+ .request(new_request_builder(HttpMethodEnum::PUT,
148
+ '/v2/orders/custom-attribute-definitions/{key}',
149
+ 'default')
150
+ .template_param(new_parameter(key, key: 'key')
151
+ .should_encode(true))
152
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
153
+ .body_param(new_parameter(body))
154
+ .header_param(new_parameter('application/json', key: 'accept'))
155
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
156
+ .auth(Single.new('global')))
157
+ .response(new_response_handler
158
+ .deserializer(APIHelper.method(:json_deserialize))
159
+ .is_api_response(true)
160
+ .convertor(ApiResponse.method(:create)))
161
+ .execute
241
162
  end
242
163
 
243
164
  # Deletes order [custom attributes]($m/CustomAttribute) as a bulk operation.
@@ -266,32 +187,20 @@ module Square
266
187
  # corresponding object definition for field details.
267
188
  # @return [BulkDeleteOrderCustomAttributesResponse Hash] response from the API call
268
189
  def bulk_delete_order_custom_attributes(body:)
269
- # Prepare query url.
270
- _query_builder = config.get_base_uri
271
- _query_builder << '/v2/orders/custom-attributes/bulk-delete'
272
- _query_url = APIHelper.clean_url _query_builder
273
-
274
- # Prepare headers.
275
- _headers = {
276
- 'accept' => 'application/json',
277
- 'Content-Type' => 'application/json'
278
- }
279
-
280
- # Prepare and execute HttpRequest.
281
- _request = config.http_client.post(
282
- _query_url,
283
- headers: _headers,
284
- parameters: body.to_json
285
- )
286
- OAuth2.apply(config, _request)
287
- _response = execute_request(_request)
288
-
289
- # Return appropriate response type.
290
- decoded = APIHelper.json_deserialize(_response.raw_body)
291
- _errors = APIHelper.map_response(decoded, ['errors'])
292
- ApiResponse.new(
293
- _response, data: decoded, errors: _errors
294
- )
190
+ new_api_call_builder
191
+ .request(new_request_builder(HttpMethodEnum::POST,
192
+ '/v2/orders/custom-attributes/bulk-delete',
193
+ 'default')
194
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
195
+ .body_param(new_parameter(body))
196
+ .header_param(new_parameter('application/json', key: 'accept'))
197
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
198
+ .auth(Single.new('global')))
199
+ .response(new_response_handler
200
+ .deserializer(APIHelper.method(:json_deserialize))
201
+ .is_api_response(true)
202
+ .convertor(ApiResponse.method(:create)))
203
+ .execute
295
204
  end
296
205
 
297
206
  # Creates or updates order [custom attributes]($m/CustomAttribute) as a bulk
@@ -321,32 +230,20 @@ module Square
321
230
  # corresponding object definition for field details.
322
231
  # @return [BulkUpsertOrderCustomAttributesResponse Hash] response from the API call
323
232
  def bulk_upsert_order_custom_attributes(body:)
324
- # Prepare query url.
325
- _query_builder = config.get_base_uri
326
- _query_builder << '/v2/orders/custom-attributes/bulk-upsert'
327
- _query_url = APIHelper.clean_url _query_builder
328
-
329
- # Prepare headers.
330
- _headers = {
331
- 'accept' => 'application/json',
332
- 'Content-Type' => 'application/json'
333
- }
334
-
335
- # Prepare and execute HttpRequest.
336
- _request = config.http_client.post(
337
- _query_url,
338
- headers: _headers,
339
- parameters: body.to_json
340
- )
341
- OAuth2.apply(config, _request)
342
- _response = execute_request(_request)
343
-
344
- # Return appropriate response type.
345
- decoded = APIHelper.json_deserialize(_response.raw_body)
346
- _errors = APIHelper.map_response(decoded, ['errors'])
347
- ApiResponse.new(
348
- _response, data: decoded, errors: _errors
349
- )
233
+ new_api_call_builder
234
+ .request(new_request_builder(HttpMethodEnum::POST,
235
+ '/v2/orders/custom-attributes/bulk-upsert',
236
+ 'default')
237
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
238
+ .body_param(new_parameter(body))
239
+ .header_param(new_parameter('application/json', key: 'accept'))
240
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
241
+ .auth(Single.new('global')))
242
+ .response(new_response_handler
243
+ .deserializer(APIHelper.method(:json_deserialize))
244
+ .is_api_response(true)
245
+ .convertor(ApiResponse.method(:create)))
246
+ .execute
350
247
  end
351
248
 
352
249
  # Lists the [custom attributes]($m/CustomAttribute) associated with an
@@ -360,13 +257,13 @@ module Square
360
257
  # other applications
361
258
  # and set to `VISIBILITY_READ_ONLY` or `VISIBILITY_READ_WRITE_VALUES`.
362
259
  # @param [String] order_id Required parameter: The ID of the target
363
- # [order]($m/Order).
260
+ # [order](entity:Order).
364
261
  # @param [VisibilityFilter] visibility_filter Optional parameter: Requests
365
262
  # that all of the custom attributes be returned, or only those that are
366
263
  # read-only or read-write.
367
264
  # @param [String] cursor Optional parameter: The cursor returned in the
368
265
  # paged response from the previous call to this endpoint. Provide this
369
- # cursor to retrieve the next page of results for your original request.
266
+ # cursor to retrieve the next page of results for your original request.
370
267
  # For more information, see
371
268
  # [Pagination](https://developer.squareup.com/docs/working-with-apis/paginat
372
269
  # ion).
@@ -379,7 +276,7 @@ module Square
379
276
  # ion).
380
277
  # @param [TrueClass|FalseClass] with_definitions Optional parameter:
381
278
  # Indicates whether to return the [custom attribute
382
- # definition]($m/CustomAttributeDefinition) in the `definition` field of
279
+ # definition](entity:CustomAttributeDefinition) in the `definition` field of
383
280
  # each custom attribute. Set this parameter to `true` to get the name and
384
281
  # description of each custom attribute, information about the data type, or
385
282
  # other definition details. The default value is `false`.
@@ -389,41 +286,23 @@ module Square
389
286
  cursor: nil,
390
287
  limit: nil,
391
288
  with_definitions: false)
392
- # Prepare query url.
393
- _query_builder = config.get_base_uri
394
- _query_builder << '/v2/orders/{order_id}/custom-attributes'
395
- _query_builder = APIHelper.append_url_with_template_parameters(
396
- _query_builder,
397
- 'order_id' => { 'value' => order_id, 'encode' => true }
398
- )
399
- _query_builder = APIHelper.append_url_with_query_parameters(
400
- _query_builder,
401
- 'visibility_filter' => visibility_filter,
402
- 'cursor' => cursor,
403
- 'limit' => limit,
404
- 'with_definitions' => with_definitions
405
- )
406
- _query_url = APIHelper.clean_url _query_builder
407
-
408
- # Prepare headers.
409
- _headers = {
410
- 'accept' => 'application/json'
411
- }
412
-
413
- # Prepare and execute HttpRequest.
414
- _request = config.http_client.get(
415
- _query_url,
416
- headers: _headers
417
- )
418
- OAuth2.apply(config, _request)
419
- _response = execute_request(_request)
420
-
421
- # Return appropriate response type.
422
- decoded = APIHelper.json_deserialize(_response.raw_body)
423
- _errors = APIHelper.map_response(decoded, ['errors'])
424
- ApiResponse.new(
425
- _response, data: decoded, errors: _errors
426
- )
289
+ new_api_call_builder
290
+ .request(new_request_builder(HttpMethodEnum::GET,
291
+ '/v2/orders/{order_id}/custom-attributes',
292
+ 'default')
293
+ .template_param(new_parameter(order_id, key: 'order_id')
294
+ .should_encode(true))
295
+ .query_param(new_parameter(visibility_filter, key: 'visibility_filter'))
296
+ .query_param(new_parameter(cursor, key: 'cursor'))
297
+ .query_param(new_parameter(limit, key: 'limit'))
298
+ .query_param(new_parameter(with_definitions, key: 'with_definitions'))
299
+ .header_param(new_parameter('application/json', key: 'accept'))
300
+ .auth(Single.new('global')))
301
+ .response(new_response_handler
302
+ .deserializer(APIHelper.method(:json_deserialize))
303
+ .is_api_response(true)
304
+ .convertor(ApiResponse.method(:create)))
305
+ .execute
427
306
  end
428
307
 
429
308
  # Deletes a [custom attribute]($m/CustomAttribute) associated with a
@@ -434,42 +313,28 @@ module Square
434
313
  # (also known as custom fields) are always set to
435
314
  # `VISIBILITY_READ_WRITE_VALUES`.
436
315
  # @param [String] order_id Required parameter: The ID of the target
437
- # [order]($m/Order).
316
+ # [order](entity:Order).
438
317
  # @param [String] custom_attribute_key Required parameter: The key of the
439
318
  # custom attribute to delete. This key must match the key of an existing
440
319
  # custom attribute definition.
441
320
  # @return [DeleteOrderCustomAttributeResponse Hash] response from the API call
442
321
  def delete_order_custom_attribute(order_id:,
443
322
  custom_attribute_key:)
444
- # Prepare query url.
445
- _query_builder = config.get_base_uri
446
- _query_builder << '/v2/orders/{order_id}/custom-attributes/{custom_attribute_key}'
447
- _query_builder = APIHelper.append_url_with_template_parameters(
448
- _query_builder,
449
- 'order_id' => { 'value' => order_id, 'encode' => true },
450
- 'custom_attribute_key' => { 'value' => custom_attribute_key, 'encode' => true }
451
- )
452
- _query_url = APIHelper.clean_url _query_builder
453
-
454
- # Prepare headers.
455
- _headers = {
456
- 'accept' => 'application/json'
457
- }
458
-
459
- # Prepare and execute HttpRequest.
460
- _request = config.http_client.delete(
461
- _query_url,
462
- headers: _headers
463
- )
464
- OAuth2.apply(config, _request)
465
- _response = execute_request(_request)
466
-
467
- # Return appropriate response type.
468
- decoded = APIHelper.json_deserialize(_response.raw_body)
469
- _errors = APIHelper.map_response(decoded, ['errors'])
470
- ApiResponse.new(
471
- _response, data: decoded, errors: _errors
472
- )
323
+ new_api_call_builder
324
+ .request(new_request_builder(HttpMethodEnum::DELETE,
325
+ '/v2/orders/{order_id}/custom-attributes/{custom_attribute_key}',
326
+ 'default')
327
+ .template_param(new_parameter(order_id, key: 'order_id')
328
+ .should_encode(true))
329
+ .template_param(new_parameter(custom_attribute_key, key: 'custom_attribute_key')
330
+ .should_encode(true))
331
+ .header_param(new_parameter('application/json', key: 'accept'))
332
+ .auth(Single.new('global')))
333
+ .response(new_response_handler
334
+ .deserializer(APIHelper.method(:json_deserialize))
335
+ .is_api_response(true)
336
+ .convertor(ApiResponse.method(:create)))
337
+ .execute
473
338
  end
474
339
 
475
340
  # Retrieves a [custom attribute]($m/CustomAttribute) associated with an
@@ -484,7 +349,7 @@ module Square
484
349
  # also known as custom fields) are always set to
485
350
  # `VISIBILITY_READ_WRITE_VALUES`.
486
351
  # @param [String] order_id Required parameter: The ID of the target
487
- # [order]($m/Order).
352
+ # [order](entity:Order).
488
353
  # @param [String] custom_attribute_key Required parameter: The key of the
489
354
  # custom attribute to retrieve. This key must match the key of an existing
490
355
  # custom attribute definition.
@@ -494,7 +359,7 @@ module Square
494
359
  # specify the current version of the custom attribute.
495
360
  # @param [TrueClass|FalseClass] with_definition Optional parameter:
496
361
  # Indicates whether to return the [custom attribute
497
- # definition]($m/CustomAttributeDefinition) in the `definition` field of
362
+ # definition](entity:CustomAttributeDefinition) in the `definition` field of
498
363
  # each custom attribute. Set this parameter to `true` to get the name and
499
364
  # description of each custom attribute, information about the data type, or
500
365
  # other definition details. The default value is `false`.
@@ -503,40 +368,23 @@ module Square
503
368
  custom_attribute_key:,
504
369
  version: nil,
505
370
  with_definition: false)
506
- # Prepare query url.
507
- _query_builder = config.get_base_uri
508
- _query_builder << '/v2/orders/{order_id}/custom-attributes/{custom_attribute_key}'
509
- _query_builder = APIHelper.append_url_with_template_parameters(
510
- _query_builder,
511
- 'order_id' => { 'value' => order_id, 'encode' => true },
512
- 'custom_attribute_key' => { 'value' => custom_attribute_key, 'encode' => true }
513
- )
514
- _query_builder = APIHelper.append_url_with_query_parameters(
515
- _query_builder,
516
- 'version' => version,
517
- 'with_definition' => with_definition
518
- )
519
- _query_url = APIHelper.clean_url _query_builder
520
-
521
- # Prepare headers.
522
- _headers = {
523
- 'accept' => 'application/json'
524
- }
525
-
526
- # Prepare and execute HttpRequest.
527
- _request = config.http_client.get(
528
- _query_url,
529
- headers: _headers
530
- )
531
- OAuth2.apply(config, _request)
532
- _response = execute_request(_request)
533
-
534
- # Return appropriate response type.
535
- decoded = APIHelper.json_deserialize(_response.raw_body)
536
- _errors = APIHelper.map_response(decoded, ['errors'])
537
- ApiResponse.new(
538
- _response, data: decoded, errors: _errors
539
- )
371
+ new_api_call_builder
372
+ .request(new_request_builder(HttpMethodEnum::GET,
373
+ '/v2/orders/{order_id}/custom-attributes/{custom_attribute_key}',
374
+ 'default')
375
+ .template_param(new_parameter(order_id, key: 'order_id')
376
+ .should_encode(true))
377
+ .template_param(new_parameter(custom_attribute_key, key: 'custom_attribute_key')
378
+ .should_encode(true))
379
+ .query_param(new_parameter(version, key: 'version'))
380
+ .query_param(new_parameter(with_definition, key: 'with_definition'))
381
+ .header_param(new_parameter('application/json', key: 'accept'))
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
540
388
  end
541
389
 
542
390
  # Creates or updates a [custom attribute]($m/CustomAttribute) for an order.
@@ -554,7 +402,7 @@ module Square
554
402
  # (also known as custom fields) are always set to
555
403
  # `VISIBILITY_READ_WRITE_VALUES`.
556
404
  # @param [String] order_id Required parameter: The ID of the target
557
- # [order]($m/Order).
405
+ # [order](entity:Order).
558
406
  # @param [String] custom_attribute_key Required parameter: The key of the
559
407
  # custom attribute to create or update. This key must match the key of an
560
408
  # existing custom attribute definition.
@@ -565,37 +413,24 @@ module Square
565
413
  def upsert_order_custom_attribute(order_id:,
566
414
  custom_attribute_key:,
567
415
  body:)
568
- # Prepare query url.
569
- _query_builder = config.get_base_uri
570
- _query_builder << '/v2/orders/{order_id}/custom-attributes/{custom_attribute_key}'
571
- _query_builder = APIHelper.append_url_with_template_parameters(
572
- _query_builder,
573
- 'order_id' => { 'value' => order_id, 'encode' => true },
574
- 'custom_attribute_key' => { 'value' => custom_attribute_key, 'encode' => true }
575
- )
576
- _query_url = APIHelper.clean_url _query_builder
577
-
578
- # Prepare headers.
579
- _headers = {
580
- 'accept' => 'application/json',
581
- 'Content-Type' => 'application/json'
582
- }
583
-
584
- # Prepare and execute HttpRequest.
585
- _request = config.http_client.post(
586
- _query_url,
587
- headers: _headers,
588
- parameters: body.to_json
589
- )
590
- OAuth2.apply(config, _request)
591
- _response = execute_request(_request)
592
-
593
- # Return appropriate response type.
594
- decoded = APIHelper.json_deserialize(_response.raw_body)
595
- _errors = APIHelper.map_response(decoded, ['errors'])
596
- ApiResponse.new(
597
- _response, data: decoded, errors: _errors
598
- )
416
+ new_api_call_builder
417
+ .request(new_request_builder(HttpMethodEnum::POST,
418
+ '/v2/orders/{order_id}/custom-attributes/{custom_attribute_key}',
419
+ 'default')
420
+ .template_param(new_parameter(order_id, key: 'order_id')
421
+ .should_encode(true))
422
+ .template_param(new_parameter(custom_attribute_key, key: 'custom_attribute_key')
423
+ .should_encode(true))
424
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
425
+ .body_param(new_parameter(body))
426
+ .header_param(new_parameter('application/json', key: 'accept'))
427
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
428
+ .auth(Single.new('global')))
429
+ .response(new_response_handler
430
+ .deserializer(APIHelper.method(:json_deserialize))
431
+ .is_api_response(true)
432
+ .convertor(ApiResponse.method(:create)))
433
+ .execute
599
434
  end
600
435
  end
601
436
  end