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

#initialize, #new_api_call_builder, #new_parameter, #new_request_builder, #new_response_handler, user_agent, user_agent_parameters

Constructor Details

This class inherits a constructor from Square::BaseApi

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



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/square/api/customer_groups_api.rb', line 41

def create_customer_group(body:)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/v2/customers/groups',
                                 'default')
               .header_param(new_parameter('application/json', key: 'Content-Type'))
               .body_param(new_parameter(body))
               .header_param(new_parameter('application/json', key: 'accept'))
               .body_serializer(proc do |param| param.to_json unless param.nil? end)
               .auth(Single.new('global')))
    .response(new_response_handler
               .deserializer(APIHelper.method(:json_deserialize))
               .is_api_response(true)
               .convertor(ApiResponse.method(:create)))
    .execute
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



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/square/api/customer_groups_api.rb', line 62

def delete_customer_group(group_id:)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::DELETE,
                                 '/v2/customers/groups/{group_id}',
                                 'default')
               .template_param(new_parameter(group_id, key: 'group_id')
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('global')))
    .response(new_response_handler
               .deserializer(APIHelper.method(:json_deserialize))
               .is_api_response(true)
               .convertor(ApiResponse.method(:create)))
    .execute
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



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/square/api/customer_groups_api.rb', line 18

def list_customer_groups(cursor: nil,
                         limit: nil)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/v2/customers/groups',
                                 'default')
               .query_param(new_parameter(cursor, key: 'cursor'))
               .query_param(new_parameter(limit, key: 'limit'))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('global')))
    .response(new_response_handler
               .deserializer(APIHelper.method(:json_deserialize))
               .is_api_response(true)
               .convertor(ApiResponse.method(:create)))
    .execute
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



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/square/api/customer_groups_api.rb', line 82

def retrieve_customer_group(group_id:)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/v2/customers/groups/{group_id}',
                                 'default')
               .template_param(new_parameter(group_id, key: 'group_id')
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('global')))
    .response(new_response_handler
               .deserializer(APIHelper.method(:json_deserialize))
               .is_api_response(true)
               .convertor(ApiResponse.method(:create)))
    .execute
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



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 105

def update_customer_group(group_id:,
                          body:)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::PUT,
                                 '/v2/customers/groups/{group_id}',
                                 'default')
               .template_param(new_parameter(group_id, key: 'group_id')
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'Content-Type'))
               .body_param(new_parameter(body))
               .header_param(new_parameter('application/json', key: 'accept'))
               .body_serializer(proc do |param| param.to_json unless param.nil? end)
               .auth(Single.new('global')))
    .response(new_response_handler
               .deserializer(APIHelper.method(:json_deserialize))
               .is_api_response(true)
               .convertor(ApiResponse.method(:create)))
    .execute
end