Class: Square::Loyalty::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void

Parameters:



9
10
11
# File 'lib/square/loyalty/client.rb', line 9

def initialize(client:)
  @client = client
end

Instance Method Details

#accountsSquare::Accounts::Client

Returns:

  • (Square::Accounts::Client)


55
56
57
# File 'lib/square/loyalty/client.rb', line 55

def accounts
  @accounts ||= Square::Loyalty::Accounts::Client.new(client: @client)
end

#programsSquare::Programs::Client

Returns:

  • (Square::Programs::Client)


60
61
62
# File 'lib/square/loyalty/client.rb', line 60

def programs
  @programs ||= Square::Loyalty::Programs::Client.new(client: @client)
end

#rewardsSquare::Rewards::Client

Returns:

  • (Square::Rewards::Client)


65
66
67
# File 'lib/square/loyalty/client.rb', line 65

def rewards
  @rewards ||= Square::Loyalty::Rewards::Client.new(client: @client)
end

#search_events(request_options: {}, **params) ⇒ Square::Types::SearchLoyaltyEventsResponse

Searches for loyalty events.

A Square loyalty program maintains a ledger of events that occur during the lifetime of a buyer’s loyalty account. Each change in the point balance (for example, points earned, points redeemed, and points expired) is recorded in the ledger. Using this endpoint, you can search the ledger for events.

Search results are sorted by ‘created_at` in descending order.

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Returns:



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/loyalty/client.rb', line 31

def search_events(request_options: {}, **params)
  params = Square::Internal::Types::Utils.normalize_keys(params)
  request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "v2/loyalty/events/search",
    body: Square::Loyalty::Types::SearchLoyaltyEventsRequest.new(params).to_h,
    request_options: request_options
  )
  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::SearchLoyaltyEventsResponse.load(response.body)
  else
    error_class = Square::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end