Class: Square::CustomerGroupsApi

Inherits:
BaseApi
  • Object
show all
Defined in:
lib/square/api/customer_groups_api.rb

Overview

CustomerGroupsApi

Instance Attribute Summary

Attributes inherited from BaseApi

#config, #http_call_back

Instance Method Summary collapse

Methods inherited from BaseApi

#execute_request, #get_user_agent, #validate_parameters, #validate_parameters_types

Constructor Details

#initialize(config, http_call_back: nil) ⇒ CustomerGroupsApi

Returns a new instance of CustomerGroupsApi.



4
5
6
# File 'lib/square/api/customer_groups_api.rb', line 4

def initialize(config, http_call_back: nil)
  super(config, http_call_back: http_call_back)
end

Instance Method Details

#create_customer_group(body:) ⇒ CreateCustomerGroupResponse Hash

Creates a new customer group for a business. The request must include the `name` value of the group. containing the fields to POST for the request. See the corresponding object definition for field details.

Parameters:

  • body (CreateCustomerGroupRequest)

    Required parameter: An object

Returns:

  • (CreateCustomerGroupResponse Hash)

    response from the API call



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
87
88
# File 'lib/square/api/customer_groups_api.rb', line 61

def create_customer_group(body:)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/customers/groups'
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json',
    'Content-Type' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.post(
    _query_url,
    headers: _headers,
    parameters: body.to_json
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end

#delete_customer_group(group_id:) ⇒ DeleteCustomerGroupResponse Hash

Deletes a customer group as identified by the `group_id` value. to delete.

Parameters:

  • group_id (String)

    Required parameter: The ID of the customer group

Returns:

  • (DeleteCustomerGroupResponse Hash)

    response from the API call



94
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
123
# File 'lib/square/api/customer_groups_api.rb', line 94

def delete_customer_group(group_id:)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/customers/groups/{group_id}'
  _query_builder = APIHelper.append_url_with_template_parameters(
    _query_builder,
    'group_id' => { 'value' => group_id, 'encode' => true }
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.delete(
    _query_url,
    headers: _headers
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end

#list_customer_groups(cursor: nil, limit: nil) ⇒ ListCustomerGroupsResponse Hash

Retrieves the list of customer groups of a business. a previous call to this endpoint. Provide this cursor to retrieve the next set of results for your original query. For more information, see [Pagination](developer.squareup.com/docs/build-basics/common-api-p atterns/pagination). to return in a single page. This limit is advisory. The response might contain more or fewer results. If the limit is less than 1 or greater than 50, Square returns a `400 VALUE_TOO_LOW` or `400 VALUE_TOO_HIGH` error. The default value is 50. For more information, see [Pagination](developer.squareup.com/docs/build-basics/common-api-p atterns/pagination).

Parameters:

  • cursor (String) (defaults to: nil)

    Optional parameter: A pagination cursor returned by

  • limit (Integer) (defaults to: nil)

    Optional parameter: The maximum number of results

Returns:

  • (ListCustomerGroupsResponse Hash)

    response from the API call



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
49
50
51
52
53
# File 'lib/square/api/customer_groups_api.rb', line 22

def list_customer_groups(cursor: nil,
                         limit: nil)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/customers/groups'
  _query_builder = APIHelper.append_url_with_query_parameters(
    _query_builder,
    'cursor' => cursor,
    'limit' => limit
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.get(
    _query_url,
    headers: _headers
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end

#retrieve_customer_group(group_id:) ⇒ RetrieveCustomerGroupResponse Hash

Retrieves a specific customer group as identified by the `group_id` value. to retrieve.

Parameters:

  • group_id (String)

    Required parameter: The ID of the customer group

Returns:

  • (RetrieveCustomerGroupResponse Hash)

    response from the API call



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
156
157
158
# File 'lib/square/api/customer_groups_api.rb', line 129

def retrieve_customer_group(group_id:)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/customers/groups/{group_id}'
  _query_builder = APIHelper.append_url_with_template_parameters(
    _query_builder,
    'group_id' => { 'value' => group_id, 'encode' => true }
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.get(
    _query_url,
    headers: _headers
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end

#update_customer_group(group_id:, body:) ⇒ UpdateCustomerGroupResponse Hash

Updates a customer group as identified by the `group_id` value. to update. containing the fields to POST for the request. See the corresponding object definition for field details.

Parameters:

  • group_id (String)

    Required parameter: The ID of the customer group

  • body (UpdateCustomerGroupRequest)

    Required parameter: An object

Returns:

  • (UpdateCustomerGroupResponse Hash)

    response from the API call



167
168
169
170
171
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
198
199
# File 'lib/square/api/customer_groups_api.rb', line 167

def update_customer_group(group_id:,
                          body:)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/customers/groups/{group_id}'
  _query_builder = APIHelper.append_url_with_template_parameters(
    _query_builder,
    'group_id' => { 'value' => group_id, 'encode' => true }
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json',
    'Content-Type' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.put(
    _query_url,
    headers: _headers,
    parameters: body.to_json
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end