Class: Square::LaborApi
Overview
LaborApi
Instance Attribute Summary
Attributes inherited from BaseApi
Instance Method Summary collapse
-
#create_break_type(body:) ⇒ CreateBreakTypeResponse Hash
Creates a new ‘BreakType`.
-
#create_shift(body:) ⇒ CreateShiftResponse Hash
Creates a new ‘Shift`.
-
#delete_break_type(id:) ⇒ DeleteBreakTypeResponse Hash
Deletes an existing ‘BreakType`.
-
#delete_shift(id:) ⇒ DeleteShiftResponse Hash
Deletes a ‘Shift`.
-
#get_break_type(id:) ⇒ GetBreakTypeResponse Hash
Returns a single ‘BreakType` specified by `id`.
-
#get_employee_wage(id:) ⇒ GetEmployeeWageResponse Hash
Returns a single ‘EmployeeWage` specified by `id`.
-
#get_shift(id:) ⇒ GetShiftResponse Hash
Returns a single ‘Shift` specified by `id`.
-
#get_team_member_wage(id:) ⇒ GetTeamMemberWageResponse Hash
Returns a single ‘TeamMemberWage` specified by `id `.
-
#initialize(config, http_call_back: nil) ⇒ LaborApi
constructor
A new instance of LaborApi.
-
#list_break_types(location_id: nil, limit: nil, cursor: nil) ⇒ ListBreakTypesResponse Hash
Returns a paginated list of ‘BreakType` instances for a business.
-
#list_employee_wages(employee_id: nil, limit: nil, cursor: nil) ⇒ ListEmployeeWagesResponse Hash
Returns a paginated list of ‘EmployeeWage` instances for a business.
-
#list_team_member_wages(team_member_id: nil, limit: nil, cursor: nil) ⇒ ListTeamMemberWagesResponse Hash
Returns a paginated list of ‘TeamMemberWage` instances for a business.
-
#list_workweek_configs(limit: nil, cursor: nil) ⇒ ListWorkweekConfigsResponse Hash
Returns a list of ‘WorkweekConfig` instances for a business.
-
#search_shifts(body:) ⇒ SearchShiftsResponse Hash
Returns a paginated list of ‘Shift` records for a business.
-
#update_break_type(id:, body:) ⇒ UpdateBreakTypeResponse Hash
Updates an existing ‘BreakType`.
-
#update_shift(id:, body:) ⇒ UpdateShiftResponse Hash
Updates an existing ‘Shift`.
-
#update_workweek_config(id:, body:) ⇒ UpdateWorkweekConfigResponse Hash
Updates a ‘WorkweekConfig`.
Methods inherited from BaseApi
#execute_request, #get_user_agent, #validate_parameters
Constructor Details
#initialize(config, http_call_back: nil) ⇒ LaborApi
Returns a new instance of LaborApi.
4 5 6 |
# File 'lib/square/api/labor_api.rb', line 4 def initialize(config, http_call_back: nil) super(config, http_call_back: http_call_back) end |
Instance Method Details
#create_break_type(body:) ⇒ CreateBreakTypeResponse Hash
Creates a new ‘BreakType`. A `BreakType` is a template for creating `Break` objects. You must provide the following values in your request to this endpoint:
-
‘location_id`
-
‘break_name`
-
‘expected_duration`
-
‘is_paid`
You can only have three ‘BreakType` instances per location. If you attempt to add a fourth `BreakType` for a location, an `INVALID_REQUEST_ERROR` “Exceeded limit of 3 breaks per location.” is returned. containing the fields to POST for the request. See the corresponding object definition for field details.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/square/api/labor_api.rb', line 70 def create_break_type(body:) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/labor/break-types' _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json', 'Content-Type' => 'application/json' } # Prepare and execute HttpRequest. _request = config.http_client.post( _query_url, headers: _headers, parameters: body.to_json ) OAuth2.apply(config, _request) _response = execute_request(_request) # Return appropriate response type. decoded = APIHelper.json_deserialize(_response.raw_body) _errors = APIHelper.map_response(decoded, ['errors']) ApiResponse.new( _response, data: decoded, errors: _errors ) end |
#create_shift(body:) ⇒ CreateShiftResponse Hash
Creates a new ‘Shift`. A `Shift` represents a complete workday for a single employee. You must provide the following values in your request to this endpoint:
-
‘location_id`
-
‘employee_id`
-
‘start_at`
An attempt to create a new ‘Shift` can result in a `BAD_REQUEST` error when:
-
The ‘status` of the new `Shift` is `OPEN` and the employee has another
shift with an ‘OPEN` status.
-
The ‘start_at` date is in the future.
-
The ‘start_at` or `end_at` date overlaps another shift for the same
employee.
-
The ‘Break` instances are set in the request and a break `start_at`
is before the ‘Shift.start_at`, a break `end_at` is after the `Shift.end_at`, or both. the fields to POST for the request. See the corresponding object definition for field details.
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
# File 'lib/square/api/labor_api.rb', line 313 def create_shift(body:) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/labor/shifts' _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json', 'Content-Type' => 'application/json' } # Prepare and execute HttpRequest. _request = config.http_client.post( _query_url, headers: _headers, parameters: body.to_json ) OAuth2.apply(config, _request) _response = execute_request(_request) # Return appropriate response type. decoded = APIHelper.json_deserialize(_response.raw_body) _errors = APIHelper.map_response(decoded, ['errors']) ApiResponse.new( _response, data: decoded, errors: _errors ) end |
#delete_break_type(id:) ⇒ DeleteBreakTypeResponse Hash
Deletes an existing ‘BreakType`. A `BreakType` can be deleted even if it is referenced from a `Shift`. deleted.
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/square/api/labor_api.rb', line 104 def delete_break_type(id:) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/labor/break-types/{id}' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'id' => { 'value' => id, 'encode' => true } ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json' } # Prepare and execute HttpRequest. _request = config.http_client.delete( _query_url, headers: _headers ) OAuth2.apply(config, _request) _response = execute_request(_request) # Return appropriate response type. decoded = APIHelper.json_deserialize(_response.raw_body) _errors = APIHelper.map_response(decoded, ['errors']) ApiResponse.new( _response, data: decoded, errors: _errors ) end |
#delete_shift(id:) ⇒ DeleteShiftResponse Hash
Deletes a ‘Shift`. deleted.
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 |
# File 'lib/square/api/labor_api.rb', line 392 def delete_shift(id:) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/labor/shifts/{id}' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'id' => { 'value' => id, 'encode' => true } ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json' } # Prepare and execute HttpRequest. _request = config.http_client.delete( _query_url, headers: _headers ) OAuth2.apply(config, _request) _response = execute_request(_request) # Return appropriate response type. decoded = APIHelper.json_deserialize(_response.raw_body) _errors = APIHelper.map_response(decoded, ['errors']) ApiResponse.new( _response, data: decoded, errors: _errors ) end |
#get_break_type(id:) ⇒ GetBreakTypeResponse Hash
Returns a single ‘BreakType` specified by `id`. retrieved.
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/square/api/labor_api.rb', line 139 def get_break_type(id:) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/labor/break-types/{id}' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'id' => { 'value' => id, 'encode' => true } ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json' } # Prepare and execute HttpRequest. _request = config.http_client.get( _query_url, headers: _headers ) OAuth2.apply(config, _request) _response = execute_request(_request) # Return appropriate response type. decoded = APIHelper.json_deserialize(_response.raw_body) _errors = APIHelper.map_response(decoded, ['errors']) ApiResponse.new( _response, data: decoded, errors: _errors ) end |
#get_employee_wage(id:) ⇒ GetEmployeeWageResponse Hash
Returns a single ‘EmployeeWage` specified by `id`. being retrieved.
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
# File 'lib/square/api/labor_api.rb', line 260 def get_employee_wage(id:) warn 'Endpoint get_employee_wage in LaborApi is deprecated' # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/labor/employee-wages/{id}' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'id' => { 'value' => id, 'encode' => true } ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json' } # Prepare and execute HttpRequest. _request = config.http_client.get( _query_url, headers: _headers ) OAuth2.apply(config, _request) _response = execute_request(_request) # Return appropriate response type. decoded = APIHelper.json_deserialize(_response.raw_body) _errors = APIHelper.map_response(decoded, ['errors']) ApiResponse.new( _response, data: decoded, errors: _errors ) end |
#get_shift(id:) ⇒ GetShiftResponse Hash
Returns a single ‘Shift` specified by `id`. retrieved.
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 |
# File 'lib/square/api/labor_api.rb', line 427 def get_shift(id:) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/labor/shifts/{id}' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'id' => { 'value' => id, 'encode' => true } ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json' } # Prepare and execute HttpRequest. _request = config.http_client.get( _query_url, headers: _headers ) OAuth2.apply(config, _request) _response = execute_request(_request) # Return appropriate response type. decoded = APIHelper.json_deserialize(_response.raw_body) _errors = APIHelper.map_response(decoded, ['errors']) ApiResponse.new( _response, data: decoded, errors: _errors ) end |
#get_team_member_wage(id:) ⇒ GetTeamMemberWageResponse Hash
Returns a single ‘TeamMemberWage` specified by `id `. being retrieved.
553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 |
# File 'lib/square/api/labor_api.rb', line 553 def get_team_member_wage(id:) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/labor/team-member-wages/{id}' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'id' => { 'value' => id, 'encode' => true } ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json' } # Prepare and execute HttpRequest. _request = config.http_client.get( _query_url, headers: _headers ) OAuth2.apply(config, _request) _response = execute_request(_request) # Return appropriate response type. decoded = APIHelper.json_deserialize(_response.raw_body) _errors = APIHelper.map_response(decoded, ['errors']) ApiResponse.new( _response, data: decoded, errors: _errors ) end |
#list_break_types(location_id: nil, limit: nil, cursor: nil) ⇒ ListBreakTypesResponse Hash
Returns a paginated list of ‘BreakType` instances for a business. `BreakType` results to only those that are associated with the specified location. `BreakType` results to return per page. The number can range between 1 and
-
The default is 200.
‘BreakType` results to fetch.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/square/api/labor_api.rb', line 18 def list_break_types(location_id: nil, limit: nil, cursor: nil) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/labor/break-types' _query_builder = APIHelper.append_url_with_query_parameters( _query_builder, 'location_id' => location_id, 'limit' => limit, 'cursor' => cursor ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json' } # Prepare and execute HttpRequest. _request = config.http_client.get( _query_url, headers: _headers ) OAuth2.apply(config, _request) _response = execute_request(_request) # Return appropriate response type. decoded = APIHelper.json_deserialize(_response.raw_body) _errors = APIHelper.map_response(decoded, ['errors']) ApiResponse.new( _response, data: decoded, errors: _errors ) end |
#list_employee_wages(employee_id: nil, limit: nil, cursor: nil) ⇒ ListEmployeeWagesResponse Hash
Returns a paginated list of ‘EmployeeWage` instances for a business. to only those that are associated with the specified employee. `EmployeeWage` results to return per page. The number can range between 1 and 200. The default is 200. `EmployeeWage` results to fetch.
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/square/api/labor_api.rb', line 220 def list_employee_wages(employee_id: nil, limit: nil, cursor: nil) warn 'Endpoint list_employee_wages in LaborApi is deprecated' # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/labor/employee-wages' _query_builder = APIHelper.append_url_with_query_parameters( _query_builder, 'employee_id' => employee_id, 'limit' => limit, 'cursor' => cursor ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json' } # Prepare and execute HttpRequest. _request = config.http_client.get( _query_url, headers: _headers ) OAuth2.apply(config, _request) _response = execute_request(_request) # Return appropriate response type. decoded = APIHelper.json_deserialize(_response.raw_body) _errors = APIHelper.map_response(decoded, ['errors']) ApiResponse.new( _response, data: decoded, errors: _errors ) end |
#list_team_member_wages(team_member_id: nil, limit: nil, cursor: nil) ⇒ ListTeamMemberWagesResponse Hash
Returns a paginated list of ‘TeamMemberWage` instances for a business. wages to only those that are associated with the specified team member. `TeamMemberWage` results to return per page. The number can range between 1 and 200. The default is 200. `EmployeeWage` results to fetch.
514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 |
# File 'lib/square/api/labor_api.rb', line 514 def list_team_member_wages(team_member_id: nil, limit: nil, cursor: nil) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/labor/team-member-wages' _query_builder = APIHelper.append_url_with_query_parameters( _query_builder, 'team_member_id' => team_member_id, 'limit' => limit, 'cursor' => cursor ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json' } # Prepare and execute HttpRequest. _request = config.http_client.get( _query_url, headers: _headers ) OAuth2.apply(config, _request) _response = execute_request(_request) # Return appropriate response type. decoded = APIHelper.json_deserialize(_response.raw_body) _errors = APIHelper.map_response(decoded, ['errors']) ApiResponse.new( _response, data: decoded, errors: _errors ) end |
#list_workweek_configs(limit: nil, cursor: nil) ⇒ ListWorkweekConfigsResponse Hash
Returns a list of ‘WorkweekConfig` instances for a business. `WorkweekConfigs` results to return per page. `WorkweekConfig` results to fetch.
590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 |
# File 'lib/square/api/labor_api.rb', line 590 def list_workweek_configs(limit: nil, cursor: nil) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/labor/workweek-configs' _query_builder = APIHelper.append_url_with_query_parameters( _query_builder, 'limit' => limit, 'cursor' => cursor ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json' } # Prepare and execute HttpRequest. _request = config.http_client.get( _query_url, headers: _headers ) OAuth2.apply(config, _request) _response = execute_request(_request) # Return appropriate response type. decoded = APIHelper.json_deserialize(_response.raw_body) _errors = APIHelper.map_response(decoded, ['errors']) ApiResponse.new( _response, data: decoded, errors: _errors ) end |
#search_shifts(body:) ⇒ SearchShiftsResponse Hash
Returns a paginated list of ‘Shift` records for a business. The list to be returned can be filtered by:
-
Location IDs.
-
Employee IDs.
-
Shift status (‘OPEN` and `CLOSED`).
-
Shift start.
-
Shift end.
-
Workday details.
The list can be sorted by:
-
‘start_at`.
-
‘end_at`.
-
‘created_at`.
-
‘updated_at`.
the fields to POST for the request. See the corresponding object definition for field details.
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 |
# File 'lib/square/api/labor_api.rb', line 359 def search_shifts(body:) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/labor/shifts/search' _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json', 'Content-Type' => 'application/json' } # Prepare and execute HttpRequest. _request = config.http_client.post( _query_url, headers: _headers, parameters: body.to_json ) OAuth2.apply(config, _request) _response = execute_request(_request) # Return appropriate response type. decoded = APIHelper.json_deserialize(_response.raw_body) _errors = APIHelper.map_response(decoded, ['errors']) ApiResponse.new( _response, data: decoded, errors: _errors ) end |
#update_break_type(id:, body:) ⇒ UpdateBreakTypeResponse Hash
Updates an existing ‘BreakType`. updated. containing the fields to POST for the request. See the corresponding object definition for field details.
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/square/api/labor_api.rb', line 177 def update_break_type(id:, body:) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/labor/break-types/{id}' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'id' => { 'value' => id, 'encode' => true } ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json', 'Content-Type' => 'application/json' } # Prepare and execute HttpRequest. _request = config.http_client.put( _query_url, headers: _headers, parameters: body.to_json ) OAuth2.apply(config, _request) _response = execute_request(_request) # Return appropriate response type. decoded = APIHelper.json_deserialize(_response.raw_body) _errors = APIHelper.map_response(decoded, ['errors']) ApiResponse.new( _response, data: decoded, errors: _errors ) end |
#update_shift(id:, body:) ⇒ UpdateShiftResponse Hash
Updates an existing ‘Shift`. When adding a `Break` to a `Shift`, any earlier `Break` instances in the `Shift` have the `end_at` property set to a valid RFC-3339 datetime string. When closing a `Shift`, all `Break` instances in the `Shift` must be complete with `end_at` set on each `Break`. updated. the fields to POST for the request. See the corresponding object definition for field details.
471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 |
# File 'lib/square/api/labor_api.rb', line 471 def update_shift(id:, body:) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/labor/shifts/{id}' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'id' => { 'value' => id, 'encode' => true } ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json', 'Content-Type' => 'application/json' } # Prepare and execute HttpRequest. _request = config.http_client.put( _query_url, headers: _headers, parameters: body.to_json ) OAuth2.apply(config, _request) _response = execute_request(_request) # Return appropriate response type. decoded = APIHelper.json_deserialize(_response.raw_body) _errors = APIHelper.map_response(decoded, ['errors']) ApiResponse.new( _response, data: decoded, errors: _errors ) end |
#update_workweek_config(id:, body:) ⇒ UpdateWorkweekConfigResponse Hash
Updates a ‘WorkweekConfig`. object being updated. containing the fields to POST for the request. See the corresponding object definition for field details.
630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 |
# File 'lib/square/api/labor_api.rb', line 630 def update_workweek_config(id:, body:) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/labor/workweek-configs/{id}' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'id' => { 'value' => id, 'encode' => true } ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json', 'Content-Type' => 'application/json' } # Prepare and execute HttpRequest. _request = config.http_client.put( _query_url, headers: _headers, parameters: body.to_json ) OAuth2.apply(config, _request) _response = execute_request(_request) # Return appropriate response type. decoded = APIHelper.json_deserialize(_response.raw_body) _errors = APIHelper.map_response(decoded, ['errors']) ApiResponse.new( _response, data: decoded, errors: _errors ) end |