class Square::CustomerSegmentsApi

CustomerSegmentsApi

Public Class Methods

new(config, http_call_back: nil) click to toggle source
Calls superclass method Square::BaseApi::new
# 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

Public Instance Methods

list_customer_segments(cursor: nil, limit: nil) click to toggle source

Retrieves the list of customer segments of a business. @param [String] cursor Optional parameter: A pagination cursor returned by 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/build-basics/common-api-p atterns/pagination). @param [Integer] limit Optional parameter: The maximum number of results to return in a single page. This limit is advisory. The response might contain more or fewer results. If the specified 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). @return [ListCustomerSegmentsResponse Hash] response from the API call

# File lib/square/api/customer_segments_api.rb, line 22
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:) click to toggle source

Retrieves a specific customer segment as identified by the ‘segment_id` value. @param [String] segment_id Required parameter: The Square-issued ID of the customer segment. @return [RetrieveCustomerSegmentResponse Hash] response from the API call

# File lib/square/api/customer_segments_api.rb, line 60
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