Class: Chargify::Coupon

Inherits:
Base
  • Object
show all
Defined in:
lib/chargify_api_ares/resources/coupon.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

element_name, #to_xml

Class Method Details

.find_all_by_product_family_id(product_family_id) ⇒ Object



3
4
5
# File 'lib/chargify_api_ares/resources/coupon.rb', line 3

def self.find_all_by_product_family_id(product_family_id)
  Coupon.find(:all, :params => { :product_family_id => product_family_id })
end

.find_by_product_family_id_and_code(product_family_id, code) ⇒ Object



7
8
9
# File 'lib/chargify_api_ares/resources/coupon.rb', line 7

def self.find_by_product_family_id_and_code(product_family_id, code)
  find(:one, :from => :lookup, :params => {:product_family_id => product_family_id, :code => code})
end

.validate(params = {}) ⇒ Object

Raises:

  • (ArgumentError)


11
12
13
14
15
16
17
18
19
20
21
# File 'lib/chargify_api_ares/resources/coupon.rb', line 11

def self.validate(params = {})
  product_family_id = params.fetch(:product_family_id, nil)
  coupon_code = params.fetch(:coupon_code, nil)

  raise ArgumentError, 'coupon_code is a required argument' if coupon_code.blank?

  params = {:coupon_code => coupon_code}
  params.merge!(:product_family_id => product_family_id) if product_family_id.present?

  find :one, :from => :validate, :params => params
end

Instance Method Details

#archiveObject



27
28
29
# File 'lib/chargify_api_ares/resources/coupon.rb', line 27

def archive
  self.destroy
end

#usageObject



23
24
25
# File 'lib/chargify_api_ares/resources/coupon.rb', line 23

def usage
  get :usage
end