Class: Iugu::Subscription

Inherits:
APIResource show all
Includes:
APICreate, APIDelete, APIFetch, APISave
Defined in:
lib/iugu/subscription.rb

Instance Attribute Summary

Attributes inherited from Object

#errors

Instance Method Summary collapse

Methods included from APIDelete

#delete

Methods included from APISave

#save

Methods included from APICreate

included

Methods included from APIFetch

included, #refresh

Methods inherited from APIResource

#is_new?, url

Methods inherited from Object

#add_accessor, #attributes, #copy, #initialize, #method_missing, #modified_attributes, #set_attributes

Constructor Details

This class inherits a constructor from Iugu::Object

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Iugu::Object

Instance Method Details

#activateObject



35
36
37
38
39
40
41
42
# File 'lib/iugu/subscription.rb', line 35

def activate
  copy Iugu::Factory.create_from_response(self.class.object_type, APIRequest.request("POST", "#{self.class.url(self.id)}/activate"))
  self.errors = nil
  true
rescue Iugu::RequestWithErrors => ex
  self.errors = ex.errors
  false
end

#add_credits(quantity) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/iugu/subscription.rb', line 8

def add_credits(quantity)
  copy Iugu::Factory.create_from_response(self.class.object_type, APIRequest.request("PUT", "#{self.class.url(self.id)}/add_credits", { quantity: quantity }))
  self.errors = nil
  true
rescue Iugu::RequestWithErrors => ex
  self.errors = ex.errors
  false
end

#change_plan(plan_identifier) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/iugu/subscription.rb', line 44

def change_plan(plan_identifier)
  copy Iugu::Factory.create_from_response(self.class.object_type, APIRequest.request("POST", "#{self.class.url(self.id)}/change_plan/#{plan_identifier}"))
  self.errors = nil
  true
rescue Iugu::RequestWithErrors => ex
  self.errors = ex.errors
  false
end

#customerObject



53
54
55
56
# File 'lib/iugu/subscription.rb', line 53

def customer
  return false unless @attributes['customer_id']
  Customer.fetch @attributes['customer_id']
end

#remove_credits(quantity) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/iugu/subscription.rb', line 17

def remove_credits(quantity)
  copy Iugu::Factory.create_from_response(self.class.object_type, APIRequest.request("PUT", "#{self.class.url(self.id)}/remove_credits", { quantity: quantity }))
  self.errors = nil
  true
rescue Iugu::RequestWithErrors => ex
  self.errors = ex.errors
  false
end

#suspendObject



26
27
28
29
30
31
32
33
# File 'lib/iugu/subscription.rb', line 26

def suspend
  copy Iugu::Factory.create_from_response(self.class.object_type, APIRequest.request("POST", "#{self.class.url(self.id)}/suspend"))
  self.errors = nil
  true
rescue Iugu::RequestWithErrors => ex
  self.errors = ex.errors
  false
end