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

#attributes, #errors, #unsaved_attributes

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

endpoint_url, #is_new?, object_base_uri, object_type, relative_url, url

Methods inherited from Object

#add_accessor, #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



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

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

#add_credits(quantity) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/iugu/subscription.rb', line 10

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

#change_plan(plan_identifier, options = {}) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/iugu/subscription.rb', line 56

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

#change_plan_simulation(plan_identifier, options = {}) ⇒ Object



69
70
71
72
73
74
75
# File 'lib/iugu/subscription.rb', line 69

def change_plan_simulation(plan_identifier, options = {})
  options[:plan_identifier] = plan_identifier
  Iugu::Factory.create_from_response(self.class.object_type,
                                     APIRequest.request("GET",
                                                        "#{self.class.url(id)}/change_plan_simulation",
                                                        options))
end

#customerObject



77
78
79
80
81
# File 'lib/iugu/subscription.rb', line 77

def customer
  return false unless @attributes["customer_id"]

  Customer.fetch @attributes["customer_id"]
end

#remove_credits(quantity) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/iugu/subscription.rb', line 22

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

#suspendObject



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

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