Class: Moip::Subscription
- Includes:
- HTTParty, Header
- Defined in:
- lib/moip/models/subscription.rb
Instance Attribute Summary collapse
-
#amount ⇒ Object
Returns the value of attribute amount.
-
#code ⇒ Object
Returns the value of attribute code.
-
#creation_date ⇒ Object
Returns the value of attribute creation_date.
-
#customer ⇒ Object
Returns the value of attribute customer.
-
#expiration_date ⇒ Object
Returns the value of attribute expiration_date.
-
#invoice ⇒ Object
Returns the value of attribute invoice.
-
#message ⇒ Object
Returns the value of attribute message.
-
#next_invoice_date ⇒ Object
Returns the value of attribute next_invoice_date.
-
#plan ⇒ Object
Returns the value of attribute plan.
-
#status ⇒ Object
Returns the value of attribute status.
-
#subscriptions ⇒ Object
Returns the value of attribute subscriptions.
Instance Method Summary collapse
- #activate ⇒ Object
- #active? ⇒ Boolean
- #attributes ⇒ Object
- #cancel ⇒ Object
- #create ⇒ Object
-
#create_with_costumer ⇒ Object
To Do.
- #find(code) ⇒ Object
- #invoices ⇒ Object
- #load ⇒ Object
- #suspend ⇒ Object
- #update_amount(plan, new_amount) ⇒ Object
- #update_next_invoice(plan, next_invoice_date) ⇒ Object
- #update_plan(new_plan) ⇒ Object
Methods included from Header
#auth, #base_url, #default_header
Methods inherited from Model
build, #set_parameters, #to_json, #validate_response
Instance Attribute Details
#amount ⇒ Object
Returns the value of attribute amount.
6 7 8 |
# File 'lib/moip/models/subscription.rb', line 6 def amount @amount end |
#code ⇒ Object
Returns the value of attribute code.
6 7 8 |
# File 'lib/moip/models/subscription.rb', line 6 def code @code end |
#creation_date ⇒ Object
Returns the value of attribute creation_date.
6 7 8 |
# File 'lib/moip/models/subscription.rb', line 6 def creation_date @creation_date end |
#customer ⇒ Object
Returns the value of attribute customer.
6 7 8 |
# File 'lib/moip/models/subscription.rb', line 6 def customer @customer end |
#expiration_date ⇒ Object
Returns the value of attribute expiration_date.
6 7 8 |
# File 'lib/moip/models/subscription.rb', line 6 def expiration_date @expiration_date end |
#invoice ⇒ Object
Returns the value of attribute invoice.
6 7 8 |
# File 'lib/moip/models/subscription.rb', line 6 def invoice @invoice end |
#message ⇒ Object
Returns the value of attribute message.
6 7 8 |
# File 'lib/moip/models/subscription.rb', line 6 def @message end |
#next_invoice_date ⇒ Object
Returns the value of attribute next_invoice_date.
6 7 8 |
# File 'lib/moip/models/subscription.rb', line 6 def next_invoice_date @next_invoice_date end |
#plan ⇒ Object
Returns the value of attribute plan.
6 7 8 |
# File 'lib/moip/models/subscription.rb', line 6 def plan @plan end |
#status ⇒ Object
Returns the value of attribute status.
6 7 8 |
# File 'lib/moip/models/subscription.rb', line 6 def status @status end |
#subscriptions ⇒ Object
Returns the value of attribute subscriptions.
6 7 8 |
# File 'lib/moip/models/subscription.rb', line 6 def subscriptions @subscriptions end |
Instance Method Details
#activate ⇒ Object
96 97 98 |
# File 'lib/moip/models/subscription.rb', line 96 def activate self.class.put(base_url(:subscriptions, :code => self.code, :status => "activate"), default_header({}.to_json)).parsed_response end |
#active? ⇒ Boolean
22 23 24 |
# File 'lib/moip/models/subscription.rb', line 22 def active? self.satus == "ACTIVE" end |
#attributes ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/moip/models/subscription.rb', line 13 def attributes { "code" => code, "amount" => amount, "plan" => plan, "customer" => customer } end |
#cancel ⇒ Object
100 101 102 |
# File 'lib/moip/models/subscription.rb', line 100 def cancel self.class.put(base_url(:subscriptions, :code => self.code, :status => "cancel"), default_header({}.to_json)).parsed_response end |
#create ⇒ Object
71 72 73 74 75 76 77 78 |
# File 'lib/moip/models/subscription.rb', line 71 def create if self.valid? response = self.class.post(base_url(:subscriptions), default_header(self.to_json)).parsed_response self.validate_response response else false end end |
#create_with_costumer ⇒ Object
To Do
81 82 83 84 |
# File 'lib/moip/models/subscription.rb', line 81 def create_with_costumer # To Do: will not be developed this feature right now, if you # want to fork and develop this feature, be welcome. end |
#find(code) ⇒ Object
87 88 89 90 |
# File 'lib/moip/models/subscription.rb', line 87 def find code response = self.class.get(base_url(:subscriptions, :code => code), default_header).parsed_response self.set_parameters response unless response.nil? end |
#invoices ⇒ Object
60 61 62 |
# File 'lib/moip/models/subscription.rb', line 60 def invoices @invoices ||= Moip::Invoice.build(:subscription_code => self.code).invoices end |
#load ⇒ Object
65 66 67 68 |
# File 'lib/moip/models/subscription.rb', line 65 def load list = self.class.get(base_url(:subscriptions), default_header).parsed_response self.subscriptions = list["subscriptions"] end |
#suspend ⇒ Object
92 93 94 |
# File 'lib/moip/models/subscription.rb', line 92 def suspend self.class.put(base_url(:subscriptions, :code => self.code, :status => "suspend"), default_header({}.to_json)).parsed_response end |
#update_amount(plan, new_amount) ⇒ Object
121 122 123 124 125 126 127 128 129 130 |
# File 'lib/moip/models/subscription.rb', line 121 def update_amount plan, new_amount hash = {} self.find self.code hash[:plan] = { :code => plan } hash[:amount] = new_amount self.class.put(base_url(:subscriptions, :code => self.code), default_header(hash.to_json)).parsed_response end |
#update_next_invoice(plan, next_invoice_date) ⇒ Object
113 114 115 116 117 118 119 |
# File 'lib/moip/models/subscription.rb', line 113 def update_next_invoice plan, next_invoice_date hash = {} hash[:plan] = { :code => plan } hash[:next_invoice_date] = next_invoice_date self.class.put(base_url(:subscriptions, :code => self.code), default_header(hash.to_json)).parsed_response end |
#update_plan(new_plan) ⇒ Object
105 106 107 108 109 110 |
# File 'lib/moip/models/subscription.rb', line 105 def update_plan new_plan hash = {} hash[:plan] = { :code => new_plan } self.class.put(base_url(:subscriptions, :code => self.code), default_header(hash.to_json)).parsed_response end |