square.rb 3.3.0.20191217

Sign up to get free protection for your applications and to get access to all the features.
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,715 @@
1
+ module Square
2
+ # V1EmployeesApi
3
+ class V1EmployeesApi < BaseApi
4
+ def initialize(config, http_call_back: nil)
5
+ super(config, http_call_back: http_call_back)
6
+ end
7
+
8
+ # Provides summary information for all of a business's employees.
9
+ # @param [SortOrder] order Optional parameter: The order in which employees
10
+ # are listed in the response, based on their created_at field. Default
11
+ # value: ASC
12
+ # @param [String] begin_updated_at Optional parameter: If filtering results
13
+ # by their updated_at field, the beginning of the requested reporting
14
+ # period, in ISO 8601 format
15
+ # @param [String] end_updated_at Optional parameter: If filtering results by
16
+ # there updated_at field, the end of the requested reporting period, in ISO
17
+ # 8601 format.
18
+ # @param [String] begin_created_at Optional parameter: If filtering results
19
+ # by their created_at field, the beginning of the requested reporting
20
+ # period, in ISO 8601 format.
21
+ # @param [String] end_created_at Optional parameter: If filtering results by
22
+ # their created_at field, the end of the requested reporting period, in ISO
23
+ # 8601 format.
24
+ # @param [V1ListEmployeesRequestStatus] status Optional parameter: If
25
+ # provided, the endpoint returns only employee entities with the specified
26
+ # status (ACTIVE or INACTIVE).
27
+ # @param [String] external_id Optional parameter: If provided, the endpoint
28
+ # returns only employee entities with the specified external_id.
29
+ # @param [Integer] limit Optional parameter: The maximum integer number of
30
+ # employee entities to return in a single response. Default 100, maximum
31
+ # 200.
32
+ # @param [String] batch_token Optional parameter: A pagination cursor to
33
+ # retrieve the next set of results for your original query to the
34
+ # endpoint.
35
+ # @return [List of V1Employee Hash] response from the API call
36
+ def list_employees(order: nil,
37
+ begin_updated_at: nil,
38
+ end_updated_at: nil,
39
+ begin_created_at: nil,
40
+ end_created_at: nil,
41
+ status: nil,
42
+ external_id: nil,
43
+ limit: nil,
44
+ batch_token: nil)
45
+ # Prepare query url.
46
+ _query_builder = config.get_base_uri
47
+ _query_builder << '/v1/me/employees'
48
+ _query_builder = APIHelper.append_url_with_query_parameters(
49
+ _query_builder,
50
+ 'order' => order,
51
+ 'begin_updated_at' => begin_updated_at,
52
+ 'end_updated_at' => end_updated_at,
53
+ 'begin_created_at' => begin_created_at,
54
+ 'end_created_at' => end_created_at,
55
+ 'status' => status,
56
+ 'external_id' => external_id,
57
+ 'limit' => limit,
58
+ 'batch_token' => batch_token
59
+ )
60
+ _query_url = APIHelper.clean_url _query_builder
61
+
62
+ # Prepare headers.
63
+ _headers = {
64
+ 'accept' => 'application/json'
65
+ }
66
+
67
+ # Prepare and execute HttpRequest.
68
+ _request = config.http_client.get(
69
+ _query_url,
70
+ headers: _headers
71
+ )
72
+ OAuth2.apply(config, _request)
73
+ _response = execute_request(_request)
74
+
75
+ # Return appropriate response type.
76
+ decoded = APIHelper.json_deserialize(_response.raw_body)
77
+ _errors = APIHelper.map_response(decoded, ['errors'])
78
+ ApiResponse.new(_response, data: decoded, errors: _errors)
79
+ end
80
+
81
+ # Use the CreateEmployee endpoint to add an employee to a Square
82
+ # account. Employees created with the Connect API have an initial status
83
+ # of `INACTIVE`. Inactive employees cannot sign in to Square Point of Sale
84
+ # until they are activated from the Square Dashboard. Employee status
85
+ # cannot be changed with the Connect API.
86
+ # <aside class="important">
87
+ # Employee entities cannot be deleted. To disable employee profiles,
88
+ # set the employee's status to <code>INACTIVE</code>
89
+ # </aside>
90
+ # @param [V1Employee] body Required parameter: An object containing the
91
+ # fields to POST for the request. See the corresponding object definition
92
+ # for field details.
93
+ # @return [V1Employee Hash] response from the API call
94
+ def create_employee(body:)
95
+ # Prepare query url.
96
+ _query_builder = config.get_base_uri
97
+ _query_builder << '/v1/me/employees'
98
+ _query_url = APIHelper.clean_url _query_builder
99
+
100
+ # Prepare headers.
101
+ _headers = {
102
+ 'accept' => 'application/json',
103
+ 'content-type' => 'application/json; charset=utf-8'
104
+ }
105
+
106
+ # Prepare and execute HttpRequest.
107
+ _request = config.http_client.post(
108
+ _query_url,
109
+ headers: _headers,
110
+ parameters: body.to_json
111
+ )
112
+ OAuth2.apply(config, _request)
113
+ _response = execute_request(_request)
114
+
115
+ # Return appropriate response type.
116
+ decoded = APIHelper.json_deserialize(_response.raw_body)
117
+ _errors = APIHelper.map_response(decoded, ['errors'])
118
+ ApiResponse.new(_response, data: decoded, errors: _errors)
119
+ end
120
+
121
+ # Provides the details for a single employee.
122
+ # @param [String] employee_id Required parameter: The employee's ID.
123
+ # @return [V1Employee Hash] response from the API call
124
+ def retrieve_employee(employee_id:)
125
+ # Prepare query url.
126
+ _query_builder = config.get_base_uri
127
+ _query_builder << '/v1/me/employees/{employee_id}'
128
+ _query_builder = APIHelper.append_url_with_template_parameters(
129
+ _query_builder,
130
+ 'employee_id' => employee_id
131
+ )
132
+ _query_url = APIHelper.clean_url _query_builder
133
+
134
+ # Prepare headers.
135
+ _headers = {
136
+ 'accept' => 'application/json'
137
+ }
138
+
139
+ # Prepare and execute HttpRequest.
140
+ _request = config.http_client.get(
141
+ _query_url,
142
+ headers: _headers
143
+ )
144
+ OAuth2.apply(config, _request)
145
+ _response = execute_request(_request)
146
+
147
+ # Return appropriate response type.
148
+ decoded = APIHelper.json_deserialize(_response.raw_body)
149
+ _errors = APIHelper.map_response(decoded, ['errors'])
150
+ ApiResponse.new(_response, data: decoded, errors: _errors)
151
+ end
152
+
153
+ # UpdateEmployee
154
+ # @param [String] employee_id Required parameter: The ID of the role to
155
+ # modify.
156
+ # @param [V1Employee] body Required parameter: An object containing the
157
+ # fields to POST for the request. See the corresponding object definition
158
+ # for field details.
159
+ # @return [V1Employee Hash] response from the API call
160
+ def update_employee(employee_id:,
161
+ body:)
162
+ # Prepare query url.
163
+ _query_builder = config.get_base_uri
164
+ _query_builder << '/v1/me/employees/{employee_id}'
165
+ _query_builder = APIHelper.append_url_with_template_parameters(
166
+ _query_builder,
167
+ 'employee_id' => employee_id
168
+ )
169
+ _query_url = APIHelper.clean_url _query_builder
170
+
171
+ # Prepare headers.
172
+ _headers = {
173
+ 'accept' => 'application/json',
174
+ 'content-type' => 'application/json; charset=utf-8'
175
+ }
176
+
177
+ # Prepare and execute HttpRequest.
178
+ _request = config.http_client.put(
179
+ _query_url,
180
+ headers: _headers,
181
+ parameters: body.to_json
182
+ )
183
+ OAuth2.apply(config, _request)
184
+ _response = execute_request(_request)
185
+
186
+ # Return appropriate response type.
187
+ decoded = APIHelper.json_deserialize(_response.raw_body)
188
+ _errors = APIHelper.map_response(decoded, ['errors'])
189
+ ApiResponse.new(_response, data: decoded, errors: _errors)
190
+ end
191
+
192
+ # Provides summary information for all of a business's employee roles.
193
+ # @param [SortOrder] order Optional parameter: The order in which employees
194
+ # are listed in the response, based on their created_at field.Default value:
195
+ # ASC
196
+ # @param [Integer] limit Optional parameter: The maximum integer number of
197
+ # employee entities to return in a single response. Default 100, maximum
198
+ # 200.
199
+ # @param [String] batch_token Optional parameter: A pagination cursor to
200
+ # retrieve the next set of results for your original query to the
201
+ # endpoint.
202
+ # @return [List of V1EmployeeRole Hash] response from the API call
203
+ def list_employee_roles(order: nil,
204
+ limit: nil,
205
+ batch_token: nil)
206
+ # Prepare query url.
207
+ _query_builder = config.get_base_uri
208
+ _query_builder << '/v1/me/roles'
209
+ _query_builder = APIHelper.append_url_with_query_parameters(
210
+ _query_builder,
211
+ 'order' => order,
212
+ 'limit' => limit,
213
+ 'batch_token' => batch_token
214
+ )
215
+ _query_url = APIHelper.clean_url _query_builder
216
+
217
+ # Prepare headers.
218
+ _headers = {
219
+ 'accept' => 'application/json'
220
+ }
221
+
222
+ # Prepare and execute HttpRequest.
223
+ _request = config.http_client.get(
224
+ _query_url,
225
+ headers: _headers
226
+ )
227
+ OAuth2.apply(config, _request)
228
+ _response = execute_request(_request)
229
+
230
+ # Return appropriate response type.
231
+ decoded = APIHelper.json_deserialize(_response.raw_body)
232
+ _errors = APIHelper.map_response(decoded, ['errors'])
233
+ ApiResponse.new(_response, data: decoded, errors: _errors)
234
+ end
235
+
236
+ # Creates an employee role you can then assign to employees.
237
+ # Square accounts can include any number of roles that can be assigned to
238
+ # employees. These roles define the actions and permissions granted to an
239
+ # employee with that role. For example, an employee with a "Shift Manager"
240
+ # role might be able to issue refunds in Square Point of Sale, whereas an
241
+ # employee with a "Clerk" role might not.
242
+ # Roles are assigned with the [V1UpdateEmployee](#endpoint-v1updateemployee)
243
+ # endpoint. An employee can have only one role at a time.
244
+ # If an employee has no role, they have none of the permissions associated
245
+ # with roles. All employees can accept payments with Square Point of Sale.
246
+ # @param [V1EmployeeRole] body Required parameter: An EmployeeRole object
247
+ # with a name and permissions, and an optional owner flag.
248
+ # @return [V1EmployeeRole Hash] response from the API call
249
+ def create_employee_role(body:)
250
+ # Prepare query url.
251
+ _query_builder = config.get_base_uri
252
+ _query_builder << '/v1/me/roles'
253
+ _query_url = APIHelper.clean_url _query_builder
254
+
255
+ # Prepare headers.
256
+ _headers = {
257
+ 'accept' => 'application/json',
258
+ 'content-type' => 'application/json; charset=utf-8'
259
+ }
260
+
261
+ # Prepare and execute HttpRequest.
262
+ _request = config.http_client.post(
263
+ _query_url,
264
+ headers: _headers,
265
+ parameters: body.to_json
266
+ )
267
+ OAuth2.apply(config, _request)
268
+ _response = execute_request(_request)
269
+
270
+ # Return appropriate response type.
271
+ decoded = APIHelper.json_deserialize(_response.raw_body)
272
+ _errors = APIHelper.map_response(decoded, ['errors'])
273
+ ApiResponse.new(_response, data: decoded, errors: _errors)
274
+ end
275
+
276
+ # Provides the details for a single employee role.
277
+ # @param [String] role_id Required parameter: The role's ID.
278
+ # @return [V1EmployeeRole Hash] response from the API call
279
+ def retrieve_employee_role(role_id:)
280
+ # Prepare query url.
281
+ _query_builder = config.get_base_uri
282
+ _query_builder << '/v1/me/roles/{role_id}'
283
+ _query_builder = APIHelper.append_url_with_template_parameters(
284
+ _query_builder,
285
+ 'role_id' => role_id
286
+ )
287
+ _query_url = APIHelper.clean_url _query_builder
288
+
289
+ # Prepare headers.
290
+ _headers = {
291
+ 'accept' => 'application/json'
292
+ }
293
+
294
+ # Prepare and execute HttpRequest.
295
+ _request = config.http_client.get(
296
+ _query_url,
297
+ headers: _headers
298
+ )
299
+ OAuth2.apply(config, _request)
300
+ _response = execute_request(_request)
301
+
302
+ # Return appropriate response type.
303
+ decoded = APIHelper.json_deserialize(_response.raw_body)
304
+ _errors = APIHelper.map_response(decoded, ['errors'])
305
+ ApiResponse.new(_response, data: decoded, errors: _errors)
306
+ end
307
+
308
+ # Modifies the details of an employee role.
309
+ # @param [String] role_id Required parameter: The ID of the role to
310
+ # modify.
311
+ # @param [V1EmployeeRole] body Required parameter: An object containing the
312
+ # fields to POST for the request. See the corresponding object definition
313
+ # for field details.
314
+ # @return [V1EmployeeRole Hash] response from the API call
315
+ def update_employee_role(role_id:,
316
+ body:)
317
+ # Prepare query url.
318
+ _query_builder = config.get_base_uri
319
+ _query_builder << '/v1/me/roles/{role_id}'
320
+ _query_builder = APIHelper.append_url_with_template_parameters(
321
+ _query_builder,
322
+ 'role_id' => role_id
323
+ )
324
+ _query_url = APIHelper.clean_url _query_builder
325
+
326
+ # Prepare headers.
327
+ _headers = {
328
+ 'accept' => 'application/json',
329
+ 'content-type' => 'application/json; charset=utf-8'
330
+ }
331
+
332
+ # Prepare and execute HttpRequest.
333
+ _request = config.http_client.put(
334
+ _query_url,
335
+ headers: _headers,
336
+ parameters: body.to_json
337
+ )
338
+ OAuth2.apply(config, _request)
339
+ _response = execute_request(_request)
340
+
341
+ # Return appropriate response type.
342
+ decoded = APIHelper.json_deserialize(_response.raw_body)
343
+ _errors = APIHelper.map_response(decoded, ['errors'])
344
+ ApiResponse.new(_response, data: decoded, errors: _errors)
345
+ end
346
+
347
+ # Provides summary information for all of a business's employee timecards.
348
+ # @param [SortOrder] order Optional parameter: The order in which timecards
349
+ # are listed in the response, based on their created_at field.
350
+ # @param [String] employee_id Optional parameter: If provided, the endpoint
351
+ # returns only timecards for the employee with the specified ID.
352
+ # @param [String] begin_clockin_time Optional parameter: If filtering
353
+ # results by their clockin_time field, the beginning of the requested
354
+ # reporting period, in ISO 8601 format.
355
+ # @param [String] end_clockin_time Optional parameter: If filtering results
356
+ # by their clockin_time field, the end of the requested reporting period, in
357
+ # ISO 8601 format.
358
+ # @param [String] begin_clockout_time Optional parameter: If filtering
359
+ # results by their clockout_time field, the beginning of the requested
360
+ # reporting period, in ISO 8601 format.
361
+ # @param [String] end_clockout_time Optional parameter: If filtering results
362
+ # by their clockout_time field, the end of the requested reporting period,
363
+ # in ISO 8601 format.
364
+ # @param [String] begin_updated_at Optional parameter: If filtering results
365
+ # by their updated_at field, the beginning of the requested reporting
366
+ # period, in ISO 8601 format.
367
+ # @param [String] end_updated_at Optional parameter: If filtering results by
368
+ # their updated_at field, the end of the requested reporting period, in ISO
369
+ # 8601 format.
370
+ # @param [Boolean] deleted Optional parameter: If true, only deleted
371
+ # timecards are returned. If false, only valid timecards are returned.If you
372
+ # don't provide this parameter, both valid and deleted timecards are
373
+ # returned.
374
+ # @param [Integer] limit Optional parameter: The maximum integer number of
375
+ # employee entities to return in a single response. Default 100, maximum
376
+ # 200.
377
+ # @param [String] batch_token Optional parameter: A pagination cursor to
378
+ # retrieve the next set of results for your original query to the
379
+ # endpoint.
380
+ # @return [List of V1Timecard Hash] response from the API call
381
+ def list_timecards(order: nil,
382
+ employee_id: nil,
383
+ begin_clockin_time: nil,
384
+ end_clockin_time: nil,
385
+ begin_clockout_time: nil,
386
+ end_clockout_time: nil,
387
+ begin_updated_at: nil,
388
+ end_updated_at: nil,
389
+ deleted: nil,
390
+ limit: nil,
391
+ batch_token: nil)
392
+ # Prepare query url.
393
+ _query_builder = config.get_base_uri
394
+ _query_builder << '/v1/me/timecards'
395
+ _query_builder = APIHelper.append_url_with_query_parameters(
396
+ _query_builder,
397
+ 'order' => order,
398
+ 'employee_id' => employee_id,
399
+ 'begin_clockin_time' => begin_clockin_time,
400
+ 'end_clockin_time' => end_clockin_time,
401
+ 'begin_clockout_time' => begin_clockout_time,
402
+ 'end_clockout_time' => end_clockout_time,
403
+ 'begin_updated_at' => begin_updated_at,
404
+ 'end_updated_at' => end_updated_at,
405
+ 'deleted' => deleted,
406
+ 'limit' => limit,
407
+ 'batch_token' => batch_token
408
+ )
409
+ _query_url = APIHelper.clean_url _query_builder
410
+
411
+ # Prepare headers.
412
+ _headers = {
413
+ 'accept' => 'application/json'
414
+ }
415
+
416
+ # Prepare and execute HttpRequest.
417
+ _request = config.http_client.get(
418
+ _query_url,
419
+ headers: _headers
420
+ )
421
+ OAuth2.apply(config, _request)
422
+ _response = execute_request(_request)
423
+
424
+ # Return appropriate response type.
425
+ decoded = APIHelper.json_deserialize(_response.raw_body)
426
+ _errors = APIHelper.map_response(decoded, ['errors'])
427
+ ApiResponse.new(_response, data: decoded, errors: _errors)
428
+ end
429
+
430
+ # Creates a timecard for an employee and clocks them in with an
431
+ # `API_CREATE` event and a `clockin_time` set to the current time unless
432
+ # the request provides a different value. To import timecards from another
433
+ # system (rather than clocking someone in). Specify the `clockin_time`
434
+ # and* `clockout_time` in the request.
435
+ # Timecards correspond to exactly one shift for a given employee, bounded
436
+ # by the `clockin_time` and `clockout_time` fields. An employee is
437
+ # considered clocked in if they have a timecard that doesn't have a
438
+ # `clockout_time` set. An employee that is currently clocked in cannot
439
+ # be clocked in a second time.
440
+ # @param [V1Timecard] body Required parameter: An object containing the
441
+ # fields to POST for the request. See the corresponding object definition
442
+ # for field details.
443
+ # @return [V1Timecard Hash] response from the API call
444
+ def create_timecard(body:)
445
+ # Prepare query url.
446
+ _query_builder = config.get_base_uri
447
+ _query_builder << '/v1/me/timecards'
448
+ _query_url = APIHelper.clean_url _query_builder
449
+
450
+ # Prepare headers.
451
+ _headers = {
452
+ 'accept' => 'application/json',
453
+ 'content-type' => 'application/json; charset=utf-8'
454
+ }
455
+
456
+ # Prepare and execute HttpRequest.
457
+ _request = config.http_client.post(
458
+ _query_url,
459
+ headers: _headers,
460
+ parameters: body.to_json
461
+ )
462
+ OAuth2.apply(config, _request)
463
+ _response = execute_request(_request)
464
+
465
+ # Return appropriate response type.
466
+ decoded = APIHelper.json_deserialize(_response.raw_body)
467
+ _errors = APIHelper.map_response(decoded, ['errors'])
468
+ ApiResponse.new(_response, data: decoded, errors: _errors)
469
+ end
470
+
471
+ # Deletes a timecard. Timecards can also be deleted through the
472
+ # Square Dashboard. Deleted timecards are still accessible through
473
+ # Connect API endpoints, but cannot be modified. The `deleted` field of
474
+ # the `Timecard` object indicates whether the timecard has been deleted.
475
+ # *Note**: By default, deleted timecards appear alongside valid timecards in
476
+ # results returned by the
477
+ # [ListTimecards](#endpoint-v1employees-listtimecards)
478
+ # endpoint. To filter deleted timecards, include the `deleted` query
479
+ # parameter in the list request.
480
+ # <aside>
481
+ # Only approved accounts can manage their employees with Square.
482
+ # Unapproved accounts cannot use employee management features with the
483
+ # API.
484
+ # </aside>
485
+ # @param [String] timecard_id Required parameter: The ID of the timecard to
486
+ # delete.
487
+ # @return [Object] response from the API call
488
+ def delete_timecard(timecard_id:)
489
+ # Prepare query url.
490
+ _query_builder = config.get_base_uri
491
+ _query_builder << '/v1/me/timecards/{timecard_id}'
492
+ _query_builder = APIHelper.append_url_with_template_parameters(
493
+ _query_builder,
494
+ 'timecard_id' => timecard_id
495
+ )
496
+ _query_url = APIHelper.clean_url _query_builder
497
+
498
+ # Prepare and execute HttpRequest.
499
+ _request = config.http_client.delete(
500
+ _query_url
501
+ )
502
+ OAuth2.apply(config, _request)
503
+ _response = execute_request(_request)
504
+
505
+ # Return appropriate response type.
506
+ ApiResponse.new(_response, data: _response.raw_body)
507
+ end
508
+
509
+ # Provides the details for a single timecard.
510
+ # <aside>
511
+ # Only approved accounts can manage their employees with Square.
512
+ # Unapproved accounts cannot use employee management features with the
513
+ # API.
514
+ # </aside>
515
+ # @param [String] timecard_id Required parameter: The timecard's ID.
516
+ # @return [V1Timecard Hash] response from the API call
517
+ def retrieve_timecard(timecard_id:)
518
+ # Prepare query url.
519
+ _query_builder = config.get_base_uri
520
+ _query_builder << '/v1/me/timecards/{timecard_id}'
521
+ _query_builder = APIHelper.append_url_with_template_parameters(
522
+ _query_builder,
523
+ 'timecard_id' => timecard_id
524
+ )
525
+ _query_url = APIHelper.clean_url _query_builder
526
+
527
+ # Prepare headers.
528
+ _headers = {
529
+ 'accept' => 'application/json'
530
+ }
531
+
532
+ # Prepare and execute HttpRequest.
533
+ _request = config.http_client.get(
534
+ _query_url,
535
+ headers: _headers
536
+ )
537
+ OAuth2.apply(config, _request)
538
+ _response = execute_request(_request)
539
+
540
+ # Return appropriate response type.
541
+ decoded = APIHelper.json_deserialize(_response.raw_body)
542
+ _errors = APIHelper.map_response(decoded, ['errors'])
543
+ ApiResponse.new(_response, data: decoded, errors: _errors)
544
+ end
545
+
546
+ # Modifies the details of a timecard with an `API_EDIT` event for
547
+ # the timecard. Updating an active timecard with a `clockout_time`
548
+ # clocks the employee out.
549
+ # @param [String] timecard_id Required parameter: TThe ID of the timecard to
550
+ # modify.
551
+ # @param [V1Timecard] body Required parameter: An object containing the
552
+ # fields to POST for the request. See the corresponding object definition
553
+ # for field details.
554
+ # @return [V1Timecard Hash] response from the API call
555
+ def update_timecard(timecard_id:,
556
+ body:)
557
+ # Prepare query url.
558
+ _query_builder = config.get_base_uri
559
+ _query_builder << '/v1/me/timecards/{timecard_id}'
560
+ _query_builder = APIHelper.append_url_with_template_parameters(
561
+ _query_builder,
562
+ 'timecard_id' => timecard_id
563
+ )
564
+ _query_url = APIHelper.clean_url _query_builder
565
+
566
+ # Prepare headers.
567
+ _headers = {
568
+ 'accept' => 'application/json',
569
+ 'content-type' => 'application/json; charset=utf-8'
570
+ }
571
+
572
+ # Prepare and execute HttpRequest.
573
+ _request = config.http_client.put(
574
+ _query_url,
575
+ headers: _headers,
576
+ parameters: body.to_json
577
+ )
578
+ OAuth2.apply(config, _request)
579
+ _response = execute_request(_request)
580
+
581
+ # Return appropriate response type.
582
+ decoded = APIHelper.json_deserialize(_response.raw_body)
583
+ _errors = APIHelper.map_response(decoded, ['errors'])
584
+ ApiResponse.new(_response, data: decoded, errors: _errors)
585
+ end
586
+
587
+ # Provides summary information for all events associated with a
588
+ # particular timecard.
589
+ # <aside>
590
+ # Only approved accounts can manage their employees with Square.
591
+ # Unapproved accounts cannot use employee management features with the
592
+ # API.
593
+ # </aside>
594
+ # @param [String] timecard_id Required parameter: The ID of the timecard to
595
+ # list events for.
596
+ # @return [List of V1TimecardEvent Hash] response from the API call
597
+ def list_timecard_events(timecard_id:)
598
+ # Prepare query url.
599
+ _query_builder = config.get_base_uri
600
+ _query_builder << '/v1/me/timecards/{timecard_id}/events'
601
+ _query_builder = APIHelper.append_url_with_template_parameters(
602
+ _query_builder,
603
+ 'timecard_id' => timecard_id
604
+ )
605
+ _query_url = APIHelper.clean_url _query_builder
606
+
607
+ # Prepare headers.
608
+ _headers = {
609
+ 'accept' => 'application/json'
610
+ }
611
+
612
+ # Prepare and execute HttpRequest.
613
+ _request = config.http_client.get(
614
+ _query_url,
615
+ headers: _headers
616
+ )
617
+ OAuth2.apply(config, _request)
618
+ _response = execute_request(_request)
619
+
620
+ # Return appropriate response type.
621
+ decoded = APIHelper.json_deserialize(_response.raw_body)
622
+ _errors = APIHelper.map_response(decoded, ['errors'])
623
+ ApiResponse.new(_response, data: decoded, errors: _errors)
624
+ end
625
+
626
+ # Provides the details for all of a location's cash drawer shifts during a
627
+ # date range. The date range you specify cannot exceed 90 days.
628
+ # @param [String] location_id Required parameter: The ID of the location to
629
+ # list cash drawer shifts for.
630
+ # @param [SortOrder] order Optional parameter: The order in which cash
631
+ # drawer shifts are listed in the response, based on their created_at field.
632
+ # Default value: ASC
633
+ # @param [String] begin_time Optional parameter: The beginning of the
634
+ # requested reporting period, in ISO 8601 format. Default value: The current
635
+ # time minus 90 days.
636
+ # @param [String] end_time Optional parameter: The beginning of the
637
+ # requested reporting period, in ISO 8601 format. Default value: The current
638
+ # time.
639
+ # @return [List of V1CashDrawerShift Hash] response from the API call
640
+ def list_cash_drawer_shifts(location_id:,
641
+ order: nil,
642
+ begin_time: nil,
643
+ end_time: nil)
644
+ # Prepare query url.
645
+ _query_builder = config.get_base_uri
646
+ _query_builder << '/v1/{location_id}/cash-drawer-shifts'
647
+ _query_builder = APIHelper.append_url_with_template_parameters(
648
+ _query_builder,
649
+ 'location_id' => location_id
650
+ )
651
+ _query_builder = APIHelper.append_url_with_query_parameters(
652
+ _query_builder,
653
+ 'order' => order,
654
+ 'begin_time' => begin_time,
655
+ 'end_time' => end_time
656
+ )
657
+ _query_url = APIHelper.clean_url _query_builder
658
+
659
+ # Prepare headers.
660
+ _headers = {
661
+ 'accept' => 'application/json'
662
+ }
663
+
664
+ # Prepare and execute HttpRequest.
665
+ _request = config.http_client.get(
666
+ _query_url,
667
+ headers: _headers
668
+ )
669
+ OAuth2.apply(config, _request)
670
+ _response = execute_request(_request)
671
+
672
+ # Return appropriate response type.
673
+ decoded = APIHelper.json_deserialize(_response.raw_body)
674
+ _errors = APIHelper.map_response(decoded, ['errors'])
675
+ ApiResponse.new(_response, data: decoded, errors: _errors)
676
+ end
677
+
678
+ # Provides the details for a single cash drawer shift, including all events
679
+ # that occurred during the shift.
680
+ # @param [String] location_id Required parameter: The ID of the location to
681
+ # list cash drawer shifts for.
682
+ # @param [String] shift_id Required parameter: The shift's ID.
683
+ # @return [V1CashDrawerShift Hash] response from the API call
684
+ def retrieve_cash_drawer_shift(location_id:,
685
+ shift_id:)
686
+ # Prepare query url.
687
+ _query_builder = config.get_base_uri
688
+ _query_builder << '/v1/{location_id}/cash-drawer-shifts/{shift_id}'
689
+ _query_builder = APIHelper.append_url_with_template_parameters(
690
+ _query_builder,
691
+ 'location_id' => location_id,
692
+ 'shift_id' => shift_id
693
+ )
694
+ _query_url = APIHelper.clean_url _query_builder
695
+
696
+ # Prepare headers.
697
+ _headers = {
698
+ 'accept' => 'application/json'
699
+ }
700
+
701
+ # Prepare and execute HttpRequest.
702
+ _request = config.http_client.get(
703
+ _query_url,
704
+ headers: _headers
705
+ )
706
+ OAuth2.apply(config, _request)
707
+ _response = execute_request(_request)
708
+
709
+ # Return appropriate response type.
710
+ decoded = APIHelper.json_deserialize(_response.raw_body)
711
+ _errors = APIHelper.map_response(decoded, ['errors'])
712
+ ApiResponse.new(_response, data: decoded, errors: _errors)
713
+ end
714
+ end
715
+ end