class Upay::Customer
Public Class Methods
new(args = {})
click to toggle source
# File lib/upay/customer.rb, line 4 def initialize(args = {}) reload(args) end
Public Instance Methods
all()
click to toggle source
Verb: GET Description: Returns: JSON
# 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()
click to toggle source
Verb: POST Description: Returns: JSON
# 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()
click to toggle source
# File lib/upay/customer.rb, line 47 def creditCards; @creditCards end
creditCards=(creditCards = {})
click to toggle source
# File lib/upay/customer.rb, line 48 def creditCards=(creditCards = {}) @creditCards = creditCards end
customerId()
click to toggle source
# File lib/upay/customer.rb, line 37 def customerId; @customerId end
customerId=(customerId)
click to toggle source
# File lib/upay/customer.rb, line 38 def customerId=(customerId) @customerId = customerId end
delete()
click to toggle source
Verb: DELETE Description: Returns: JSON
# File lib/upay/customer.rb, line 107 def delete url = "rest/v4.3/customers/#{self.customerId}" Requestor.new.delete(url, {}) end
email()
click to toggle source
# File lib/upay/customer.rb, line 27 def email; @email end
email=(email)
click to toggle source
# File lib/upay/customer.rb, line 28 def email=(email) @email = email end
fullName()
click to toggle source
# File lib/upay/customer.rb, line 22 def fullName; @fullName end
fullName=(fullName)
click to toggle source
# File lib/upay/customer.rb, line 23 def fullName=(fullName) @fullName = fullName end
has_subscription?(planCode)
click to toggle source
# 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?()
click to toggle source
# 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()
click to toggle source
# File lib/upay/customer.rb, line 32 def id; @id end
id=(id)
click to toggle source
# File lib/upay/customer.rb, line 33 def id=(id) @id = id end
reload(args = {})
click to toggle source
# 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()
click to toggle source
Verb: GET Description: Returns: JSON
# 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()
click to toggle source
# File lib/upay/customer.rb, line 42 def subscription; @subscription end
subscription=(subscription)
click to toggle source
# File lib/upay/customer.rb, line 43 def subscription=(subscription) @subscription = subscription end
to_hash()
click to toggle source
# File lib/upay/customer.rb, line 146 def to_hash { :customerId => self.customerId || nil, :fullName => self.fullName, :email => self.email } end
update()
click to toggle source
Verb: UPDATE Description: Returns: JSON
# 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?()
click to toggle source
# File lib/upay/customer.rb, line 50 def valid? validator = CustomerValidator.new validator.valid?(self) end