square.rb 3.3.0.20191217

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 (51) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +10 -0
  3. data/README.md +285 -0
  4. data/lib/square/api/apple_pay_api.rb +50 -0
  5. data/lib/square/api/base_api.rb +43 -0
  6. data/lib/square/api/cash_drawers_api.rb +150 -0
  7. data/lib/square/api/catalog_api.rb +545 -0
  8. data/lib/square/api/checkout_api.rb +49 -0
  9. data/lib/square/api/customers_api.rb +327 -0
  10. data/lib/square/api/employees_api.rb +86 -0
  11. data/lib/square/api/inventory_api.rb +295 -0
  12. data/lib/square/api/labor_api.rb +553 -0
  13. data/lib/square/api/locations_api.rb +146 -0
  14. data/lib/square/api/merchants_api.rb +82 -0
  15. data/lib/square/api/mobile_authorization_api.rb +52 -0
  16. data/lib/square/api/o_auth_api.rb +163 -0
  17. data/lib/square/api/orders_api.rb +266 -0
  18. data/lib/square/api/payments_api.rb +277 -0
  19. data/lib/square/api/refunds_api.rb +144 -0
  20. data/lib/square/api/reporting_api.rb +138 -0
  21. data/lib/square/api/transactions_api.rb +377 -0
  22. data/lib/square/api/v1_employees_api.rb +715 -0
  23. data/lib/square/api/v1_items_api.rb +2046 -0
  24. data/lib/square/api/v1_locations_api.rb +83 -0
  25. data/lib/square/api/v1_transactions_api.rb +568 -0
  26. data/lib/square/api_helper.rb +276 -0
  27. data/lib/square/client.rb +156 -0
  28. data/lib/square/configuration.rb +93 -0
  29. data/lib/square/exceptions/api_exception.rb +15 -0
  30. data/lib/square/http/api_response.rb +45 -0
  31. data/lib/square/http/auth/o_auth2.rb +12 -0
  32. data/lib/square/http/faraday_client.rb +59 -0
  33. data/lib/square/http/http_call_back.rb +19 -0
  34. data/lib/square/http/http_client.rb +99 -0
  35. data/lib/square/http/http_method_enum.rb +8 -0
  36. data/lib/square/http/http_request.rb +45 -0
  37. data/lib/square/http/http_response.rb +24 -0
  38. data/lib/square.rb +49 -0
  39. data/spec/user_journey_spec.rb +145 -0
  40. data/test/api/api_test_base.rb +24 -0
  41. data/test/api/test_catalog_api.rb +59 -0
  42. data/test/api/test_customers_api.rb +45 -0
  43. data/test/api/test_employees_api.rb +36 -0
  44. data/test/api/test_labor_api.rb +74 -0
  45. data/test/api/test_locations_api.rb +35 -0
  46. data/test/api/test_merchants_api.rb +40 -0
  47. data/test/api/test_payments_api.rb +42 -0
  48. data/test/api/test_refunds_api.rb +41 -0
  49. data/test/http_response_catcher.rb +19 -0
  50. data/test/test_helper.rb +94 -0
  51. metadata +190 -0
@@ -0,0 +1,553 @@
1
+ module Square
2
+ # LaborApi
3
+ class LaborApi < BaseApi
4
+ def initialize(config, http_call_back: nil)
5
+ super(config, http_call_back: http_call_back)
6
+ end
7
+
8
+ # Returns a paginated list of `BreakType` instances for a business.
9
+ # @param [String] location_id Optional parameter: Filter Break Types
10
+ # returned to only those that are associated with the specified location.
11
+ # @param [Integer] limit Optional parameter: Maximum number of Break Types
12
+ # to return per page. Can range between 1 and 200. The default is the
13
+ # maximum at 200.
14
+ # @param [String] cursor Optional parameter: Pointer to the next page of
15
+ # Break Type results to fetch.
16
+ # @return [ListBreakTypesResponse Hash] response from the API call
17
+ def list_break_types(location_id: nil,
18
+ limit: nil,
19
+ cursor: nil)
20
+ # Prepare query url.
21
+ _query_builder = config.get_base_uri
22
+ _query_builder << '/v2/labor/break-types'
23
+ _query_builder = APIHelper.append_url_with_query_parameters(
24
+ _query_builder,
25
+ 'location_id' => location_id,
26
+ 'limit' => limit,
27
+ 'cursor' => cursor
28
+ )
29
+ _query_url = APIHelper.clean_url _query_builder
30
+
31
+ # Prepare headers.
32
+ _headers = {
33
+ 'accept' => 'application/json'
34
+ }
35
+
36
+ # Prepare and execute HttpRequest.
37
+ _request = config.http_client.get(
38
+ _query_url,
39
+ headers: _headers
40
+ )
41
+ OAuth2.apply(config, _request)
42
+ _response = execute_request(_request)
43
+
44
+ # Return appropriate response type.
45
+ decoded = APIHelper.json_deserialize(_response.raw_body)
46
+ _errors = APIHelper.map_response(decoded, ['errors'])
47
+ ApiResponse.new(_response, data: decoded, errors: _errors)
48
+ end
49
+
50
+ # Creates a new `BreakType`.
51
+ # A `BreakType` is a template for creating `Break` objects.
52
+ # You must provide the following values in your request to this
53
+ # endpoint:
54
+ # - `location_id`
55
+ # - `break_name`
56
+ # - `expected_duration`
57
+ # - `is_paid`
58
+ # You can only have 3 `BreakType` instances per location. If you attempt to
59
+ # add a 4th
60
+ # `BreakType` for a location, an `INVALID_REQUEST_ERROR` "Exceeded limit of
61
+ # 3 breaks per location."
62
+ # is returned.
63
+ # @param [CreateBreakTypeRequest] body Required parameter: An object
64
+ # containing the fields to POST for the request. See the corresponding
65
+ # object definition for field details.
66
+ # @return [CreateBreakTypeResponse Hash] response from the API call
67
+ def create_break_type(body:)
68
+ # Prepare query url.
69
+ _query_builder = config.get_base_uri
70
+ _query_builder << '/v2/labor/break-types'
71
+ _query_url = APIHelper.clean_url _query_builder
72
+
73
+ # Prepare headers.
74
+ _headers = {
75
+ 'accept' => 'application/json',
76
+ 'content-type' => 'application/json; charset=utf-8'
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(_response, data: decoded, errors: _errors)
92
+ end
93
+
94
+ # Deletes an existing `BreakType`.
95
+ # A `BreakType` can be deleted even if it is referenced from a `Shift`.
96
+ # @param [String] id Required parameter: UUID for the `BreakType` being
97
+ # deleted.
98
+ # @return [DeleteBreakTypeResponse Hash] response from the API call
99
+ def delete_break_type(id:)
100
+ # Prepare query url.
101
+ _query_builder = config.get_base_uri
102
+ _query_builder << '/v2/labor/break-types/{id}'
103
+ _query_builder = APIHelper.append_url_with_template_parameters(
104
+ _query_builder,
105
+ 'id' => id
106
+ )
107
+ _query_url = APIHelper.clean_url _query_builder
108
+
109
+ # Prepare headers.
110
+ _headers = {
111
+ 'accept' => 'application/json'
112
+ }
113
+
114
+ # Prepare and execute HttpRequest.
115
+ _request = config.http_client.delete(
116
+ _query_url,
117
+ headers: _headers
118
+ )
119
+ OAuth2.apply(config, _request)
120
+ _response = execute_request(_request)
121
+
122
+ # Return appropriate response type.
123
+ decoded = APIHelper.json_deserialize(_response.raw_body)
124
+ _errors = APIHelper.map_response(decoded, ['errors'])
125
+ ApiResponse.new(_response, data: decoded, errors: _errors)
126
+ end
127
+
128
+ # Returns a single `BreakType` specified by id.
129
+ # @param [String] id Required parameter: UUID for the `BreakType` being
130
+ # retrieved.
131
+ # @return [GetBreakTypeResponse Hash] response from the API call
132
+ def get_break_type(id:)
133
+ # Prepare query url.
134
+ _query_builder = config.get_base_uri
135
+ _query_builder << '/v2/labor/break-types/{id}'
136
+ _query_builder = APIHelper.append_url_with_template_parameters(
137
+ _query_builder,
138
+ 'id' => id
139
+ )
140
+ _query_url = APIHelper.clean_url _query_builder
141
+
142
+ # Prepare headers.
143
+ _headers = {
144
+ 'accept' => 'application/json'
145
+ }
146
+
147
+ # Prepare and execute HttpRequest.
148
+ _request = config.http_client.get(
149
+ _query_url,
150
+ headers: _headers
151
+ )
152
+ OAuth2.apply(config, _request)
153
+ _response = execute_request(_request)
154
+
155
+ # Return appropriate response type.
156
+ decoded = APIHelper.json_deserialize(_response.raw_body)
157
+ _errors = APIHelper.map_response(decoded, ['errors'])
158
+ ApiResponse.new(_response, data: decoded, errors: _errors)
159
+ end
160
+
161
+ # Updates an existing `BreakType`.
162
+ # @param [String] id Required parameter: UUID for the `BreakType` being
163
+ # updated.
164
+ # @param [UpdateBreakTypeRequest] body Required parameter: An object
165
+ # containing the fields to POST for the request. See the corresponding
166
+ # object definition for field details.
167
+ # @return [UpdateBreakTypeResponse Hash] response from the API call
168
+ def update_break_type(id:,
169
+ body:)
170
+ # Prepare query url.
171
+ _query_builder = config.get_base_uri
172
+ _query_builder << '/v2/labor/break-types/{id}'
173
+ _query_builder = APIHelper.append_url_with_template_parameters(
174
+ _query_builder,
175
+ 'id' => id
176
+ )
177
+ _query_url = APIHelper.clean_url _query_builder
178
+
179
+ # Prepare headers.
180
+ _headers = {
181
+ 'accept' => 'application/json',
182
+ 'content-type' => 'application/json; charset=utf-8'
183
+ }
184
+
185
+ # Prepare and execute HttpRequest.
186
+ _request = config.http_client.put(
187
+ _query_url,
188
+ headers: _headers,
189
+ parameters: body.to_json
190
+ )
191
+ OAuth2.apply(config, _request)
192
+ _response = execute_request(_request)
193
+
194
+ # Return appropriate response type.
195
+ decoded = APIHelper.json_deserialize(_response.raw_body)
196
+ _errors = APIHelper.map_response(decoded, ['errors'])
197
+ ApiResponse.new(_response, data: decoded, errors: _errors)
198
+ end
199
+
200
+ # Returns a paginated list of `EmployeeWage` instances for a business.
201
+ # @param [String] employee_id Optional parameter: Filter wages returned to
202
+ # only those that are associated with the specified employee.
203
+ # @param [Integer] limit Optional parameter: Maximum number of Employee
204
+ # Wages to return per page. Can range between 1 and 200. The default is the
205
+ # maximum at 200.
206
+ # @param [String] cursor Optional parameter: Pointer to the next page of
207
+ # Employee Wage results to fetch.
208
+ # @return [ListEmployeeWagesResponse Hash] response from the API call
209
+ def list_employee_wages(employee_id: nil,
210
+ limit: nil,
211
+ cursor: nil)
212
+ # Prepare query url.
213
+ _query_builder = config.get_base_uri
214
+ _query_builder << '/v2/labor/employee-wages'
215
+ _query_builder = APIHelper.append_url_with_query_parameters(
216
+ _query_builder,
217
+ 'employee_id' => employee_id,
218
+ 'limit' => limit,
219
+ 'cursor' => cursor
220
+ )
221
+ _query_url = APIHelper.clean_url _query_builder
222
+
223
+ # Prepare headers.
224
+ _headers = {
225
+ 'accept' => 'application/json'
226
+ }
227
+
228
+ # Prepare and execute HttpRequest.
229
+ _request = config.http_client.get(
230
+ _query_url,
231
+ headers: _headers
232
+ )
233
+ OAuth2.apply(config, _request)
234
+ _response = execute_request(_request)
235
+
236
+ # Return appropriate response type.
237
+ decoded = APIHelper.json_deserialize(_response.raw_body)
238
+ _errors = APIHelper.map_response(decoded, ['errors'])
239
+ ApiResponse.new(_response, data: decoded, errors: _errors)
240
+ end
241
+
242
+ # Returns a single `EmployeeWage` specified by id.
243
+ # @param [String] id Required parameter: UUID for the `EmployeeWage` being
244
+ # retrieved.
245
+ # @return [GetEmployeeWageResponse Hash] response from the API call
246
+ def get_employee_wage(id:)
247
+ # Prepare query url.
248
+ _query_builder = config.get_base_uri
249
+ _query_builder << '/v2/labor/employee-wages/{id}'
250
+ _query_builder = APIHelper.append_url_with_template_parameters(
251
+ _query_builder,
252
+ 'id' => id
253
+ )
254
+ _query_url = APIHelper.clean_url _query_builder
255
+
256
+ # Prepare headers.
257
+ _headers = {
258
+ 'accept' => 'application/json'
259
+ }
260
+
261
+ # Prepare and execute HttpRequest.
262
+ _request = config.http_client.get(
263
+ _query_url,
264
+ headers: _headers
265
+ )
266
+ OAuth2.apply(config, _request)
267
+ _response = execute_request(_request)
268
+
269
+ # Return appropriate response type.
270
+ decoded = APIHelper.json_deserialize(_response.raw_body)
271
+ _errors = APIHelper.map_response(decoded, ['errors'])
272
+ ApiResponse.new(_response, data: decoded, errors: _errors)
273
+ end
274
+
275
+ # Creates a new `Shift`.
276
+ # A `Shift` represents a complete work day for a single employee.
277
+ # You must provide the following values in your request to this
278
+ # endpoint:
279
+ # - `location_id`
280
+ # - `employee_id`
281
+ # - `start_at`
282
+ # An attempt to create a new `Shift` can result in a `BAD_REQUEST` error
283
+ # when:
284
+ # - The `status` of the new `Shift` is `OPEN` and the employee has another
285
+ # shift with an `OPEN` status.
286
+ # - The `start_at` date is in the future
287
+ # - the `start_at` or `end_at` overlaps another shift for the same employee
288
+ # - If `Break`s are set in the request, a break `start_at`
289
+ # must not be before the `Shift.start_at`. A break `end_at` must not be
290
+ # after
291
+ # the `Shift.end_at`
292
+ # @param [CreateShiftRequest] body Required parameter: An object containing
293
+ # the fields to POST for the request. See the corresponding object
294
+ # definition for field details.
295
+ # @return [CreateShiftResponse Hash] response from the API call
296
+ def create_shift(body:)
297
+ # Prepare query url.
298
+ _query_builder = config.get_base_uri
299
+ _query_builder << '/v2/labor/shifts'
300
+ _query_url = APIHelper.clean_url _query_builder
301
+
302
+ # Prepare headers.
303
+ _headers = {
304
+ 'accept' => 'application/json',
305
+ 'content-type' => 'application/json; charset=utf-8'
306
+ }
307
+
308
+ # Prepare and execute HttpRequest.
309
+ _request = config.http_client.post(
310
+ _query_url,
311
+ headers: _headers,
312
+ parameters: body.to_json
313
+ )
314
+ OAuth2.apply(config, _request)
315
+ _response = execute_request(_request)
316
+
317
+ # Return appropriate response type.
318
+ decoded = APIHelper.json_deserialize(_response.raw_body)
319
+ _errors = APIHelper.map_response(decoded, ['errors'])
320
+ ApiResponse.new(_response, data: decoded, errors: _errors)
321
+ end
322
+
323
+ # Returns a paginated list of `Shift` records for a business.
324
+ # The list to be returned can be filtered by:
325
+ # - Location IDs **and**
326
+ # - employee IDs **and**
327
+ # - shift status (`OPEN`, `CLOSED`) **and**
328
+ # - shift start **and**
329
+ # - shift end **and**
330
+ # - work day details
331
+ # The list can be sorted by:
332
+ # - `start_at`
333
+ # - `end_at`
334
+ # - `created_at`
335
+ # - `updated_at`
336
+ # @param [SearchShiftsRequest] body Required parameter: An object containing
337
+ # the fields to POST for the request. See the corresponding object
338
+ # definition for field details.
339
+ # @return [SearchShiftsResponse Hash] response from the API call
340
+ def search_shifts(body:)
341
+ # Prepare query url.
342
+ _query_builder = config.get_base_uri
343
+ _query_builder << '/v2/labor/shifts/search'
344
+ _query_url = APIHelper.clean_url _query_builder
345
+
346
+ # Prepare headers.
347
+ _headers = {
348
+ 'accept' => 'application/json',
349
+ 'content-type' => 'application/json; charset=utf-8'
350
+ }
351
+
352
+ # Prepare and execute HttpRequest.
353
+ _request = config.http_client.post(
354
+ _query_url,
355
+ headers: _headers,
356
+ parameters: body.to_json
357
+ )
358
+ OAuth2.apply(config, _request)
359
+ _response = execute_request(_request)
360
+
361
+ # Return appropriate response type.
362
+ decoded = APIHelper.json_deserialize(_response.raw_body)
363
+ _errors = APIHelper.map_response(decoded, ['errors'])
364
+ ApiResponse.new(_response, data: decoded, errors: _errors)
365
+ end
366
+
367
+ # Deletes a `Shift`.
368
+ # @param [String] id Required parameter: UUID for the `Shift` being
369
+ # deleted.
370
+ # @return [DeleteShiftResponse Hash] response from the API call
371
+ def delete_shift(id:)
372
+ # Prepare query url.
373
+ _query_builder = config.get_base_uri
374
+ _query_builder << '/v2/labor/shifts/{id}'
375
+ _query_builder = APIHelper.append_url_with_template_parameters(
376
+ _query_builder,
377
+ 'id' => id
378
+ )
379
+ _query_url = APIHelper.clean_url _query_builder
380
+
381
+ # Prepare headers.
382
+ _headers = {
383
+ 'accept' => 'application/json'
384
+ }
385
+
386
+ # Prepare and execute HttpRequest.
387
+ _request = config.http_client.delete(
388
+ _query_url,
389
+ headers: _headers
390
+ )
391
+ OAuth2.apply(config, _request)
392
+ _response = execute_request(_request)
393
+
394
+ # Return appropriate response type.
395
+ decoded = APIHelper.json_deserialize(_response.raw_body)
396
+ _errors = APIHelper.map_response(decoded, ['errors'])
397
+ ApiResponse.new(_response, data: decoded, errors: _errors)
398
+ end
399
+
400
+ # Returns a single `Shift` specified by id.
401
+ # @param [String] id Required parameter: UUID for the `Shift` being
402
+ # retrieved.
403
+ # @return [GetShiftResponse Hash] response from the API call
404
+ def get_shift(id:)
405
+ # Prepare query url.
406
+ _query_builder = config.get_base_uri
407
+ _query_builder << '/v2/labor/shifts/{id}'
408
+ _query_builder = APIHelper.append_url_with_template_parameters(
409
+ _query_builder,
410
+ 'id' => id
411
+ )
412
+ _query_url = APIHelper.clean_url _query_builder
413
+
414
+ # Prepare headers.
415
+ _headers = {
416
+ 'accept' => 'application/json'
417
+ }
418
+
419
+ # Prepare and execute HttpRequest.
420
+ _request = config.http_client.get(
421
+ _query_url,
422
+ headers: _headers
423
+ )
424
+ OAuth2.apply(config, _request)
425
+ _response = execute_request(_request)
426
+
427
+ # Return appropriate response type.
428
+ decoded = APIHelper.json_deserialize(_response.raw_body)
429
+ _errors = APIHelper.map_response(decoded, ['errors'])
430
+ ApiResponse.new(_response, data: decoded, errors: _errors)
431
+ end
432
+
433
+ # Updates an existing `Shift`.
434
+ # When adding a `Break` to a `Shift`, any earlier `Breaks` in the `Shift`
435
+ # have
436
+ # the `end_at` property set to a valid RFC-3339 datetime string.
437
+ # When closing a `Shift`, all `Break` instances in the shift must be
438
+ # complete with `end_at`
439
+ # set on each `Break`.
440
+ # @param [String] id Required parameter: ID of the object being updated.
441
+ # @param [UpdateShiftRequest] body Required parameter: An object containing
442
+ # the fields to POST for the request. See the corresponding object
443
+ # definition for field details.
444
+ # @return [UpdateShiftResponse Hash] response from the API call
445
+ def update_shift(id:,
446
+ body:)
447
+ # Prepare query url.
448
+ _query_builder = config.get_base_uri
449
+ _query_builder << '/v2/labor/shifts/{id}'
450
+ _query_builder = APIHelper.append_url_with_template_parameters(
451
+ _query_builder,
452
+ 'id' => id
453
+ )
454
+ _query_url = APIHelper.clean_url _query_builder
455
+
456
+ # Prepare headers.
457
+ _headers = {
458
+ 'accept' => 'application/json',
459
+ 'content-type' => 'application/json; charset=utf-8'
460
+ }
461
+
462
+ # Prepare and execute HttpRequest.
463
+ _request = config.http_client.put(
464
+ _query_url,
465
+ headers: _headers,
466
+ parameters: body.to_json
467
+ )
468
+ OAuth2.apply(config, _request)
469
+ _response = execute_request(_request)
470
+
471
+ # Return appropriate response type.
472
+ decoded = APIHelper.json_deserialize(_response.raw_body)
473
+ _errors = APIHelper.map_response(decoded, ['errors'])
474
+ ApiResponse.new(_response, data: decoded, errors: _errors)
475
+ end
476
+
477
+ # Returns a list of `WorkweekConfig` instances for a business.
478
+ # @param [Integer] limit Optional parameter: Maximum number of Workweek
479
+ # Configs to return per page.
480
+ # @param [String] cursor Optional parameter: Pointer to the next page of
481
+ # Workweek Config results to fetch.
482
+ # @return [ListWorkweekConfigsResponse Hash] response from the API call
483
+ def list_workweek_configs(limit: nil,
484
+ cursor: nil)
485
+ # Prepare query url.
486
+ _query_builder = config.get_base_uri
487
+ _query_builder << '/v2/labor/workweek-configs'
488
+ _query_builder = APIHelper.append_url_with_query_parameters(
489
+ _query_builder,
490
+ 'limit' => limit,
491
+ 'cursor' => cursor
492
+ )
493
+ _query_url = APIHelper.clean_url _query_builder
494
+
495
+ # Prepare headers.
496
+ _headers = {
497
+ 'accept' => 'application/json'
498
+ }
499
+
500
+ # Prepare and execute HttpRequest.
501
+ _request = config.http_client.get(
502
+ _query_url,
503
+ headers: _headers
504
+ )
505
+ OAuth2.apply(config, _request)
506
+ _response = execute_request(_request)
507
+
508
+ # Return appropriate response type.
509
+ decoded = APIHelper.json_deserialize(_response.raw_body)
510
+ _errors = APIHelper.map_response(decoded, ['errors'])
511
+ ApiResponse.new(_response, data: decoded, errors: _errors)
512
+ end
513
+
514
+ # Updates a `WorkweekConfig`.
515
+ # @param [String] id Required parameter: UUID for the `WorkweekConfig`
516
+ # object being updated.
517
+ # @param [UpdateWorkweekConfigRequest] body Required parameter: An object
518
+ # containing the fields to POST for the request. See the corresponding
519
+ # object definition for field details.
520
+ # @return [UpdateWorkweekConfigResponse Hash] response from the API call
521
+ def update_workweek_config(id:,
522
+ body:)
523
+ # Prepare query url.
524
+ _query_builder = config.get_base_uri
525
+ _query_builder << '/v2/labor/workweek-configs/{id}'
526
+ _query_builder = APIHelper.append_url_with_template_parameters(
527
+ _query_builder,
528
+ 'id' => id
529
+ )
530
+ _query_url = APIHelper.clean_url _query_builder
531
+
532
+ # Prepare headers.
533
+ _headers = {
534
+ 'accept' => 'application/json',
535
+ 'content-type' => 'application/json; charset=utf-8'
536
+ }
537
+
538
+ # Prepare and execute HttpRequest.
539
+ _request = config.http_client.put(
540
+ _query_url,
541
+ headers: _headers,
542
+ parameters: body.to_json
543
+ )
544
+ OAuth2.apply(config, _request)
545
+ _response = execute_request(_request)
546
+
547
+ # Return appropriate response type.
548
+ decoded = APIHelper.json_deserialize(_response.raw_body)
549
+ _errors = APIHelper.map_response(decoded, ['errors'])
550
+ ApiResponse.new(_response, data: decoded, errors: _errors)
551
+ end
552
+ end
553
+ end
@@ -0,0 +1,146 @@
1
+ module Square
2
+ # LocationsApi
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
+ # Provides information of all locations of a business.
9
+ # Most other Connect API endpoints have a required `location_id` path
10
+ # parameter.
11
+ # The `id` field of the [`Location`](#type-location) objects returned by
12
+ # this
13
+ # endpoint correspond to that `location_id` parameter.
14
+ # @return [ListLocationsResponse Hash] response from the API call
15
+ def list_locations
16
+ # Prepare query url.
17
+ _query_builder = config.get_base_uri
18
+ _query_builder << '/v2/locations'
19
+ _query_url = APIHelper.clean_url _query_builder
20
+
21
+ # Prepare headers.
22
+ _headers = {
23
+ 'accept' => 'application/json'
24
+ }
25
+
26
+ # Prepare and execute HttpRequest.
27
+ _request = config.http_client.get(
28
+ _query_url,
29
+ headers: _headers
30
+ )
31
+ OAuth2.apply(config, _request)
32
+ _response = execute_request(_request)
33
+
34
+ # Return appropriate response type.
35
+ decoded = APIHelper.json_deserialize(_response.raw_body)
36
+ _errors = APIHelper.map_response(decoded, ['errors'])
37
+ ApiResponse.new(_response, data: decoded, errors: _errors)
38
+ end
39
+
40
+ # Creates a location.
41
+ # For more information about locations, see [Locations API
42
+ # Overview](https://developer.squareup.com/docs/locations-api).
43
+ # @param [CreateLocationRequest] body Required parameter: An object
44
+ # containing the fields to POST for the request. See the corresponding
45
+ # object definition for field details.
46
+ # @return [CreateLocationResponse Hash] response from the API call
47
+ def create_location(body:)
48
+ # Prepare query url.
49
+ _query_builder = config.get_base_uri
50
+ _query_builder << '/v2/locations'
51
+ _query_url = APIHelper.clean_url _query_builder
52
+
53
+ # Prepare headers.
54
+ _headers = {
55
+ 'accept' => 'application/json',
56
+ 'content-type' => 'application/json; charset=utf-8'
57
+ }
58
+
59
+ # Prepare and execute HttpRequest.
60
+ _request = config.http_client.post(
61
+ _query_url,
62
+ headers: _headers,
63
+ parameters: body.to_json
64
+ )
65
+ OAuth2.apply(config, _request)
66
+ _response = execute_request(_request)
67
+
68
+ # Return appropriate response type.
69
+ decoded = APIHelper.json_deserialize(_response.raw_body)
70
+ _errors = APIHelper.map_response(decoded, ['errors'])
71
+ ApiResponse.new(_response, data: decoded, errors: _errors)
72
+ end
73
+
74
+ # Retrieves details of a location.
75
+ # @param [String] location_id Required parameter: The ID of the location to
76
+ # retrieve.
77
+ # @return [RetrieveLocationResponse Hash] response from the API call
78
+ def retrieve_location(location_id:)
79
+ # Prepare query url.
80
+ _query_builder = config.get_base_uri
81
+ _query_builder << '/v2/locations/{location_id}'
82
+ _query_builder = APIHelper.append_url_with_template_parameters(
83
+ _query_builder,
84
+ 'location_id' => location_id
85
+ )
86
+ _query_url = APIHelper.clean_url _query_builder
87
+
88
+ # Prepare headers.
89
+ _headers = {
90
+ 'accept' => 'application/json'
91
+ }
92
+
93
+ # Prepare and execute HttpRequest.
94
+ _request = config.http_client.get(
95
+ _query_url,
96
+ headers: _headers
97
+ )
98
+ OAuth2.apply(config, _request)
99
+ _response = execute_request(_request)
100
+
101
+ # Return appropriate response type.
102
+ decoded = APIHelper.json_deserialize(_response.raw_body)
103
+ _errors = APIHelper.map_response(decoded, ['errors'])
104
+ ApiResponse.new(_response, data: decoded, errors: _errors)
105
+ end
106
+
107
+ # Updates a location.
108
+ # @param [String] location_id Required parameter: The ID of the location to
109
+ # update.
110
+ # @param [UpdateLocationRequest] body Required parameter: An object
111
+ # containing the fields to POST for the request. See the corresponding
112
+ # object definition for field details.
113
+ # @return [UpdateLocationResponse Hash] response from the API call
114
+ def update_location(location_id:,
115
+ body:)
116
+ # Prepare query url.
117
+ _query_builder = config.get_base_uri
118
+ _query_builder << '/v2/locations/{location_id}'
119
+ _query_builder = APIHelper.append_url_with_template_parameters(
120
+ _query_builder,
121
+ 'location_id' => location_id
122
+ )
123
+ _query_url = APIHelper.clean_url _query_builder
124
+
125
+ # Prepare headers.
126
+ _headers = {
127
+ 'accept' => 'application/json',
128
+ 'content-type' => 'application/json; charset=utf-8'
129
+ }
130
+
131
+ # Prepare and execute HttpRequest.
132
+ _request = config.http_client.put(
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(_response, data: decoded, errors: _errors)
144
+ end
145
+ end
146
+ end