Class: Upay::Customer
- Inherits:
-
Object
- Object
- Upay::Customer
- Defined in:
- lib/upay/customer.rb
Instance Method Summary collapse
-
#all ⇒ Object
Verb: GET Description: Returns: JSON.
-
#create ⇒ Object
Verb: POST Description: Returns: JSON.
- #creditCards ⇒ Object
- #creditCards=(creditCards = {}) ⇒ Object
- #customerId ⇒ Object
- #customerId=(customerId) ⇒ Object
-
#delete ⇒ Object
Verb: DELETE Description: Returns: JSON.
- #email ⇒ Object
- #email=(email) ⇒ Object
- #fullName ⇒ Object
- #fullName=(fullName) ⇒ Object
- #has_subscription?(planCode) ⇒ Boolean
- #has_subscriptions? ⇒ Boolean
- #id ⇒ Object
- #id=(id) ⇒ Object
-
#initialize(args = {}) ⇒ Customer
constructor
A new instance of Customer.
- #reload(args = {}) ⇒ Object
-
#show ⇒ Object
Verb: GET Description: Returns: JSON.
-
#subscription ⇒ Object
Subscriptions Thingys.
- #subscription=(subscription) ⇒ Object
- #to_hash ⇒ Object
-
#update ⇒ Object
Verb: UPDATE Description: Returns: JSON.
- #valid? ⇒ Boolean
Constructor Details
#initialize(args = {}) ⇒ Customer
Returns a new instance of Customer.
4 5 6 |
# File 'lib/upay/customer.rb', line 4 def initialize(args = {}) reload(args) end |
Instance Method Details
#all ⇒ Object
Verb: GET Description: Returns: JSON
94 95 96 97 98 99 100 101 102 |
# File 'lib/upay/customer.rb', line 94 def all url = "rest/v4.3/customers/" customers = [] list_of_customers = Requestor.new.get(url, {}) if list_of_customers["customerList"] && list_of_customers["customerList"].count > 0 customers = list_of_customers["customerList"].map{|x| Customer.new(x) } end customers end |
#create ⇒ Object
Verb: POST Description: Returns: JSON
58 59 60 61 62 63 64 65 |
# File 'lib/upay/customer.rb', line 58 def create url = "rest/v4.3/customers" hash_for_create = self.to_hash response = Requestor.new.post(url, {:fullName => self.fullName, :email => self.email}) self.customerId = response["id"] self.id = response["id"] self end |
#creditCards ⇒ Object
47 |
# File 'lib/upay/customer.rb', line 47 def creditCards; @creditCards end |
#creditCards=(creditCards = {}) ⇒ Object
48 |
# File 'lib/upay/customer.rb', line 48 def creditCards=(creditCards = {}) @creditCards = creditCards end |
#customerId ⇒ Object
37 |
# File 'lib/upay/customer.rb', line 37 def customerId; @customerId end |
#customerId=(customerId) ⇒ Object
38 39 40 |
# File 'lib/upay/customer.rb', line 38 def customerId=(customerId) @customerId = customerId end |
#delete ⇒ Object
Verb: DELETE Description: Returns: JSON
107 108 109 110 |
# File 'lib/upay/customer.rb', line 107 def delete url = "rest/v4.3/customers/#{self.customerId}" Requestor.new.delete(url, {}) end |
#email ⇒ Object
27 |
# File 'lib/upay/customer.rb', line 27 def email; @email end |
#email=(email) ⇒ Object
28 29 30 |
# File 'lib/upay/customer.rb', line 28 def email=(email) @email = email end |
#fullName ⇒ Object
22 |
# File 'lib/upay/customer.rb', line 22 def fullName; @fullName end |
#fullName=(fullName) ⇒ Object
23 24 25 |
# File 'lib/upay/customer.rb', line 23 def fullName=(fullName) @fullName = fullName end |
#has_subscription?(planCode) ⇒ Boolean
124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/upay/customer.rb', line 124 def has_subscription?(planCode) response = self.show it_has = false unless response["subscriptions"].blank? response["subscriptions"].each do |subscription| if subscription["plan"]["planCode"] == planCode it_has = true end end end it_has end |
#has_subscriptions? ⇒ Boolean
137 138 139 140 141 142 143 144 |
# File 'lib/upay/customer.rb', line 137 def has_subscriptions? response = self.show unless response["subscriptions"].blank? response["subscriptions"].count > 0 else false end end |
#id ⇒ Object
32 |
# File 'lib/upay/customer.rb', line 32 def id; @id end |
#id=(id) ⇒ Object
33 34 35 |
# File 'lib/upay/customer.rb', line 33 def id=(id) @id = id end |
#reload(args = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/upay/customer.rb', line 8 def reload(args = {}) args.each do |k,v| instance_variable_set("@#{k}", v) if k == "creditCards" ccs = [] v.each do |c| puts c ccs << CreditCard.new(c) end instance_variable_set("@#{k}", ccs) end end end |
#show ⇒ Object
Verb: GET Description: Returns: JSON
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/upay/customer.rb', line 78 def show begin unless self.customerId.nil? url = "rest/v4.3/customers/#{self.customerId}" response = Requestor.new.get(url, {}) self.reload(response) else raise "customerId cannot be blank" end end self end |
#subscription ⇒ Object
Subscriptions Thingys
114 |
# File 'lib/upay/customer.rb', line 114 def subscription; @subscription end |
#subscription=(subscription) ⇒ Object
43 44 45 |
# File 'lib/upay/customer.rb', line 43 def subscription=(subscription) @subscription = subscription end |
#to_hash ⇒ Object
146 147 148 149 150 151 152 |
# File 'lib/upay/customer.rb', line 146 def to_hash { :customerId => self.customerId || nil, :fullName => self.fullName, :email => self.email } end |
#update ⇒ Object
Verb: UPDATE Description: Returns: JSON
70 71 72 73 |
# File 'lib/upay/customer.rb', line 70 def update url = "rest/v4.3/customers/#{self.customerId}" Requestor.new.put(url, {:fullName => self.fullName, :email => self.email}) end |
#valid? ⇒ Boolean
50 51 52 53 |
# File 'lib/upay/customer.rb', line 50 def valid? validator = CustomerValidator.new validator.valid?(self) end |