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.
Methods inherited from PrivateApiBase
find, #initialize, #reference, #referrer, #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
5 6 7 |
# File 'lib/fastspring-saasy/subscription.rb', line 5 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?
25 26 27 |
# File 'lib/fastspring-saasy/subscription.rb', line 25 def active? status == 'active' end |
#base_subscription_path ⇒ Object
Returns the base path for a subscription
15 16 17 |
# File 'lib/fastspring-saasy/subscription.rb', line 15 def base_subscription_path "/company/#{@company}/subscription/#{@reference}" end |
#cancelable? ⇒ Boolean
Can the subscription be cancelled?
30 31 32 |
# File 'lib/fastspring-saasy/subscription.rb', line 30 def cancelable? value_for('cancelable') == 'true' end |
#customer_url ⇒ Object
52 53 54 |
# File 'lib/fastspring-saasy/subscription.rb', line 52 def customer_url value_for('customerUrl') end |
#destroy ⇒ Object Also known as: cancel!
Cancel the subscription
57 58 59 |
# File 'lib/fastspring-saasy/subscription.rb', line 57 def destroy self.class.delete(base_subscription_path, :basic_auth => @auth) end |
#ends_on ⇒ Object
The date the subscription ends on
44 45 46 |
# File 'lib/fastspring-saasy/subscription.rb', line 44 def ends_on Date.parse(value_for('end')) end |
#find ⇒ Object
Get the subscription from Saasy
9 10 11 12 |
# File 'lib/fastspring-saasy/subscription.rb', line 9 def find @response = self.class.get(base_subscription_path, :basic_auth => @auth, :ssl_ca_file => @ssl_ca_file) self end |
#next_period_date ⇒ Object
39 40 41 |
# File 'lib/fastspring-saasy/subscription.rb', line 39 def next_period_date Date.parse(value_for('nextPeriodDate')) end |
#product_name ⇒ Object
Subscription product name
35 36 37 |
# File 'lib/fastspring-saasy/subscription.rb', line 35 def product_name value_for('productName') end |
#quantity ⇒ Object
48 49 50 |
# File 'lib/fastspring-saasy/subscription.rb', line 48 def quantity value_for('quantity').to_i end |
#renew ⇒ Object
Renew the subscription
67 68 69 |
# File 'lib/fastspring-saasy/subscription.rb', line 67 def renew self.class.post(renew_path, :basic_auth => @auth) end |
#renew_path ⇒ Object
62 63 64 |
# File 'lib/fastspring-saasy/subscription.rb', line 62 def renew_path "#{base_subscription_path}/renew" end |
#status_reason ⇒ Object
The reason for a status change
20 21 22 |
# File 'lib/fastspring-saasy/subscription.rb', line 20 def status_reason value_for('statusReason') end |