Class: Square::Customers::CustomAttributes::Client
- Inherits:
-
Object
- Object
- Square::Customers::CustomAttributes::Client
- Defined in:
- lib/square/customers/custom_attributes/client.rb
Instance Method Summary collapse
-
#delete(request_options: {}, **params) ⇒ Square::Types::DeleteCustomerCustomAttributeResponse
Deletes a custom attribute associated with a customer profile.
-
#get(request_options: {}, **params) ⇒ Square::Types::GetCustomerCustomAttributeResponse
Retrieves a custom attribute associated with a customer profile.
- #initialize(client:) ⇒ void constructor
-
#list(request_options: {}, **params) ⇒ Square::Types::ListCustomerCustomAttributesResponse
Lists the custom attributes associated with a customer profile.
-
#upsert(request_options: {}, **params) ⇒ Square::Types::UpsertCustomerCustomAttributeResponse
Creates or updates a custom attribute for a customer profile.
Constructor Details
#initialize(client:) ⇒ void
10 11 12 |
# File 'lib/square/customers/custom_attributes/client.rb', line 10 def initialize(client:) @client = client end |
Instance Method Details
#delete(request_options: {}, **params) ⇒ Square::Types::DeleteCustomerCustomAttributeResponse
Deletes a custom attribute 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.
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/square/customers/custom_attributes/client.rb', line 191 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/customers/#{params[:customer_id]}/custom-attributes/#{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::DeleteCustomerCustomAttributeResponse.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::GetCustomerCustomAttributeResponse
Retrieves a custom attribute associated with a customer profile.
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.
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/square/customers/custom_attributes/client.rb', line 95 def get(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) query_param_names = %i[with_definition version] query_params = {} query_params["with_definition"] = params[:with_definition] if params.key?(:with_definition) 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/customers/#{params[:customer_id]}/custom-attributes/#{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::GetCustomerCustomAttributeResponse.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::ListCustomerCustomAttributesResponse
Lists the custom attributes associated with a customer profile.
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.
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 71 |
# File 'lib/square/customers/custom_attributes/client.rb', line 36 def list(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) query_param_names = %i[limit cursor with_definitions] query_params = {} query_params["limit"] = params[:limit] if params.key?(:limit) query_params["cursor"] = params[:cursor] if params.key?(:cursor) 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/customers/#{params[:customer_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::ListCustomerCustomAttributesResponse.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::UpsertCustomerCustomAttributeResponse
Creates or updates a custom attribute for a customer profile.
Use this endpoint to set the value of a custom attribute for a specified customer profile. A custom attribute is based on a custom attribute definition in a Square seller account, which is created using the CreateCustomerCustomAttributeDefinition 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.
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 172 |
# File 'lib/square/customers/custom_attributes/client.rb', line 147 def upsert(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) request_data = Square::Customers::CustomAttributes::Types::UpsertCustomerCustomAttributeRequest.new(params).to_h non_body_param_names = %w[customer_id key] body = request_data.except(*non_body_param_names) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "v2/customers/#{params[:customer_id]}/custom-attributes/#{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::UpsertCustomerCustomAttributeResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |