Class: Mousetrap::Subscription

Inherits:
Resource
  • Object
show all
Defined in:
lib/mousetrap/subscription.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

#initialize, #new?

Constructor Details

This class inherits a constructor from Mousetrap::Resource

Instance Attribute Details

#billing_addressObject

Attributes we send to the API.



4
5
6
# File 'lib/mousetrap/subscription.rb', line 4

def billing_address
  @billing_address
end

#billing_cityObject

Attributes we send to the API.



4
5
6
# File 'lib/mousetrap/subscription.rb', line 4

def billing_city
  @billing_city
end

#billing_countryObject

Attributes we send to the API.



4
5
6
# File 'lib/mousetrap/subscription.rb', line 4

def billing_country
  @billing_country
end

#billing_dateObject

Attributes that come from the API.



4
5
6
# File 'lib/mousetrap/subscription.rb', line 4

def billing_date
  @billing_date
end

#billing_first_nameObject

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_nameObject

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_stateObject

Attributes we send to the API.



4
5
6
# File 'lib/mousetrap/subscription.rb', line 4

def billing_state
  @billing_state
end

#billing_zip_codeObject

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_atObject

Attributes that come from the API.



23
24
25
# File 'lib/mousetrap/subscription.rb', line 23

def canceled_at
  @canceled_at
end

#created_atObject

Attributes that come from the API.



23
24
25
# File 'lib/mousetrap/subscription.rb', line 23

def created_at
  @created_at
end

#credit_card_codeObject

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_dateObject

Attributes that come from the API.



23
24
25
# File 'lib/mousetrap/subscription.rb', line 23

def credit_card_expiration_date
  @credit_card_expiration_date
end

#credit_card_expiration_monthObject

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_yearObject

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_digitsObject

Attributes that come from the API.



23
24
25
# File 'lib/mousetrap/subscription.rb', line 23

def credit_card_last_four_digits
  @credit_card_last_four_digits
end

#credit_card_numberObject

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_typeObject

Attributes that come from the API.



23
24
25
# File 'lib/mousetrap/subscription.rb', line 23

def credit_card_type
  @credit_card_type
end

#customer_codeObject

Attributes we send to the API.



4
5
6
# File 'lib/mousetrap/subscription.rb', line 4

def customer_code
  @customer_code
end

#idObject

Attributes that come from the API.



23
24
25
# File 'lib/mousetrap/subscription.rb', line 23

def id
  @id
end

#invoicesObject

Attributes that come from the API.



23
24
25
# File 'lib/mousetrap/subscription.rb', line 23

def invoices
  @invoices
end

#itemsObject

Attributes that come from the API.



23
24
25
# File 'lib/mousetrap/subscription.rb', line 23

def items
  @items
end

#planObject

Attributes we send to the API.



4
5
6
# File 'lib/mousetrap/subscription.rb', line 4

def plan
  @plan
end

#plan_codeObject

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



34
35
36
# File 'lib/mousetrap/subscription.rb', line 34

def self.[](code)
  raise_api_unsupported_error
end

.allObject



38
39
40
# File 'lib/mousetrap/subscription.rb', line 38

def self.all
  raise_api_unsupported_error
end

.destroy_allObject



42
43
44
# File 'lib/mousetrap/subscription.rb', line 42

def self.destroy_all
  raise_api_unsupported_error
end

.exists?(code) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/mousetrap/subscription.rb', line 46

def self.exists?(code)
  raise_api_unsupported_error
end

.new_from_api(attributes) ⇒ Object



91
92
93
94
95
# File 'lib/mousetrap/subscription.rb', line 91

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



97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/mousetrap/subscription.rb', line 97

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

#attributesObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/mousetrap/subscription.rb', line 60

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,
    :billing_date                 => billing_date
  }
end

#attributes_for_apiObject



79
80
81
# File 'lib/mousetrap/subscription.rb', line 79

def attributes_for_api
  self.class.attributes_for_api(attributes)
end

#current_invoiceObject



50
51
52
53
54
55
56
57
58
# File 'lib/mousetrap/subscription.rb', line 50

def current_invoice
  invoice_attributes = if invoices['invoice'].kind_of?(Array)
    invoices['invoice'][0]
  else
    invoices['invoice']
  end

  Invoice.new(invoice_attributes)
end

#destroyObject



83
84
85
# File 'lib/mousetrap/subscription.rb', line 83

def destroy
  self.class.raise_api_unsupported_error
end

#exists?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/mousetrap/subscription.rb', line 87

def exists?
  self.class.raise_api_unsupported_error
end