Class: FastSpring::Subscription
- Inherits:
-
PrivateApiBase
- Object
- PrivateApiBase
- FastSpring::Subscription
- Defined in:
- lib/fastspring-saasy/subscription.rb
Instance Attribute Summary
Attributes inherited from PrivateApiBase
Class Method Summary collapse
Instance Method Summary collapse
-
#active? ⇒ Boolean
Is the subscription active?.
-
#base_subscription_path ⇒ Object
Returns the base path for a subscription.
-
#cancelable? ⇒ Boolean
Can the subscription be cancelled?.
- #customer_url ⇒ Object
-
#destroy ⇒ Object
(also: #cancel!)
Cancel the subscription.
-
#ends_on ⇒ Object
The date the subscription ends on.
-
#find ⇒ Object
Get the subscription from Saasy.
- #next_period_date ⇒ Object
-
#product_name ⇒ Object
Subscription product name.
- #quantity ⇒ Object
-
#renew ⇒ Object
Renew the subscription.
- #renew_path ⇒ Object
-
#status_reason ⇒ Object
The reason for a status change.
- #tags ⇒ Object
-
#update!(options = {}) ⇒ Object
Update the subscription from Saasy.
Methods inherited from PrivateApiBase
find, #initialize, #reference, #referrer, #search, search, #source_campaign, #source_key, #source_name, #status, #status_changed
Constructor Details
This class inherits a constructor from FastSpring::PrivateApiBase
Class Method Details
.create_subscription_url(reference, referrer) ⇒ Object
6 7 8 |
# File 'lib/fastspring-saasy/subscription.rb', line 6 def self.create_subscription_url(reference, referrer) "#{SITE_URL}/#{FastSpring::Account.fetch(:company)}/product/#{reference}?referrer=#{referrer}" end |
Instance Method Details
#active? ⇒ Boolean
Is the subscription active?
33 34 35 |
# File 'lib/fastspring-saasy/subscription.rb', line 33 def active? status == 'active' end |
#base_subscription_path ⇒ Object
Returns the base path for a subscription
23 24 25 |
# File 'lib/fastspring-saasy/subscription.rb', line 23 def base_subscription_path "/company/#{@company}/subscription/#{@reference}" end |
#cancelable? ⇒ Boolean
Can the subscription be cancelled?
38 39 40 |
# File 'lib/fastspring-saasy/subscription.rb', line 38 def cancelable? value_for('cancelable') == 'true' end |
#customer_url ⇒ Object
74 75 76 |
# File 'lib/fastspring-saasy/subscription.rb', line 74 def customer_url value_for('customerUrl') end |
#destroy ⇒ Object Also known as: cancel!
Cancel the subscription
79 80 81 |
# File 'lib/fastspring-saasy/subscription.rb', line 79 def destroy self.class.delete(base_subscription_path, :basic_auth => @auth) end |
#ends_on ⇒ Object
The date the subscription ends on
52 53 54 |
# File 'lib/fastspring-saasy/subscription.rb', line 52 def ends_on Date.parse(value_for('end')) end |
#find ⇒ Object
Get the subscription from Saasy
11 12 13 14 |
# File 'lib/fastspring-saasy/subscription.rb', line 11 def find @response = self.class.get(base_subscription_path, :basic_auth => @auth, :ssl_ca_file => @ssl_ca_file) self end |
#next_period_date ⇒ Object
47 48 49 |
# File 'lib/fastspring-saasy/subscription.rb', line 47 def next_period_date Date.parse(value_for('nextPeriodDate')) end |
#product_name ⇒ Object
Subscription product name
43 44 45 |
# File 'lib/fastspring-saasy/subscription.rb', line 43 def product_name value_for('productName') end |
#quantity ⇒ Object
56 57 58 |
# File 'lib/fastspring-saasy/subscription.rb', line 56 def quantity value_for('quantity').to_i end |
#renew ⇒ Object
Renew the subscription
89 90 91 |
# File 'lib/fastspring-saasy/subscription.rb', line 89 def renew self.class.post(renew_path, :basic_auth => @auth) end |
#renew_path ⇒ Object
84 85 86 |
# File 'lib/fastspring-saasy/subscription.rb', line 84 def renew_path "#{base_subscription_path}/renew" end |
#status_reason ⇒ Object
The reason for a status change
28 29 30 |
# File 'lib/fastspring-saasy/subscription.rb', line 28 def status_reason value_for('statusReason') end |
#tags ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/fastspring-saasy/subscription.rb', line 60 def begin = value_for('tags') result = {} .split(",").each do |t| k,v = t.strip.split('=') result[k.to_sym] = v end result rescue nil end end |
#update!(options = {}) ⇒ Object
Update the subscription from Saasy
17 18 19 20 |
# File 'lib/fastspring-saasy/subscription.rb', line 17 def update!(={}) @response = self.class.put(base_subscription_path, :body => Gyoku.xml(subscription: ), :headers => {'Content-Type' => 'application/xml'},:basic_auth => @auth) self end |