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 46 47 48 49 50 51 |
# 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::PRODUCTION, method: "POST", path: "v2/labor/shifts", body: params ) begin _response = @client.send(_request) rescue Net::HTTPRequestTimeout raise Square::Errors::TimeoutError end code = _response.code.to_i if code.between?(200, 299) Square::Types::CreateShiftResponse.load(_response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(_response.body, code: code) end end |
#delete(request_options: {}, **params) ⇒ Square::Types::DeleteShiftResponse
Deletes a ‘Shift`.
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/square/labor/shifts/client.rb', line 148 def delete(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::PRODUCTION, method: "DELETE", path: "v2/labor/shifts/#{params[:id]}" ) begin _response = @client.send(_request) rescue Net::HTTPRequestTimeout raise Square::Errors::TimeoutError end code = _response.code.to_i if code.between?(200, 299) Square::Types::DeleteShiftResponse.load(_response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(_response.body, code: code) end end |
#get(request_options: {}, **params) ⇒ Square::Types::GetShiftResponse
Returns a single ‘Shift` specified by `id`.
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/square/labor/shifts/client.rb', line 93 def get(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::PRODUCTION, method: "GET", path: "v2/labor/shifts/#{params[:id]}" ) begin _response = @client.send(_request) rescue Net::HTTPRequestTimeout raise Square::Errors::TimeoutError end code = _response.code.to_i if code.between?(200, 299) Square::Types::GetShiftResponse.load(_response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(_response.body, code: code) end 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`
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/square/labor/shifts/client.rb', line 69 def search(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::PRODUCTION, method: "POST", path: "v2/labor/shifts/search", body: params ) begin _response = @client.send(_request) rescue Net::HTTPRequestTimeout raise Square::Errors::TimeoutError end code = _response.code.to_i if code.between?(200, 299) Square::Types::SearchShiftsResponse.load(_response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(_response.body, code: code) end 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`.
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/square/labor/shifts/client.rb', line 122 def update(request_options: {}, **params) _path_param_names = ["id"] _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::PRODUCTION, method: "PUT", path: "v2/labor/shifts/#{params[:id]}", body: params.except(*_path_param_names) ) begin _response = @client.send(_request) rescue Net::HTTPRequestTimeout raise Square::Errors::TimeoutError end code = _response.code.to_i if code.between?(200, 299) Square::Types::UpdateShiftResponse.load(_response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(_response.body, code: code) end end |