Class: Square::Orders::CustomAttributes::Client
- Inherits:
-
Object
- Object
- Square::Orders::CustomAttributes::Client
- Defined in:
- lib/square/orders/custom_attributes/client.rb
Instance Method Summary collapse
-
#batch_delete(request_options: {}, **params) ⇒ Square::Types::BulkDeleteOrderCustomAttributesResponse
Deletes order [custom attributes](entity:CustomAttribute) as a bulk operation.
-
#batch_upsert(request_options: {}, **params) ⇒ Square::Types::BulkUpsertOrderCustomAttributesResponse
Creates or updates order [custom attributes](entity:CustomAttribute) as a bulk operation.
-
#delete(request_options: {}, **params) ⇒ Square::Types::DeleteOrderCustomAttributeResponse
Deletes a [custom attribute](entity:CustomAttribute) associated with a customer profile.
-
#get(request_options: {}, **params) ⇒ Square::Types::RetrieveOrderCustomAttributeResponse
Retrieves a [custom attribute](entity:CustomAttribute) associated with an order.
- #initialize(client:) ⇒ void constructor
-
#list(request_options: {}, **params) ⇒ Square::Types::ListOrderCustomAttributesResponse
Lists the [custom attributes](entity:CustomAttribute) associated with an order.
-
#upsert(request_options: {}, **params) ⇒ Square::Types::UpsertOrderCustomAttributeResponse
Creates or updates a [custom attribute](entity:CustomAttribute) for an order.
Constructor Details
#initialize(client:) ⇒ void
10 11 12 |
# File 'lib/square/orders/custom_attributes/client.rb', line 10 def initialize(client:) @client = client end |
Instance Method Details
#batch_delete(request_options: {}, **params) ⇒ Square::Types::BulkDeleteOrderCustomAttributesResponse
Deletes order [custom attributes](entity:CustomAttribute) as a bulk operation.
Use this endpoint to delete one or more custom attributes from one or more orders. A custom attribute is based on a custom attribute definition in a Square seller account. (To create a custom attribute definition, use the [CreateOrderCustomAttributeDefinition](api-endpoint:OrderCustomAttributes-CreateOrderCustomAttributeDefinition) endpoint.)
This ‘BulkDeleteOrderCustomAttributes` endpoint accepts a map of 1 to 25 individual delete requests and returns a map of individual delete responses. Each delete request has a unique ID and provides an order ID and custom attribute. Each delete response is returned with the ID of the corresponding request.
To delete a custom attribute owned by another application, the ‘visibility` setting must be `VISIBILITY_READ_WRITE_VALUES`. Note that seller-defined custom attributes (also known as custom fields) are always set to `VISIBILITY_READ_WRITE_VALUES`.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/square/orders/custom_attributes/client.rb', line 40 def batch_delete(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/orders/custom-attributes/bulk-delete", body: Square::Orders::CustomAttributes::Types::BulkDeleteOrderCustomAttributesRequest.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::BulkDeleteOrderCustomAttributesResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#batch_upsert(request_options: {}, **params) ⇒ Square::Types::BulkUpsertOrderCustomAttributesResponse
Creates or updates order [custom attributes](entity:CustomAttribute) as a bulk operation.
Use this endpoint to delete one or more custom attributes from one or more orders. A custom attribute is based on a custom attribute definition in a Square seller account. (To create a custom attribute definition, use the [CreateOrderCustomAttributeDefinition](api-endpoint:OrderCustomAttributes-CreateOrderCustomAttributeDefinition) endpoint.)
This ‘BulkUpsertOrderCustomAttributes` endpoint accepts a map of 1 to 25 individual upsert requests and returns a map of individual upsert responses. Each upsert request has a unique ID and provides an order ID and custom attribute. Each upsert response is returned with the ID of the corresponding request.
To create or update a custom attribute owned by another application, the ‘visibility` setting must be `VISIBILITY_READ_WRITE_VALUES`. Note that seller-defined custom attributes (also known as custom fields) are always set to `VISIBILITY_READ_WRITE_VALUES`.
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/orders/custom_attributes/client.rb', line 89 def batch_upsert(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/orders/custom-attributes/bulk-upsert", body: Square::Orders::CustomAttributes::Types::BulkUpsertOrderCustomAttributesRequest.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::BulkUpsertOrderCustomAttributesResponse.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::DeleteOrderCustomAttributeResponse
Deletes a [custom attribute](entity:CustomAttribute) associated with a customer profile.
To delete a custom attribute owned by another application, the ‘visibility` setting must be `VISIBILITY_READ_WRITE_VALUES`. Note that seller-defined custom attributes (also known as custom fields) are always set to `VISIBILITY_READ_WRITE_VALUES`.
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 |
# File 'lib/square/orders/custom_attributes/client.rb', line 291 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/orders/#{params[:order_id]}/custom-attributes/#{params[:custom_attribute_key]}", 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::DeleteOrderCustomAttributeResponse.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::RetrieveOrderCustomAttributeResponse
Retrieves a [custom attribute](entity:CustomAttribute) associated with an order.
You can use the ‘with_definition` query parameter to also retrieve the custom attribute definition in the same call.
To retrieve a custom attribute owned by another application, the ‘visibility` setting must be `VISIBILITY_READ_ONLY` or `VISIBILITY_READ_WRITE_VALUES`. Note that seller-defined custom attributes also known as custom fields) are always set to `VISIBILITY_READ_WRITE_VALUES`.
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/square/orders/custom_attributes/client.rb', line 195 def get(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) query_param_names = %i[version with_definition] query_params = {} query_params["version"] = params[:version] if params.key?(:version) query_params["with_definition"] = params[:with_definition] if params.key?(:with_definition) params = params.except(*query_param_names) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "v2/orders/#{params[:order_id]}/custom-attributes/#{params[:custom_attribute_key]}", 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::RetrieveOrderCustomAttributeResponse.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::ListOrderCustomAttributesResponse
Lists the [custom attributes](entity:CustomAttribute) associated with an order.
You can use the ‘with_definitions` query parameter to also retrieve custom attribute definitions in the same call.
When all response pages are retrieved, the results include all custom attributes that are visible to the requesting application, including those that are owned by other applications and set to ‘VISIBILITY_READ_ONLY` or `VISIBILITY_READ_WRITE_VALUES`.
135 136 137 138 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 169 170 171 |
# File 'lib/square/orders/custom_attributes/client.rb', line 135 def list(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) query_param_names = %i[visibility_filter cursor limit with_definitions] query_params = {} query_params["visibility_filter"] = params[:visibility_filter] if params.key?(:visibility_filter) query_params["cursor"] = params[:cursor] if params.key?(:cursor) query_params["limit"] = params[:limit] if params.key?(:limit) query_params["with_definitions"] = params[:with_definitions] if params.key?(:with_definitions) params = params.except(*query_param_names) Square::Internal::CursorItemIterator.new( cursor_field: :cursor, item_field: :custom_attributes, 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/orders/#{params[:order_id]}/custom-attributes", 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::ListOrderCustomAttributesResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end end |
#upsert(request_options: {}, **params) ⇒ Square::Types::UpsertOrderCustomAttributeResponse
Creates or updates a [custom attribute](entity:CustomAttribute) for an order.
Use this endpoint to set the value of a custom attribute for a specific order. A custom attribute is based on a custom attribute definition in a Square seller account. (To create a custom attribute definition, use the [CreateOrderCustomAttributeDefinition](api-endpoint:OrderCustomAttributes-CreateOrderCustomAttributeDefinition) endpoint.)
To create or update a custom attribute owned by another application, the ‘visibility` setting must be `VISIBILITY_READ_WRITE_VALUES`. Note that seller-defined custom attributes (also known as custom fields) are always set to `VISIBILITY_READ_WRITE_VALUES`.
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
# File 'lib/square/orders/custom_attributes/client.rb', line 247 def upsert(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) request_data = Square::Orders::CustomAttributes::Types::UpsertOrderCustomAttributeRequest.new(params).to_h non_body_param_names = %w[order_id custom_attribute_key] body = request_data.except(*non_body_param_names) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "v2/orders/#{params[:order_id]}/custom-attributes/#{params[:custom_attribute_key]}", 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::UpsertOrderCustomAttributeResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |