Class: Square::Customers::CustomAttributeDefinitions::Client
- Inherits:
-
Object
- Object
- Square::Customers::CustomAttributeDefinitions::Client
- Defined in:
- lib/square/customers/custom_attribute_definitions/client.rb
Instance Method Summary collapse
-
#batch_upsert(request_options: {}, **params) ⇒ Square::Types::BatchUpsertCustomerCustomAttributesResponse
Creates or updates [custom attributes](entity:CustomAttribute) for customer profiles as a bulk operation.
-
#create(request_options: {}, **params) ⇒ Square::Types::CreateCustomerCustomAttributeDefinitionResponse
Creates a customer-related [custom attribute definition](entity:CustomAttributeDefinition) for a Square seller account.
-
#delete(request_options: {}, **params) ⇒ Square::Types::DeleteCustomerCustomAttributeDefinitionResponse
Deletes a customer-related [custom attribute definition](entity:CustomAttributeDefinition) from a Square seller account.
-
#get(request_options: {}, **params) ⇒ Square::Types::GetCustomerCustomAttributeDefinitionResponse
Retrieves a customer-related [custom attribute definition](entity:CustomAttributeDefinition) from a Square seller account.
- #initialize(client:) ⇒ Square::Customers::CustomAttributeDefinitions::Client constructor
-
#list(request_options: {}, **params) ⇒ Square::Types::ListCustomerCustomAttributeDefinitionsResponse
Lists the customer-related [custom attribute definitions](entity:CustomAttributeDefinition) that belong to a Square seller account.
-
#update(request_options: {}, **params) ⇒ Square::Types::UpdateCustomerCustomAttributeDefinitionResponse
Updates a customer-related [custom attribute definition](entity:CustomAttributeDefinition) for a Square seller account.
Constructor Details
#initialize(client:) ⇒ Square::Customers::CustomAttributeDefinitions::Client
8 9 10 |
# File 'lib/square/customers/custom_attribute_definitions/client.rb', line 8 def initialize(client:) @client = client end |
Instance Method Details
#batch_upsert(request_options: {}, **params) ⇒ Square::Types::BatchUpsertCustomerCustomAttributesResponse
Creates or updates [custom attributes](entity:CustomAttribute) for customer profiles as a bulk operation.
Use this endpoint to set the value of one or more custom attributes for one or more customer profiles. A custom attribute is based on a custom attribute definition in a Square seller account, which is created using the [CreateCustomerCustomAttributeDefinition](api-endpoint:CustomerCustomAttributes-CreateCustomerCustomAttributeDefinition) endpoint.
This ‘BulkUpsertCustomerCustomAttributes` 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 a customer 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`.
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/square/customers/custom_attribute_definitions/client.rb', line 193 def batch_upsert(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::PRODUCTION, method: "POST", path: "v2/customers/custom-attributes/bulk-upsert", 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::BatchUpsertCustomerCustomAttributesResponse.load(_response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(_response.body, code: code) end end |
#create(request_options: {}, **params) ⇒ Square::Types::CreateCustomerCustomAttributeDefinitionResponse
Creates a customer-related [custom attribute definition](entity:CustomAttributeDefinition) for a Square seller account. Use this endpoint to define a custom attribute that can be associated with customer profiles.
A custom attribute definition specifies the ‘key`, `visibility`, `schema`, and other properties for a custom attribute. After the definition is created, you can call [UpsertCustomerCustomAttribute](api-endpoint:CustomerCustomAttributes-UpsertCustomerCustomAttribute) or [BulkUpsertCustomerCustomAttributes](api-endpoint:CustomerCustomAttributes-BulkUpsertCustomerCustomAttributes) to set the custom attribute for customer profiles in the seller’s Customer Directory.
Sellers can view all custom attributes in exported customer data, including those set to ‘VISIBILITY_HIDDEN`.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/square/customers/custom_attribute_definitions/client.rb', line 61 def create(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::PRODUCTION, method: "POST", path: "v2/customers/custom-attribute-definitions", 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::CreateCustomerCustomAttributeDefinitionResponse.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::DeleteCustomerCustomAttributeDefinitionResponse
Deletes a customer-related [custom attribute definition](entity:CustomAttributeDefinition) from a Square seller account.
Deleting a custom attribute definition also deletes the corresponding custom attribute from all customer profiles in the seller’s Customer Directory.
Only the definition owner can delete a custom attribute definition.
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/square/customers/custom_attribute_definitions/client.rb', line 157 def delete(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::PRODUCTION, method: "DELETE", path: "v2/customers/custom-attribute-definitions/#{params[:key]}" ) 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::DeleteCustomerCustomAttributeDefinitionResponse.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::GetCustomerCustomAttributeDefinitionResponse
Retrieves a customer-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`.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/square/customers/custom_attribute_definitions/client.rb', line 89 def get(request_options: {}, **params) _query_param_names = [ ["version"], %i[version] ].flatten _query = params.slice(*_query_param_names) params = params.except(*_query_param_names) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::PRODUCTION, method: "GET", path: "v2/customers/custom-attribute-definitions/#{params[:key]}", query: _query ) 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::GetCustomerCustomAttributeDefinitionResponse.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::ListCustomerCustomAttributeDefinitionsResponse
Lists the customer-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`.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/square/customers/custom_attribute_definitions/client.rb', line 20 def list(request_options: {}, **params) _query_param_names = [ %w[limit cursor], %i[limit cursor] ].flatten _query = params.slice(*_query_param_names) params.except(*_query_param_names) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::PRODUCTION, method: "GET", path: "v2/customers/custom-attribute-definitions", query: _query ) 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::ListCustomerCustomAttributeDefinitionsResponse.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::UpdateCustomerCustomAttributeDefinitionResponse
Updates a customer-related [custom attribute definition](entity:CustomAttributeDefinition) for a Square seller account.
Use this endpoint to update the following fields: ‘name`, `description`, `visibility`, or the `schema` for a `Selection` data type.
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`.
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/square/customers/custom_attribute_definitions/client.rb', line 126 def update(request_options: {}, **params) _path_param_names = ["key"] _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::PRODUCTION, method: "PUT", path: "v2/customers/custom-attribute-definitions/#{params[:key]}", 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::UpdateCustomerCustomAttributeDefinitionResponse.load(_response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(_response.body, code: code) end end |