Class: Square::Loyalty::Programs::Promotions::Client
- Inherits:
-
Object
- Object
- Square::Loyalty::Programs::Promotions::Client
- Defined in:
- lib/square/loyalty/programs/promotions/client.rb
Instance Method Summary collapse
-
#cancel(request_options: {}, **params) ⇒ Square::Types::CancelLoyaltyPromotionResponse
Cancels a loyalty promotion.
-
#create(request_options: {}, **params) ⇒ Square::Types::CreateLoyaltyPromotionResponse
Creates a loyalty promotion for a [loyalty program](entity:LoyaltyProgram).
-
#get(request_options: {}, **params) ⇒ Square::Types::GetLoyaltyPromotionResponse
Retrieves a loyalty promotion.
- #initialize(client:) ⇒ Square::Loyalty::Programs::Promotions::Client constructor
-
#list(request_options: {}, **params) ⇒ Square::Types::ListLoyaltyPromotionsResponse
Lists the loyalty promotions associated with a [loyalty program](entity:LoyaltyProgram).
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
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/square/loyalty/programs/promotions/client.rb', line 107 def cancel(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::PRODUCTION, method: "POST", path: "v2/loyalty/programs/#{params[:program_id]}/promotions/#{params[:promotion_id]}/cancel" ) 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::CancelLoyaltyPromotionResponse.load(_response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(_response.body, code: code) end 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.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/square/loyalty/programs/promotions/client.rb', line 53 def create(request_options: {}, **params) _path_param_names = ["program_id"] _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::PRODUCTION, method: "POST", path: "v2/loyalty/programs/#{params[:program_id]}/promotions", body: params.except(*_path_param_names) ) 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::CreateLoyaltyPromotionResponse.load(_response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(_response.body, code: code) end end |
#get(request_options: {}, **params) ⇒ Square::Types::GetLoyaltyPromotionResponse
Retrieves a loyalty promotion.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/square/loyalty/programs/promotions/client.rb', line 79 def get(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::PRODUCTION, method: "GET", path: "v2/loyalty/programs/#{params[:program_id]}/promotions/#{params[:promotion_id]}" ) 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::GetLoyaltyPromotionResponse.load(_response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(_response.body, code: code) end 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 35 36 37 38 39 40 41 42 43 |
# File 'lib/square/loyalty/programs/promotions/client.rb', line 17 def list(request_options: {}, **params) _query_param_names = [ %w[status cursor limit], %i[status cursor limit] ].flatten _query = params.slice(*_query_param_names) params = params.except(*_query_param_names) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::PRODUCTION, method: "GET", path: "v2/loyalty/programs/#{params[:program_id]}/promotions", query: _query ) 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::ListLoyaltyPromotionsResponse.load(_response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(_response.body, code: code) end end |