Class: Square::Loyalty::Programs::Promotions::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Square::Loyalty::Programs::Promotions::Client



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

def initialize(client:)
  @client = client
end

Instance Method Details

#cancel(request_options: {}, **params) ⇒ Square::Types::CancelLoyaltyPromotionResponse

Cancels a loyalty promotion. Use this endpoint to cancel an ‘ACTIVE` promotion earlier than the end date, cancel an `ACTIVE` promotion when an end date is not specified, or cancel a `SCHEDULED` promotion. Because updating a promotion is not supported, you can also use this endpoint to cancel a promotion before you create a new one.

This endpoint sets the loyalty promotion to the ‘CANCELED` state



86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/square/loyalty/programs/promotions/client.rb', line 86

def cancel(request_options: {}, **params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::SANDBOX,
    method: "POST",
    path: "v2/loyalty/programs/#{params[:program_id]}/promotions/#{params[:promotion_id]}/cancel"
  )
  _response = @client.send(_request)
  if _response.code >= "200" && _response.code < "300"
    return Square::Types::CancelLoyaltyPromotionResponse.load(_response.body)
  end

  raise _response.body
end

#create(request_options: {}, **params) ⇒ Square::Types::CreateLoyaltyPromotionResponse

Creates a loyalty promotion for a [loyalty program](entity:LoyaltyProgram). A loyalty promotion enables buyers to earn points in addition to those earned from the base loyalty program.

This endpoint sets the loyalty promotion to the ‘ACTIVE` or `SCHEDULED` status, depending on the `available_time` setting. A loyalty program can have a maximum of 10 loyalty promotions with an `ACTIVE` or `SCHEDULED` status.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/square/loyalty/programs/promotions/client.rb', line 44

def create(request_options: {}, **params)
  _path_param_names = ["program_id"]

  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::SANDBOX,
    method: "POST",
    path: "v2/loyalty/programs/#{params[:program_id]}/promotions",
    body: params.except(*_path_param_names)
  )
  _response = @client.send(_request)
  if _response.code >= "200" && _response.code < "300"
    return Square::Types::CreateLoyaltyPromotionResponse.load(_response.body)
  end

  raise _response.body
end

#get(request_options: {}, **params) ⇒ Square::Types::GetLoyaltyPromotionResponse

Retrieves a loyalty promotion.



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/square/loyalty/programs/promotions/client.rb', line 64

def get(request_options: {}, **params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::SANDBOX,
    method: "GET",
    path: "v2/loyalty/programs/#{params[:program_id]}/promotions/#{params[:promotion_id]}"
  )
  _response = @client.send(_request)
  if _response.code >= "200" && _response.code < "300"
    return Square::Types::GetLoyaltyPromotionResponse.load(_response.body)
  end

  raise _response.body
end

#list(request_options: {}, **params) ⇒ Square::Types::ListLoyaltyPromotionsResponse

Lists the loyalty promotions associated with a [loyalty program](entity:LoyaltyProgram). Results are sorted by the ‘created_at` date in descending order (newest to oldest).



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/square/loyalty/programs/promotions/client.rb', line 17

def list(request_options: {}, **params)
  _query_param_names = %w[status cursor limit]
  _query = params.slice(*_query_param_names)
  params = params.except(*_query_param_names)

  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::SANDBOX,
    method: "GET",
    path: "v2/loyalty/programs/#{params[:program_id]}/promotions",
    query: _query
  )
  _response = @client.send(_request)
  if _response.code >= "200" && _response.code < "300"
    return Square::Types::ListLoyaltyPromotionsResponse.load(_response.body)
  end

  raise _response.body
end