Class: Square::CustomerSegmentsApi

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

Overview

CustomerSegmentsApi

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

Constructor Details

#initialize(config, http_call_back: nil) ⇒ CustomerSegmentsApi

Returns a new instance of CustomerSegmentsApi.



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

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

Instance Method Details

#list_customer_segments(cursor: nil, limit: nil) ⇒ ListCustomerSegmentsResponse Hash

Retrieves the list of customer segments of a business. previous calls to ‘ListCustomerSegments`. This cursor is used to retrieve the next set of query results. For more information, see [Pagination](developer.squareup.com/docs/working-with-apis/paginat ion). to return in a single page. This limit is advisory. The response might contain more or fewer results. The limit is ignored if it is less than 1 or greater than 50. The default value is 50. For more information, see [Pagination](developer.squareup.com/docs/working-with-apis/paginat ion).

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:

  • (ListCustomerSegmentsResponse Hash)

    response from the API call



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
47
48
49
50
51
52
# File 'lib/square/api/customer_segments_api.rb', line 21

def list_customer_segments(cursor: nil,
                           limit: nil)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/customers/segments'
  _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_segment(segment_id:) ⇒ RetrieveCustomerSegmentResponse Hash

Retrieves a specific customer segment as identified by the ‘segment_id` value. customer segment.

Parameters:

  • segment_id (String)

    Required parameter: The Square-issued ID of the

Returns:

  • (RetrieveCustomerSegmentResponse Hash)

    response from the API call



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

def retrieve_customer_segment(segment_id:)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/customers/segments/{segment_id}'
  _query_builder = APIHelper.append_url_with_template_parameters(
    _query_builder,
    'segment_id' => { 'value' => segment_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