Class: Mousetrap::Customer
- Defined in:
- lib/mousetrap/customer.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
Returns the value of attribute code.
-
#email ⇒ Object
Returns the value of attribute email.
-
#first_name ⇒ Object
Returns the value of attribute first_name.
-
#id ⇒ Object
Returns the value of attribute id.
-
#last_name ⇒ Object
Returns the value of attribute last_name.
-
#subscription ⇒ Object
Returns the value of attribute subscription.
Class Method Summary collapse
Instance Method Summary collapse
- #attributes ⇒ Object
- #attributes_for_api ⇒ Object
- #cancel ⇒ Object
- #save ⇒ Object
- #subscription_attributes=(attributes) ⇒ Object
Methods inherited from Resource
[], delete, #destroy, destroy_all, exists?, #exists?, #initialize, #new?
Constructor Details
This class inherits a constructor from Mousetrap::Resource
Instance Attribute Details
#code ⇒ Object
Returns the value of attribute code.
3 4 5 |
# File 'lib/mousetrap/customer.rb', line 3 def code @code end |
#email ⇒ Object
Returns the value of attribute email.
3 4 5 |
# File 'lib/mousetrap/customer.rb', line 3 def email @email end |
#first_name ⇒ Object
Returns the value of attribute first_name.
3 4 5 |
# File 'lib/mousetrap/customer.rb', line 3 def first_name @first_name end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/mousetrap/customer.rb', line 3 def id @id end |
#last_name ⇒ Object
Returns the value of attribute last_name.
3 4 5 |
# File 'lib/mousetrap/customer.rb', line 3 def last_name @last_name end |
#subscription ⇒ Object
Returns the value of attribute subscription.
3 4 5 |
# File 'lib/mousetrap/customer.rb', line 3 def subscription @subscription end |
Class Method Details
.all ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/mousetrap/customer.rb', line 43 def self.all response = get_resources plural_resource_name if response['error'] if response['error'] == "Bad request: No customers found." return [] else raise response['error'] end end build_resources_from response end |
.create(attributes) ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/mousetrap/customer.rb', line 57 def self.create(attributes) object = new(attributes) response = object.save returned_customer = build_resource_from response object.id = returned_customer.id # TODO: what other attrs to copy over? object end |
.new_from_api(attributes) ⇒ Object
66 67 68 69 70 71 |
# File 'lib/mousetrap/customer.rb', line 66 def self.new_from_api(attributes) customer = new(attributes_from_api(attributes)) customer.subscription = Subscription.new_from_api( attributes['subscriptions']['subscription']) customer end |
Instance Method Details
#attributes ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/mousetrap/customer.rb', line 15 def attributes { :id => id, :code => code, :email => email, :first_name => first_name, :last_name => last_name, } end |
#attributes_for_api ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/mousetrap/customer.rb', line 25 def attributes_for_api a = self.class.attributes_for_api(attributes, new_record?) if subscription a[:subscription] = subscription.attributes_for_api end a end |
#cancel ⇒ Object
35 36 37 |
# File 'lib/mousetrap/customer.rb', line 35 def cancel member_action 'cancel' unless new_record? end |
#save ⇒ Object
39 40 41 |
# File 'lib/mousetrap/customer.rb', line 39 def save new? ? create : update end |
#subscription_attributes=(attributes) ⇒ Object
11 12 13 |
# File 'lib/mousetrap/customer.rb', line 11 def subscription_attributes=(attributes) self.subscription = Subscription.new attributes end |