Class: Iugu::Api::Plan

Inherits:
IuguResource show all
Defined in:
lib/iugu-api/models/plan.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from IuguResource

#build_options, find, #to_json, #to_xml, #virtual_attributes

Class Method Details

.find_by_identifier(identifier) ⇒ Object



27
28
29
# File 'lib/iugu-api/models/plan.rb', line 27

def self.find_by_identifier(identifier)
  new.load(JSON.parse(connection.get( Plan.prefix + "plans/identifier/#{identifier}.json").body))
end

.with_currency(currency) ⇒ Object



23
24
25
# File 'lib/iugu-api/models/plan.rb', line 23

def self.with_currency(currency)
  self.find(:all, params: { currency: currency })
end

Instance Method Details

#features(scope = :all) ⇒ Object



6
7
8
# File 'lib/iugu-api/models/plan.rb', line 6

def features(scope = :all)
  Iugu::Api::PlanFeature.find(scope, :params => {:plan_id => self.id})
end

#price_by_currency(currency) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/iugu-api/models/plan.rb', line 14

def price_by_currency(currency)
  response = connection.get(Plan.prefix + "plans/identifier/#{self.identifier}/price/#{currency}")
  if response.body == 'null'
    raise ActiveResource::ResourceNotFound.new("Not Found")
  else
    Iugu::Api::PlanPrice.new.load(JSON.parse(response.body))
  end
end

#prices(scope = :all) ⇒ Object



10
11
12
# File 'lib/iugu-api/models/plan.rb', line 10

def prices(scope = :all)
  Iugu::Api::PlanPrice.find(scope, :params => {:plan_id => self.id})
end