Class: Square::Labor::BreakTypes::Client
- Inherits:
-
Object
- Object
- Square::Labor::BreakTypes::Client
- Defined in:
- lib/square/labor/break_types/client.rb
Instance Method Summary collapse
-
#create(request_options: {}, **params) ⇒ Square::Types::CreateBreakTypeResponse
Creates a new ‘BreakType`.
-
#delete(request_options: {}, **params) ⇒ Square::Types::DeleteBreakTypeResponse
Deletes an existing ‘BreakType`.
-
#get(request_options: {}, **params) ⇒ Square::Types::GetBreakTypeResponse
Returns a single ‘BreakType` specified by `id`.
- #initialize(client:) ⇒ void constructor
-
#list(request_options: {}, **params) ⇒ Square::Types::ListBreakTypesResponse
Returns a paginated list of ‘BreakType` instances for a business.
-
#update(request_options: {}, **params) ⇒ Square::Types::UpdateBreakTypeResponse
Updates an existing ‘BreakType`.
Constructor Details
#initialize(client:) ⇒ void
10 11 12 |
# File 'lib/square/labor/break_types/client.rb', line 10 def initialize(client:) @client = client end |
Instance Method Details
#create(request_options: {}, **params) ⇒ Square::Types::CreateBreakTypeResponse
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.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/square/labor/break_types/client.rb', line 89 def create(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "v2/labor/break-types", body: Square::Labor::BreakTypes::Types::CreateBreakTypeRequest.new(params).to_h, request_options: ) 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::CreateBreakTypeResponse.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::DeleteBreakTypeResponse
Deletes an existing ‘BreakType`.
A ‘BreakType` can be deleted even if it is referenced from a `Shift`.
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/square/labor/break_types/client.rb', line 199 def delete(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "DELETE", path: "v2/labor/break-types/#{params[:id]}", request_options: ) 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::DeleteBreakTypeResponse.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::GetBreakTypeResponse
Returns a single ‘BreakType` specified by `id`.
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/square/labor/break_types/client.rb', line 124 def get(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "v2/labor/break-types/#{params[:id]}", request_options: ) 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::GetBreakTypeResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#list(request_options: {}, **params) ⇒ Square::Types::ListBreakTypesResponse
Returns a paginated list of ‘BreakType` instances for a business.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/square/labor/break_types/client.rb', line 28 def list(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) query_param_names = %i[location_id limit cursor] query_params = {} query_params["location_id"] = params[:location_id] if params.key?(:location_id) query_params["limit"] = params[:limit] if params.key?(:limit) query_params["cursor"] = params[:cursor] if params.key?(:cursor) params.except(*query_param_names) Square::Internal::CursorItemIterator.new( cursor_field: :cursor, item_field: :break_types, initial_cursor: query_params[:cursor] ) do |next_cursor| query_params[:cursor] = next_cursor request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "v2/labor/break-types", query: query_params, request_options: ) 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::ListBreakTypesResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end end |
#update(request_options: {}, **params) ⇒ Square::Types::UpdateBreakTypeResponse
Updates an existing ‘BreakType`.
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/square/labor/break_types/client.rb', line 158 def update(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) request_data = Square::Labor::BreakTypes::Types::UpdateBreakTypeRequest.new(params).to_h non_body_param_names = ["id"] body = request_data.except(*non_body_param_names) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "PUT", path: "v2/labor/break-types/#{params[:id]}", body: body, request_options: ) 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::UpdateBreakTypeResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |