Class: Spreedly::Subscriptions::SubscriptionPlan

Inherits:
Resource
  • Object
show all
Defined in:
lib/spreedly/subscriptions.rb,
lib/spreedly/subscriptions/mock.rb

Instance Attribute Summary

Attributes inherited from Resource

#attributes

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

attributes, attributes=, #id, #initialize, #method_missing

Constructor Details

This class inherits a constructor from Spreedly::Subscriptions::Resource

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Spreedly::Subscriptions::Resource

Class Method Details

.allObject

Returns all of the subscription plans defined in your site.



268
269
270
271
272
273
274
275
# File 'lib/spreedly/subscriptions.rb', line 268

def self.all
  xml = Spreedly::Subscriptions.get('/subscription_plans.xml')
  if xml.code == 200
    xml['subscription_plans'].collect{|data| new(data)}
  else
    raise "Could not list subscription plans: result code #{xml.code}, body '#{xml.body}'"
  end
end

.find(id) ⇒ Object

Returns the subscription plan with the given id.



278
279
280
# File 'lib/spreedly/subscriptions.rb', line 278

def self.find(id)
  all.detect{|e| e.id.to_s == id.to_s}
end

.plansObject



191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/spreedly/subscriptions/mock.rb', line 191

def self.plans
  @plans ||= {
    1 => new(
      :id => 1,
      :name => 'Default mock plan',
      :duration_quantity => 1,
      :duration_units => 'days',
      :amount => 6
    ),
      2 => new(
        :id => 2,
        :name => 'Test Free Trial Plan',
        :plan_type => 'free_trial',
        :duration_quantity => 1,
        :duration_units => 'days',
        :amount => 11
    ),
      3 => new(
        :id => 3,
        :name => 'Test Regular Plan',
        :duration_quantity => 1,
        :duration_units => 'days',
        :amount => 17
    )
  }
end

Instance Method Details

#trial?Boolean

Convenience method for determining if this plan is a free trial plan or not.

Returns:

  • (Boolean)


283
284
285
# File 'lib/spreedly/subscriptions.rb', line 283

def trial?
  (plan_type == 'free_trial')
end