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
@@ -0,0 +1,419 @@
1
+ module Square
2
+ # LocationCustomAttributesApi
3
+ class LocationCustomAttributesApi < BaseApi
4
+ # Lists the location-related [custom attribute
5
+ # definitions]($m/CustomAttributeDefinition) that belong to a Square seller
6
+ # account.
7
+ # When all response pages are retrieved, the results include all custom
8
+ # attribute definitions
9
+ # that are visible to the requesting application, including those that are
10
+ # created by other
11
+ # applications and set to `VISIBILITY_READ_ONLY` or
12
+ # `VISIBILITY_READ_WRITE_VALUES`.
13
+ # @param [VisibilityFilter] visibility_filter Optional parameter: Filters
14
+ # the `CustomAttributeDefinition` results by their `visibility` values.
15
+ # @param [Integer] limit Optional parameter: The maximum number of results
16
+ # to return in a single paged response. This limit is advisory. The response
17
+ # might contain more or fewer results. The minimum value is 1 and the
18
+ # maximum value is 100. The default value is 20. For more information, see
19
+ # [Pagination](https://developer.squareup.com/docs/build-basics/common-api-p
20
+ # atterns/pagination).
21
+ # @param [String] cursor Optional parameter: The cursor returned in the
22
+ # paged response from the previous call to this endpoint. Provide this
23
+ # cursor to retrieve the next page of results for your original request. For
24
+ # more information, see
25
+ # [Pagination](https://developer.squareup.com/docs/build-basics/common-api-p
26
+ # atterns/pagination).
27
+ # @return [ListLocationCustomAttributeDefinitionsResponse Hash] response from the API call
28
+ def list_location_custom_attribute_definitions(visibility_filter: nil,
29
+ limit: nil,
30
+ cursor: nil)
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
45
+ end
46
+
47
+ # Creates a location-related [custom attribute
48
+ # definition]($m/CustomAttributeDefinition) for a Square seller account.
49
+ # Use this endpoint to define a custom attribute that can be associated with
50
+ # locations.
51
+ # A custom attribute definition specifies the `key`, `visibility`, `schema`,
52
+ # and other properties
53
+ # for a custom attribute. After the definition is created, you can call
54
+ # [UpsertLocationCustomAttribute]($e/LocationCustomAttributes/UpsertLocation
55
+ # CustomAttribute) or
56
+ # [BulkUpsertLocationCustomAttributes]($e/LocationCustomAttributes/BulkUpser
57
+ # tLocationCustomAttributes)
58
+ # to set the custom attribute for locations.
59
+ # @param [CreateLocationCustomAttributeDefinitionRequest] body Required
60
+ # parameter: An object containing the fields to POST for the request. See
61
+ # the corresponding object definition for field details.
62
+ # @return [CreateLocationCustomAttributeDefinitionResponse Hash] response from the API call
63
+ def create_location_custom_attribute_definition(body:)
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
78
+ end
79
+
80
+ # Deletes a location-related [custom attribute
81
+ # definition]($m/CustomAttributeDefinition) from a Square seller account.
82
+ # Deleting a custom attribute definition also deletes the corresponding
83
+ # custom attribute from
84
+ # all locations.
85
+ # Only the definition owner can delete a custom attribute definition.
86
+ # @param [String] key Required parameter: The key of the custom attribute
87
+ # definition to delete.
88
+ # @return [DeleteLocationCustomAttributeDefinitionResponse Hash] response from the API call
89
+ def delete_location_custom_attribute_definition(key:)
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
103
+ end
104
+
105
+ # Retrieves a location-related [custom attribute
106
+ # definition]($m/CustomAttributeDefinition) from a Square seller account.
107
+ # To retrieve a custom attribute definition created by another application,
108
+ # the `visibility`
109
+ # setting must be `VISIBILITY_READ_ONLY` or `VISIBILITY_READ_WRITE_VALUES`.
110
+ # @param [String] key Required parameter: The key of the custom attribute
111
+ # definition to retrieve. If the requesting application is not the
112
+ # definition owner, you must use the qualified key.
113
+ # @param [Integer] version Optional parameter: The current version of the
114
+ # custom attribute definition, which is used for strongly consistent reads
115
+ # to guarantee that you receive the most up-to-date data. When included in
116
+ # the request, Square returns the specified version or a higher version if
117
+ # one exists. If the specified version is higher than the current version,
118
+ # Square returns a `BAD_REQUEST` error.
119
+ # @return [RetrieveLocationCustomAttributeDefinitionResponse Hash] response from the API call
120
+ def retrieve_location_custom_attribute_definition(key:,
121
+ version: nil)
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
136
+ end
137
+
138
+ # Updates a location-related [custom attribute
139
+ # definition]($m/CustomAttributeDefinition) for a Square seller account.
140
+ # Use this endpoint to update the following fields: `name`, `description`,
141
+ # `visibility`, or the
142
+ # `schema` for a `Selection` data type.
143
+ # Only the definition owner can update a custom attribute definition.
144
+ # @param [String] key Required parameter: The key of the custom attribute
145
+ # definition to update.
146
+ # @param [UpdateLocationCustomAttributeDefinitionRequest] body Required
147
+ # parameter: An object containing the fields to POST for the request. See
148
+ # the corresponding object definition for field details.
149
+ # @return [UpdateLocationCustomAttributeDefinitionResponse Hash] response from the API call
150
+ def update_location_custom_attribute_definition(key:,
151
+ body:)
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
168
+ end
169
+
170
+ # Deletes [custom attributes]($m/CustomAttribute) for locations as a bulk
171
+ # operation.
172
+ # To delete a custom attribute owned by another application, the
173
+ # `visibility` setting must be
174
+ # `VISIBILITY_READ_WRITE_VALUES`.
175
+ # @param [BulkDeleteLocationCustomAttributesRequest] body Required
176
+ # parameter: An object containing the fields to POST for the request. See
177
+ # the corresponding object definition for field details.
178
+ # @return [BulkDeleteLocationCustomAttributesResponse Hash] response from the API call
179
+ def bulk_delete_location_custom_attributes(body:)
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
194
+ end
195
+
196
+ # Creates or updates [custom attributes]($m/CustomAttribute) for locations
197
+ # as a bulk operation.
198
+ # Use this endpoint to set the value of one or more custom attributes for
199
+ # one or more locations.
200
+ # A custom attribute is based on a custom attribute definition in a Square
201
+ # seller account, which is
202
+ # created using the
203
+ # [CreateLocationCustomAttributeDefinition]($e/LocationCustomAttributes/Crea
204
+ # teLocationCustomAttributeDefinition) endpoint.
205
+ # This `BulkUpsertLocationCustomAttributes` endpoint accepts a map of 1 to
206
+ # 25 individual upsert
207
+ # requests and returns a map of individual upsert responses. Each upsert
208
+ # request has a unique ID
209
+ # and provides a location ID and custom attribute. Each upsert response is
210
+ # returned with the ID
211
+ # of the corresponding request.
212
+ # To create or update a custom attribute owned by another application, the
213
+ # `visibility` setting
214
+ # must be `VISIBILITY_READ_WRITE_VALUES`.
215
+ # @param [BulkUpsertLocationCustomAttributesRequest] body Required
216
+ # parameter: An object containing the fields to POST for the request. See
217
+ # the corresponding object definition for field details.
218
+ # @return [BulkUpsertLocationCustomAttributesResponse Hash] response from the API call
219
+ def bulk_upsert_location_custom_attributes(body:)
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
234
+ end
235
+
236
+ # Lists the [custom attributes]($m/CustomAttribute) associated with a
237
+ # location.
238
+ # You can use the `with_definitions` query parameter to also retrieve custom
239
+ # attribute definitions
240
+ # in the same call.
241
+ # When all response pages are retrieved, the results include all custom
242
+ # attributes that are
243
+ # visible to the requesting application, including those that are owned by
244
+ # other applications
245
+ # and set to `VISIBILITY_READ_ONLY` or `VISIBILITY_READ_WRITE_VALUES`.
246
+ # @param [String] location_id Required parameter: The ID of the target
247
+ # [location]($m/Location).
248
+ # @param [VisibilityFilter] visibility_filter Optional parameter: Filters
249
+ # the `CustomAttributeDefinition` results by their `visibility` values.
250
+ # @param [Integer] limit Optional parameter: The maximum number of results
251
+ # to return in a single paged response. This limit is advisory. The response
252
+ # might contain more or fewer results. The minimum value is 1 and the
253
+ # maximum value is 100. The default value is 20. For more information, see
254
+ # [Pagination](https://developer.squareup.com/docs/build-basics/common-api-p
255
+ # atterns/pagination).
256
+ # @param [String] cursor Optional parameter: The cursor returned in the
257
+ # paged response from the previous call to this endpoint. Provide this
258
+ # cursor to retrieve the next page of results for your original request. For
259
+ # more information, see
260
+ # [Pagination](https://developer.squareup.com/docs/build-basics/common-api-p
261
+ # atterns/pagination).
262
+ # @param [TrueClass|FalseClass] with_definitions Optional parameter:
263
+ # Indicates whether to return the [custom attribute
264
+ # definition]($m/CustomAttributeDefinition) in the `definition` field of
265
+ # each custom attribute. Set this parameter to `true` to get the name and
266
+ # description of each custom attribute, information about the data type, or
267
+ # other definition details. The default value is `false`.
268
+ # @return [ListLocationCustomAttributesResponse Hash] response from the API call
269
+ def list_location_custom_attributes(location_id:,
270
+ visibility_filter: nil,
271
+ limit: nil,
272
+ cursor: nil,
273
+ with_definitions: false)
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
291
+ end
292
+
293
+ # Deletes a [custom attribute]($m/CustomAttribute) associated with a
294
+ # location.
295
+ # To delete a custom attribute owned by another application, the
296
+ # `visibility` setting must be
297
+ # `VISIBILITY_READ_WRITE_VALUES`.
298
+ # @param [String] location_id Required parameter: The ID of the target
299
+ # [location]($m/Location).
300
+ # @param [String] key Required parameter: The key of the custom attribute to
301
+ # delete. This key must match the `key` of a custom attribute definition in
302
+ # the Square seller account. If the requesting application is not the
303
+ # definition owner, you must use the qualified key.
304
+ # @return [DeleteLocationCustomAttributeResponse Hash] response from the API call
305
+ def delete_location_custom_attribute(location_id:,
306
+ key:)
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
322
+ end
323
+
324
+ # Retrieves a [custom attribute]($m/CustomAttribute) associated with a
325
+ # location.
326
+ # You can use the `with_definition` query parameter to also retrieve the
327
+ # custom attribute definition
328
+ # in the same call.
329
+ # To retrieve a custom attribute owned by another application, the
330
+ # `visibility` setting must be
331
+ # `VISIBILITY_READ_ONLY` or `VISIBILITY_READ_WRITE_VALUES`.
332
+ # @param [String] location_id Required parameter: The ID of the target
333
+ # [location]($m/Location).
334
+ # @param [String] key Required parameter: The key of the custom attribute to
335
+ # retrieve. This key must match the `key` of a custom attribute definition
336
+ # in the Square seller account. If the requesting application is not the
337
+ # definition owner, you must use the qualified key.
338
+ # @param [TrueClass|FalseClass] with_definition Optional parameter:
339
+ # Indicates whether to return the [custom attribute
340
+ # definition]($m/CustomAttributeDefinition) in the `definition` field of the
341
+ # custom attribute. Set this parameter to `true` to get the name and
342
+ # description of the custom attribute, information about the data type, or
343
+ # other definition details. The default value is `false`.
344
+ # @param [Integer] version Optional parameter: The current version of the
345
+ # custom attribute, which is used for strongly consistent reads to guarantee
346
+ # that you receive the most up-to-date data. When included in the request,
347
+ # Square returns the specified version or a higher version if one exists. If
348
+ # the specified version is higher than the current version, Square returns a
349
+ # `BAD_REQUEST` error.
350
+ # @return [RetrieveLocationCustomAttributeResponse Hash] response from the API call
351
+ def retrieve_location_custom_attribute(location_id:,
352
+ key:,
353
+ with_definition: false,
354
+ version: nil)
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
372
+ end
373
+
374
+ # Creates or updates a [custom attribute]($m/CustomAttribute) for a
375
+ # location.
376
+ # Use this endpoint to set the value of a custom attribute for a specified
377
+ # location.
378
+ # A custom attribute is based on a custom attribute definition in a Square
379
+ # seller account, which
380
+ # is created using the
381
+ # [CreateLocationCustomAttributeDefinition]($e/LocationCustomAttributes/Crea
382
+ # teLocationCustomAttributeDefinition) endpoint.
383
+ # To create or update a custom attribute owned by another application, the
384
+ # `visibility` setting
385
+ # must be `VISIBILITY_READ_WRITE_VALUES`.
386
+ # @param [String] location_id Required parameter: The ID of the target
387
+ # [location]($m/Location).
388
+ # @param [String] key Required parameter: The key of the custom attribute to
389
+ # create or update. This key must match the `key` of a custom attribute
390
+ # definition in the Square seller account. If the requesting application is
391
+ # not the definition owner, you must use the qualified key.
392
+ # @param [UpsertLocationCustomAttributeRequest] body Required parameter: An
393
+ # object containing the fields to POST for the request. See the
394
+ # corresponding object definition for field details.
395
+ # @return [UpsertLocationCustomAttributeResponse Hash] response from the API call
396
+ def upsert_location_custom_attribute(location_id:,
397
+ key:,
398
+ body:)
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
417
+ end
418
+ end
419
+ end
@@ -1,39 +1,22 @@
1
1
  module Square
2
2
  # LocationsApi
3
3
  class LocationsApi < BaseApi
4
- def initialize(config, http_call_back: nil)
5
- super(config, http_call_back: http_call_back)
6
- end
7
-
8
4
  # Provides details about all of the seller's
9
5
  # [locations](https://developer.squareup.com/docs/locations-api),
10
6
  # including those with an inactive status.
11
7
  # @return [ListLocationsResponse Hash] response from the API call
12
8
  def list_locations
13
- # Prepare query url.
14
- _query_builder = config.get_base_uri
15
- _query_builder << '/v2/locations'
16
- _query_url = APIHelper.clean_url _query_builder
17
-
18
- # Prepare headers.
19
- _headers = {
20
- 'accept' => 'application/json'
21
- }
22
-
23
- # Prepare and execute HttpRequest.
24
- _request = config.http_client.get(
25
- _query_url,
26
- headers: _headers
27
- )
28
- OAuth2.apply(config, _request)
29
- _response = execute_request(_request)
30
-
31
- # Return appropriate response type.
32
- decoded = APIHelper.json_deserialize(_response.raw_body)
33
- _errors = APIHelper.map_response(decoded, ['errors'])
34
- ApiResponse.new(
35
- _response, data: decoded, errors: _errors
36
- )
9
+ new_api_call_builder
10
+ .request(new_request_builder(HttpMethodEnum::GET,
11
+ '/v2/locations',
12
+ 'default')
13
+ .header_param(new_parameter('application/json', key: 'accept'))
14
+ .auth(Single.new('global')))
15
+ .response(new_response_handler
16
+ .deserializer(APIHelper.method(:json_deserialize))
17
+ .is_api_response(true)
18
+ .convertor(ApiResponse.method(:create)))
19
+ .execute
37
20
  end
38
21
 
39
22
  # Creates a [location](https://developer.squareup.com/docs/locations-api).
@@ -51,32 +34,20 @@ module Square
51
34
  # object definition for field details.
52
35
  # @return [CreateLocationResponse Hash] response from the API call
53
36
  def create_location(body:)
54
- # Prepare query url.
55
- _query_builder = config.get_base_uri
56
- _query_builder << '/v2/locations'
57
- _query_url = APIHelper.clean_url _query_builder
58
-
59
- # Prepare headers.
60
- _headers = {
61
- 'accept' => 'application/json',
62
- 'Content-Type' => 'application/json'
63
- }
64
-
65
- # Prepare and execute HttpRequest.
66
- _request = config.http_client.post(
67
- _query_url,
68
- headers: _headers,
69
- parameters: body.to_json
70
- )
71
- OAuth2.apply(config, _request)
72
- _response = execute_request(_request)
73
-
74
- # Return appropriate response type.
75
- decoded = APIHelper.json_deserialize(_response.raw_body)
76
- _errors = APIHelper.map_response(decoded, ['errors'])
77
- ApiResponse.new(
78
- _response, data: decoded, errors: _errors
79
- )
37
+ new_api_call_builder
38
+ .request(new_request_builder(HttpMethodEnum::POST,
39
+ '/v2/locations',
40
+ 'default')
41
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
42
+ .body_param(new_parameter(body))
43
+ .header_param(new_parameter('application/json', key: 'accept'))
44
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
45
+ .auth(Single.new('global')))
46
+ .response(new_response_handler
47
+ .deserializer(APIHelper.method(:json_deserialize))
48
+ .is_api_response(true)
49
+ .convertor(ApiResponse.method(:create)))
50
+ .execute
80
51
  end
81
52
 
82
53
  # Retrieves details of a single location. Specify "main"
@@ -87,34 +58,19 @@ module Square
87
58
  # retrieve. Specify the string "main" to return the main location.
88
59
  # @return [RetrieveLocationResponse Hash] response from the API call
89
60
  def retrieve_location(location_id:)
90
- # Prepare query url.
91
- _query_builder = config.get_base_uri
92
- _query_builder << '/v2/locations/{location_id}'
93
- _query_builder = APIHelper.append_url_with_template_parameters(
94
- _query_builder,
95
- 'location_id' => { 'value' => location_id, 'encode' => true }
96
- )
97
- _query_url = APIHelper.clean_url _query_builder
98
-
99
- # Prepare headers.
100
- _headers = {
101
- 'accept' => 'application/json'
102
- }
103
-
104
- # Prepare and execute HttpRequest.
105
- _request = config.http_client.get(
106
- _query_url,
107
- headers: _headers
108
- )
109
- OAuth2.apply(config, _request)
110
- _response = execute_request(_request)
111
-
112
- # Return appropriate response type.
113
- decoded = APIHelper.json_deserialize(_response.raw_body)
114
- _errors = APIHelper.map_response(decoded, ['errors'])
115
- ApiResponse.new(
116
- _response, data: decoded, errors: _errors
117
- )
61
+ new_api_call_builder
62
+ .request(new_request_builder(HttpMethodEnum::GET,
63
+ '/v2/locations/{location_id}',
64
+ 'default')
65
+ .template_param(new_parameter(location_id, key: 'location_id')
66
+ .should_encode(true))
67
+ .header_param(new_parameter('application/json', key: 'accept'))
68
+ .auth(Single.new('global')))
69
+ .response(new_response_handler
70
+ .deserializer(APIHelper.method(:json_deserialize))
71
+ .is_api_response(true)
72
+ .convertor(ApiResponse.method(:create)))
73
+ .execute
118
74
  end
119
75
 
120
76
  # Updates a [location](https://developer.squareup.com/docs/locations-api).
@@ -126,36 +82,22 @@ module Square
126
82
  # @return [UpdateLocationResponse Hash] response from the API call
127
83
  def update_location(location_id:,
128
84
  body:)
129
- # Prepare query url.
130
- _query_builder = config.get_base_uri
131
- _query_builder << '/v2/locations/{location_id}'
132
- _query_builder = APIHelper.append_url_with_template_parameters(
133
- _query_builder,
134
- 'location_id' => { 'value' => location_id, 'encode' => true }
135
- )
136
- _query_url = APIHelper.clean_url _query_builder
137
-
138
- # Prepare headers.
139
- _headers = {
140
- 'accept' => 'application/json',
141
- 'Content-Type' => 'application/json'
142
- }
143
-
144
- # Prepare and execute HttpRequest.
145
- _request = config.http_client.put(
146
- _query_url,
147
- headers: _headers,
148
- parameters: body.to_json
149
- )
150
- OAuth2.apply(config, _request)
151
- _response = execute_request(_request)
152
-
153
- # Return appropriate response type.
154
- decoded = APIHelper.json_deserialize(_response.raw_body)
155
- _errors = APIHelper.map_response(decoded, ['errors'])
156
- ApiResponse.new(
157
- _response, data: decoded, errors: _errors
158
- )
85
+ new_api_call_builder
86
+ .request(new_request_builder(HttpMethodEnum::PUT,
87
+ '/v2/locations/{location_id}',
88
+ 'default')
89
+ .template_param(new_parameter(location_id, key: 'location_id')
90
+ .should_encode(true))
91
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
92
+ .body_param(new_parameter(body))
93
+ .header_param(new_parameter('application/json', key: 'accept'))
94
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
95
+ .auth(Single.new('global')))
96
+ .response(new_response_handler
97
+ .deserializer(APIHelper.method(:json_deserialize))
98
+ .is_api_response(true)
99
+ .convertor(ApiResponse.method(:create)))
100
+ .execute
159
101
  end
160
102
  end
161
103
  end