Class: Leal::CustomerCards::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/leal/customer_cards/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void

Parameters:



9
10
11
# File 'lib/leal/customer_cards/client.rb', line 9

def initialize(client:)
  @client = client
end

Instance Method Details

#get(request_options: {}, **params) ⇒ Leal::CustomerCards::Types::GetCustomerCardsResponse

Returns detailed information about a specific customer card, including stamp progress, a list of rewards the customer has earned enough stamps to redeem, and wallet pass URLs (apple_wallet_url and google_wallet_url) for adding the card to Apple Wallet or Google Wallet.

Examples:

client.customer_cards.get(
  account_id: 1,
  customer_id: 1,
  id: 1
)

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

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)

Options Hash (**params):

  • :account_id (Integer)
  • :customer_id (Integer)
  • :id (Integer)

Returns:



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/leal/customer_cards/client.rb', line 79

def get(request_options: {}, **params)
  params = Leal::Internal::Types::Utils.normalize_keys(params)
  request = Leal::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "api/v1/accounts/#{URI.encode_uri_component(params[:account_id].to_s)}/customers/#{URI.encode_uri_component(params[:customer_id].to_s)}/customer_cards/#{URI.encode_uri_component(params[:id].to_s)}",
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Leal::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Leal::CustomerCards::Types::GetCustomerCardsResponse.load(response.body)
  else
    error_class = Leal::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#list(request_options: {}, **params) ⇒ Array[Leal::CustomerCards::Types::ListCustomerCardsResponseItem]

Returns all loyalty cards enrolled for a specific customer, including stamp progress, status, wallet pass installation state, and wallet pass URLs (apple_wallet_url and google_wallet_url) that you can use to let customers add their loyalty card to Apple Wallet or Google Wallet from your own app or website.

Examples:

client.customer_cards.list(
  account_id: 1,
  customer_id: 1
)

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

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)

Options Hash (**params):

  • :account_id (Integer)
  • :customer_id (Integer)

Returns:

Raises:

  • (error_class)


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/leal/customer_cards/client.rb', line 35

def list(request_options: {}, **params)
  params = Leal::Internal::Types::Utils.normalize_keys(params)
  request = Leal::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "api/v1/accounts/#{URI.encode_uri_component(params[:account_id].to_s)}/customers/#{URI.encode_uri_component(params[:customer_id].to_s)}/customer_cards",
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Leal::Errors::TimeoutError
  end
  code = response.code.to_i
  return if code.between?(200, 299)

  error_class = Leal::Errors::ResponseError.subclass_for_code(code)
  raise error_class.new(response.body, code: code)
end

#redeem(request_options: {}, **params) ⇒ Leal::CustomerCards::Types::RedeemCustomerCardsResponse

Redeems a reward for a customer, deducting the required stamps from their card. The customer must have enough stamps on this card to cover the reward's cost. Triggers wallet pass updates and push notifications.

Examples:

client.customer_cards.redeem(
  account_id: 1,
  customer_id: 1,
  id: 1,
  reward_id: 1
)

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)

Options Hash (**params):

  • :account_id (Integer)
  • :customer_id (Integer)
  • :id (Integer)

Returns:



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/leal/customer_cards/client.rb', line 125

def redeem(request_options: {}, **params)
  params = Leal::Internal::Types::Utils.normalize_keys(params)
  request_data = Leal::CustomerCards::Types::RedeemCustomerCardsRequest.new(params).to_h
  non_body_param_names = %w[account_id customer_id id]
  body = request_data.except(*non_body_param_names)

  request = Leal::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "api/v1/accounts/#{URI.encode_uri_component(params[:account_id].to_s)}/customers/#{URI.encode_uri_component(params[:customer_id].to_s)}/customer_cards/#{URI.encode_uri_component(params[:id].to_s)}/redeem",
    body: body,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Leal::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Leal::CustomerCards::Types::RedeemCustomerCardsResponse.load(response.body)
  else
    error_class = Leal::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#stamp(request_options: {}, **params) ⇒ Leal::CustomerCards::Types::StampCustomerCardsResponse

Adds stamps to a customer's loyalty card. Triggers ledger entries, wallet pass updates, and push notifications. Pass skip_notifications to stamp silently.

Examples:

client.customer_cards.stamp(
  account_id: 1,
  customer_id: 1,
  id: 1,
  stamps: 1
)

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)

Options Hash (**params):

  • :account_id (Integer)
  • :customer_id (Integer)
  • :id (Integer)

Returns:



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
200
# File 'lib/leal/customer_cards/client.rb', line 175

def stamp(request_options: {}, **params)
  params = Leal::Internal::Types::Utils.normalize_keys(params)
  request_data = Leal::CustomerCards::Types::StampCustomerCardsRequest.new(params).to_h
  non_body_param_names = %w[account_id customer_id id]
  body = request_data.except(*non_body_param_names)

  request = Leal::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "api/v1/accounts/#{URI.encode_uri_component(params[:account_id].to_s)}/customers/#{URI.encode_uri_component(params[:customer_id].to_s)}/customer_cards/#{URI.encode_uri_component(params[:id].to_s)}/stamp",
    body: body,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Leal::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Leal::CustomerCards::Types::StampCustomerCardsResponse.load(response.body)
  else
    error_class = Leal::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end