Class: Square::Customers::CustomAttributes::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/square/customers/custom_attributes/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Square::Customers::CustomAttributes::Client



8
9
10
# File 'lib/square/customers/custom_attributes/client.rb', line 8

def initialize(client:)
  @client = client
end

Instance Method Details

#delete(request_options: {}, **params) ⇒ Square::Types::DeleteCustomerCustomAttributeResponse

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`.



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/square/customers/custom_attributes/client.rb', line 129

def delete(request_options: {}, **params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
    method: "DELETE",
    path: "v2/customers/#{params[:customer_id]}/custom-attributes/#{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::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](entity:CustomAttribute) 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`.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/square/customers/custom_attributes/client.rb', line 60

def get(request_options: {}, **params)
  _query_param_names = [
    %w[with_definition version],
    %i[with_definition version]
  ].flatten
  _query = params.slice(*_query_param_names)
  params = params.except(*_query_param_names)

  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
    method: "GET",
    path: "v2/customers/#{params[:customer_id]}/custom-attributes/#{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::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](entity:CustomAttribute) 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`.



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
47
48
# File 'lib/square/customers/custom_attributes/client.rb', line 22

def list(request_options: {}, **params)
  _query_param_names = [
    %w[limit cursor with_definitions],
    %i[limit cursor with_definitions]
  ].flatten
  _query = params.slice(*_query_param_names)
  params = params.except(*_query_param_names)

  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
    method: "GET",
    path: "v2/customers/#{params[:customer_id]}/custom-attributes",
    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::ListCustomerCustomAttributesResponse.load(_response.body)
  else
    error_class = Square::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(_response.body, code: code)
  end
end

#upsert(request_options: {}, **params) ⇒ Square::Types::UpsertCustomerCustomAttributeResponse

Creates or updates a [custom attribute](entity:CustomAttribute) 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](api-endpoint:CustomerCustomAttributes-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`.



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/square/customers/custom_attributes/client.rb', line 99

def upsert(request_options: {}, **params)
  _path_param_names = %w[customer_id key]

  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
    method: "POST",
    path: "v2/customers/#{params[:customer_id]}/custom-attributes/#{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::UpsertCustomerCustomAttributeResponse.load(_response.body)
  else
    error_class = Square::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(_response.body, code: code)
  end
end