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:) ⇒ void constructor
-
#list(request_options: {}, **params) ⇒ Square::Types::ListLoyaltyPromotionsResponse
Lists the loyalty promotions associated with a [loyalty program](entity:LoyaltyProgram).
Constructor Details
#initialize(client:) ⇒ void
11 12 13 |
# File 'lib/square/loyalty/programs/promotions/client.rb', line 11 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
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/square/loyalty/programs/promotions/client.rb', line 165 def cancel(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "v2/loyalty/programs/#{params[:program_id]}/promotions/#{params[:promotion_id]}/cancel", 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::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.
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/square/loyalty/programs/promotions/client.rb', line 85 def create(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) request_data = Square::Loyalty::Programs::Promotions::Types::CreateLoyaltyPromotionRequest.new(params).to_h non_body_param_names = ["program_id"] body = request_data.except(*non_body_param_names) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "v2/loyalty/programs/#{params[:program_id]}/promotions", body: body, 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::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.
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/square/loyalty/programs/promotions/client.rb', line 125 def get(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "v2/loyalty/programs/#{params[:program_id]}/promotions/#{params[:promotion_id]}", 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::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).
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/square/loyalty/programs/promotions/client.rb', line 31 def list(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) query_param_names = %i[status cursor limit] query_params = {} query_params["status"] = params[:status] if params.key?(:status) query_params["cursor"] = params[:cursor] if params.key?(:cursor) query_params["limit"] = params[:limit] if params.key?(:limit) params = params.except(*query_param_names) Square::Internal::CursorItemIterator.new( cursor_field: :cursor, item_field: :loyalty_promotions, initial_cursor: query_params[:cursor] ) do |next_cursor| query_params[:cursor] = next_cursor request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "v2/loyalty/programs/#{params[:program_id]}/promotions", query: query_params, 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::ListLoyaltyPromotionsResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end end |