Class: Square::Labor::Shifts::Client
- Inherits:
-
Object
- Object
- Square::Labor::Shifts::Client
- Defined in:
- lib/square/labor/shifts/client.rb
Instance Method Summary collapse
-
#create(request_options: {}, **params) ⇒ Square::Types::CreateShiftResponse
Creates a new ‘Shift`.
-
#delete(request_options: {}, **params) ⇒ Square::Types::DeleteShiftResponse
Deletes a ‘Shift`.
-
#get(request_options: {}, **params) ⇒ Square::Types::GetShiftResponse
Returns a single ‘Shift` specified by `id`.
- #initialize(client:) ⇒ Square::Labor::Shifts::Client constructor
-
#search(request_options: {}, **params) ⇒ Square::Types::SearchShiftsResponse
Returns a paginated list of ‘Shift` records for a business.
-
#update(request_options: {}, **params) ⇒ Square::Types::UpdateShiftResponse
Updates an existing ‘Shift`.
Constructor Details
#initialize(client:) ⇒ Square::Labor::Shifts::Client
8 9 10 |
# File 'lib/square/labor/shifts/client.rb', line 8 def initialize(client:) @client = client end |
Instance Method Details
#create(request_options: {}, **params) ⇒ Square::Types::CreateShiftResponse
Creates a new ‘Shift`.
A ‘Shift` represents a complete workday for a single team member. You must provide the following values in your request to this endpoint:
-
‘location_id`
-
‘team_member_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 team member 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 team member.
-
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.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/square/labor/shifts/client.rb', line 32 def create(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::SANDBOX, method: "POST", path: "v2/labor/shifts", body: params ) _response = @client.send(_request) if _response.code >= "200" && _response.code < "300" return Square::Types::CreateShiftResponse.load(_response.body) end raise _response.body end |
#delete(request_options: {}, **params) ⇒ Square::Types::DeleteShiftResponse
Deletes a ‘Shift`.
124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/square/labor/shifts/client.rb', line 124 def delete(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::SANDBOX, method: "DELETE", path: "v2/labor/shifts/#{params[:id]}" ) _response = @client.send(_request) if _response.code >= "200" && _response.code < "300" return Square::Types::DeleteShiftResponse.load(_response.body) end raise _response.body end |
#get(request_options: {}, **params) ⇒ Square::Types::GetShiftResponse
Returns a single ‘Shift` specified by `id`.
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/square/labor/shifts/client.rb', line 81 def get(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::SANDBOX, method: "GET", path: "v2/labor/shifts/#{params[:id]}" ) _response = @client.send(_request) if _response.code >= "200" && _response.code < "300" return Square::Types::GetShiftResponse.load(_response.body) end raise _response.body end |
#search(request_options: {}, **params) ⇒ Square::Types::SearchShiftsResponse
Returns a paginated list of ‘Shift` records for a business. The list to be returned can be filtered by:
-
Location IDs
-
Team member IDs
-
Shift status (‘OPEN` or `CLOSED`)
-
Shift start
-
Shift end
-
Workday details
The list can be sorted by:
-
‘START_AT`
-
‘END_AT`
-
‘CREATED_AT`
-
‘UPDATED_AT`
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/square/labor/shifts/client.rb', line 63 def search(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::SANDBOX, method: "POST", path: "v2/labor/shifts/search", body: params ) _response = @client.send(_request) if _response.code >= "200" && _response.code < "300" return Square::Types::SearchShiftsResponse.load(_response.body) end raise _response.body end |
#update(request_options: {}, **params) ⇒ Square::Types::UpdateShiftResponse
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`.
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/square/labor/shifts/client.rb', line 104 def update(request_options: {}, **params) _path_param_names = ["id"] _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::SANDBOX, method: "PUT", path: "v2/labor/shifts/#{params[:id]}", body: params.except(*_path_param_names) ) _response = @client.send(_request) if _response.code >= "200" && _response.code < "300" return Square::Types::UpdateShiftResponse.load(_response.body) end raise _response.body end |