Class: Square::Orders::CustomAttributeDefinitions::Client
- Inherits:
-
Object
- Object
- Square::Orders::CustomAttributeDefinitions::Client
- Defined in:
- lib/square/orders/custom_attribute_definitions/client.rb
Instance Method Summary collapse
-
#create(request_options: {}, **params) ⇒ Square::Types::CreateOrderCustomAttributeDefinitionResponse
Creates an order-related custom attribute definition.
-
#delete(request_options: {}, **params) ⇒ Square::Types::DeleteOrderCustomAttributeDefinitionResponse
Deletes an order-related [custom attribute definition](entity:CustomAttributeDefinition) from a Square seller account.
-
#get(request_options: {}, **params) ⇒ Square::Types::RetrieveOrderCustomAttributeDefinitionResponse
Retrieves an order-related [custom attribute definition](entity:CustomAttributeDefinition) from a Square seller account.
- #initialize(client:) ⇒ void constructor
-
#list(request_options: {}, **params) ⇒ Square::Types::ListOrderCustomAttributeDefinitionsResponse
Lists the order-related [custom attribute definitions](entity:CustomAttributeDefinition) that belong to a Square seller account.
-
#update(request_options: {}, **params) ⇒ Square::Types::UpdateOrderCustomAttributeDefinitionResponse
Updates an order-related custom attribute definition for a Square seller account.
Constructor Details
#initialize(client:) ⇒ void
10 11 12 |
# File 'lib/square/orders/custom_attribute_definitions/client.rb', line 10 def initialize(client:) @client = client end |
Instance Method Details
#create(request_options: {}, **params) ⇒ Square::Types::CreateOrderCustomAttributeDefinitionResponse
Creates an order-related custom attribute definition. Use this endpoint to define a custom attribute that can be associated with orders.
After creating a custom attribute definition, you can set the custom attribute for orders in the Square seller account.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/square/orders/custom_attribute_definitions/client.rb', line 87 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/orders/custom-attribute-definitions", body: Square::Orders::CustomAttributeDefinitions::Types::CreateOrderCustomAttributeDefinitionRequest.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::CreateOrderCustomAttributeDefinitionResponse.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::DeleteOrderCustomAttributeDefinitionResponse
Deletes an order-related [custom attribute definition](entity:CustomAttributeDefinition) from a Square seller account.
Only the definition owner can delete a custom attribute definition.
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/square/orders/custom_attribute_definitions/client.rb', line 214 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/custom-attribute-definitions/#{params[: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::DeleteOrderCustomAttributeDefinitionResponse.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::RetrieveOrderCustomAttributeDefinitionResponse
Retrieves an order-related [custom attribute definition](entity:CustomAttributeDefinition) from a Square seller account.
To retrieve a custom attribute definition created 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`.
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/square/orders/custom_attribute_definitions/client.rb', line 129 def get(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) query_param_names = %i[version] query_params = {} query_params["version"] = params[:version] if params.key?(:version) params = params.except(*query_param_names) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "v2/orders/custom-attribute-definitions/#{params[: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::RetrieveOrderCustomAttributeDefinitionResponse.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::ListOrderCustomAttributeDefinitionsResponse
Lists the order-related [custom attribute definitions](entity:CustomAttributeDefinition) that belong to a Square seller account.
When all response pages are retrieved, the results include all custom attribute definitions that are visible to the requesting application, including those that are created by other applications and set to ‘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`.
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 64 65 66 67 68 69 70 |
# File 'lib/square/orders/custom_attribute_definitions/client.rb', line 35 def list(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) query_param_names = %i[visibility_filter cursor limit] 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) params.except(*query_param_names) Square::Internal::CursorItemIterator.new( cursor_field: :cursor, item_field: :custom_attribute_definitions, 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/custom-attribute-definitions", 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::ListOrderCustomAttributeDefinitionsResponse.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::UpdateOrderCustomAttributeDefinitionResponse
Updates an order-related custom attribute definition for a Square seller account.
Only the definition owner can update a custom attribute definition. Note that sellers can view all custom attributes in exported customer data, including those set to ‘VISIBILITY_HIDDEN`.
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/square/orders/custom_attribute_definitions/client.rb', line 172 def update(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) request_data = Square::Orders::CustomAttributeDefinitions::Types::UpdateOrderCustomAttributeDefinitionRequest.new(params).to_h non_body_param_names = ["key"] body = request_data.except(*non_body_param_names) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "PUT", path: "v2/orders/custom-attribute-definitions/#{params[: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::UpdateOrderCustomAttributeDefinitionResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |