Class: Spreedly::SubscriptionPlan

Inherits:
Resource
  • Object
show all
Defined in:
lib/spreedly.rb,
lib/spreedly/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::Resource

Dynamic Method Handling

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

Class Method Details

+ (Object) all

Returns all of the subscription plans defined in your site.



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

def self.all
  xml = Spreedly.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

+ (Object) find(id)

Returns the subscription plan with the given id.



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

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

+ (Object) plans



190
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
# File 'lib/spreedly/mock.rb', line 190

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

- (Boolean) trial?

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

Returns:

  • (Boolean)


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

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