Class: Mousetrap::Subscription
- Defined in:
- lib/mousetrap/subscription.rb
Instance Attribute Summary collapse
-
#billing_address ⇒ Object
Attributes we send to the API.
-
#billing_city ⇒ Object
Attributes we send to the API.
-
#billing_country ⇒ Object
Attributes we send to the API.
-
#billing_first_name ⇒ Object
Attributes we send to the API.
-
#billing_last_name ⇒ Object
Attributes we send to the API.
-
#billing_state ⇒ Object
Attributes we send to the API.
-
#billing_zip_code ⇒ Object
Attributes we send to the API.
-
#canceled_at ⇒ Object
readonly
Attributes that come from the API.
-
#created_at ⇒ Object
readonly
Attributes that come from the API.
-
#credit_card_code ⇒ Object
Attributes we send to the API.
-
#credit_card_expiration_date ⇒ Object
readonly
Attributes that come from the API.
-
#credit_card_expiration_month ⇒ Object
Attributes we send to the API.
-
#credit_card_expiration_year ⇒ Object
Attributes we send to the API.
-
#credit_card_last_four_digits ⇒ Object
readonly
Attributes that come from the API.
-
#credit_card_number ⇒ Object
Attributes we send to the API.
-
#credit_card_type ⇒ Object
readonly
Attributes that come from the API.
-
#customer_code ⇒ Object
Attributes we send to the API.
-
#id ⇒ Object
readonly
Attributes that come from the API.
-
#invoices ⇒ Object
readonly
Attributes that come from the API.
-
#items ⇒ Object
readonly
Attributes that come from the API.
-
#plan ⇒ Object
Attributes we send to the API.
-
#plan_code ⇒ Object
Attributes we send to the API.
Class Method Summary collapse
- .[](code) ⇒ Object
- .all ⇒ Object
- .destroy_all ⇒ Object
- .exists?(code) ⇒ Boolean
- .new_from_api(attributes) ⇒ Object
- .update(customer_code, attributes) ⇒ Object
Instance Method Summary collapse
- #attributes ⇒ Object
- #attributes_for_api ⇒ Object
- #current_invoice ⇒ Object
- #destroy ⇒ Object
- #exists? ⇒ Boolean
Methods inherited from Resource
Constructor Details
This class inherits a constructor from Mousetrap::Resource
Instance Attribute Details
#billing_address ⇒ Object
Attributes we send to the API.
4 5 6 |
# File 'lib/mousetrap/subscription.rb', line 4 def billing_address @billing_address end |
#billing_city ⇒ Object
Attributes we send to the API.
4 5 6 |
# File 'lib/mousetrap/subscription.rb', line 4 def billing_city @billing_city end |
#billing_country ⇒ Object
Attributes we send to the API.
4 5 6 |
# File 'lib/mousetrap/subscription.rb', line 4 def billing_country @billing_country end |
#billing_first_name ⇒ Object
Attributes we send to the API.
4 5 6 |
# File 'lib/mousetrap/subscription.rb', line 4 def billing_first_name @billing_first_name end |
#billing_last_name ⇒ Object
Attributes we send to the API.
4 5 6 |
# File 'lib/mousetrap/subscription.rb', line 4 def billing_last_name @billing_last_name end |
#billing_state ⇒ Object
Attributes we send to the API.
4 5 6 |
# File 'lib/mousetrap/subscription.rb', line 4 def billing_state @billing_state end |
#billing_zip_code ⇒ Object
Attributes we send to the API.
4 5 6 |
# File 'lib/mousetrap/subscription.rb', line 4 def billing_zip_code @billing_zip_code end |
#canceled_at ⇒ Object
Attributes that come from the API.
22 23 24 |
# File 'lib/mousetrap/subscription.rb', line 22 def canceled_at @canceled_at end |
#created_at ⇒ Object
Attributes that come from the API.
22 23 24 |
# File 'lib/mousetrap/subscription.rb', line 22 def created_at @created_at end |
#credit_card_code ⇒ Object
Attributes we send to the API.
4 5 6 |
# File 'lib/mousetrap/subscription.rb', line 4 def credit_card_code @credit_card_code end |
#credit_card_expiration_date ⇒ Object
Attributes that come from the API.
22 23 24 |
# File 'lib/mousetrap/subscription.rb', line 22 def credit_card_expiration_date @credit_card_expiration_date end |
#credit_card_expiration_month ⇒ Object
Attributes we send to the API.
4 5 6 |
# File 'lib/mousetrap/subscription.rb', line 4 def credit_card_expiration_month @credit_card_expiration_month end |
#credit_card_expiration_year ⇒ Object
Attributes we send to the API.
4 5 6 |
# File 'lib/mousetrap/subscription.rb', line 4 def credit_card_expiration_year @credit_card_expiration_year end |
#credit_card_last_four_digits ⇒ Object
Attributes that come from the API.
22 23 24 |
# File 'lib/mousetrap/subscription.rb', line 22 def credit_card_last_four_digits @credit_card_last_four_digits end |
#credit_card_number ⇒ Object
Attributes we send to the API.
4 5 6 |
# File 'lib/mousetrap/subscription.rb', line 4 def credit_card_number @credit_card_number end |
#credit_card_type ⇒ Object
Attributes that come from the API.
22 23 24 |
# File 'lib/mousetrap/subscription.rb', line 22 def credit_card_type @credit_card_type end |
#customer_code ⇒ Object
Attributes we send to the API.
4 5 6 |
# File 'lib/mousetrap/subscription.rb', line 4 def customer_code @customer_code end |
#id ⇒ Object
Attributes that come from the API.
22 23 24 |
# File 'lib/mousetrap/subscription.rb', line 22 def id @id end |
#invoices ⇒ Object
Attributes that come from the API.
22 23 24 |
# File 'lib/mousetrap/subscription.rb', line 22 def invoices @invoices end |
#items ⇒ Object
Attributes that come from the API.
22 23 24 |
# File 'lib/mousetrap/subscription.rb', line 22 def items @items end |
#plan ⇒ Object
Attributes we send to the API.
4 5 6 |
# File 'lib/mousetrap/subscription.rb', line 4 def plan @plan end |
#plan_code ⇒ Object
Attributes we send to the API.
4 5 6 |
# File 'lib/mousetrap/subscription.rb', line 4 def plan_code @plan_code end |
Class Method Details
.[](code) ⇒ Object
32 33 34 |
# File 'lib/mousetrap/subscription.rb', line 32 def self.[](code) raise_api_unsupported_error end |
.all ⇒ Object
36 37 38 |
# File 'lib/mousetrap/subscription.rb', line 36 def self.all raise_api_unsupported_error end |
.destroy_all ⇒ Object
40 41 42 |
# File 'lib/mousetrap/subscription.rb', line 40 def self.destroy_all raise_api_unsupported_error end |
.exists?(code) ⇒ Boolean
44 45 46 |
# File 'lib/mousetrap/subscription.rb', line 44 def self.exists?(code) raise_api_unsupported_error end |
.new_from_api(attributes) ⇒ Object
88 89 90 91 92 |
# File 'lib/mousetrap/subscription.rb', line 88 def self.new_from_api(attributes) subscription = new(attributes_from_api(attributes)) subscription.plan = Plan.new_from_api(attributes['plans']['plan']) subscription end |
.update(customer_code, attributes) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/mousetrap/subscription.rb', line 94 def self.update(customer_code, attributes) mutated_attributes = attributes_for_api(attributes) mutated_attributes.delete_if { |k, v| v.blank? } response = put_resource( 'customers', 'edit-subscription', customer_code, mutated_attributes ) raise response['error'] if response['error'] end |
Instance Method Details
#attributes ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/mousetrap/subscription.rb', line 58 def attributes { :id => id, :plan_code => plan_code, :billing_first_name => billing_first_name, :billing_last_name => billing_last_name, :credit_card_number => credit_card_number, :credit_card_expiration_month => credit_card_expiration_month, :credit_card_expiration_year => credit_card_expiration_year, :credit_card_code => credit_card_code, :billing_country => billing_country, :billing_address => billing_address, :billing_city => billing_city, :billing_state => billing_state, :billing_zip_code => billing_zip_code, } end |
#attributes_for_api ⇒ Object
76 77 78 |
# File 'lib/mousetrap/subscription.rb', line 76 def attributes_for_api self.class.attributes_for_api(attributes) end |
#current_invoice ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/mousetrap/subscription.rb', line 48 def current_invoice invoice_attributes = if invoices['invoice'].kind_of?(Array) invoices['invoice'][0] else invoices['invoice'] end Invoice.new(invoice_attributes) end |
#destroy ⇒ Object
80 81 82 |
# File 'lib/mousetrap/subscription.rb', line 80 def destroy self.class.raise_api_unsupported_error end |
#exists? ⇒ Boolean
84 85 86 |
# File 'lib/mousetrap/subscription.rb', line 84 def exists? self.class.raise_api_unsupported_error end |