class Moka::Customer
Attributes
address[RW]
birth_date[RW]
card_list[RW]
credit_card[RW]
customer_code[RW]
dealer_customer_id[RW]
email[RW]
first_name[RW]
gender[RW]
gsm_number[RW]
last_name[RW]
password[RW]
response[RW]
Public Class Methods
new(opts = {})
click to toggle source
# File lib/moka/model/customer.rb, line 7 def initialize(opts = {}) opts.each do |o| send("#{o.first.to_s}=".to_sym, o.last) end end
Public Instance Methods
add_with_card()
click to toggle source
# File lib/moka/model/customer.rb, line 37 def add_with_card response = RestClient.post Moka.endpoints.add_customer_with_card, get_and_delete_hash self.response = JSON.parse(response) end
create()
click to toggle source
# File lib/moka/model/customer.rb, line 17 def create response = RestClient.post Moka.endpoints.add_customer, create_hash self.response = JSON.parse(response) end
delete()
click to toggle source
# File lib/moka/model/customer.rb, line 32 def delete response = RestClient.post Moka.endpoints.add_customer, get_and_delete_hash self.response = JSON.parse(response) end
full_name()
click to toggle source
# File lib/moka/model/customer.rb, line 13 def full_name "#{first_name} #{last_name}" end
get()
click to toggle source
# File lib/moka/model/customer.rb, line 22 def get response = RestClient.post Moka.endpoints.add_customer, get_and_delete_hash self.response = JSON.parse(response) end
success?()
click to toggle source
# File lib/moka/model/customer.rb, line 42 def success? response && response['ResultCode'] == 'Success' end
update()
click to toggle source
# File lib/moka/model/customer.rb, line 27 def update response = RestClient.post Moka.endpoints.add_customer, update_hash self.response = JSON.parse(response) end
Private Instance Methods
create_hash(with_card = false)
click to toggle source
# File lib/moka/model/customer.rb, line 47 def create_hash(with_card = false) hsh = { "DealerCustomerAuthentication": Moka.configuration.config_hash, "DealerCustomerRequest": { "CustomerCode": customer_code, "Password": password, "FirstName": first_name, "LastName": last_name, "Gender": gender, "BirthDate": birth_date, "GsmNumber": gsm_number, "Email": email, "Address": address } } if with_card && credit_card && credit_card.is_a?(Moka::Card) hsh[:DealerCustomerRequest][:CardHolderFullName] = credit_card.card_holder_full_name hsh[:DealerCustomerRequest][:CardNumber] = credit_card.card_number hsh[:DealerCustomerRequest][:ExpMonth] = credit_card.exp_month hsh[:DealerCustomerRequest][:ExpYear] = credit_card.exp_year hsh[:DealerCustomerRequest][:CardName] = credit_card.card_name end hsh end
get_and_delete_hash()
click to toggle source
# File lib/moka/model/customer.rb, line 93 def get_and_delete_hash { "DealerCustomerAuthentication": Moka.configuration.config_hash, "DealerCustomerRequest": { "DealerCustomerId": dealer_customer_id, "CustomerCode": customer_code } } end
update_hash()
click to toggle source
# File lib/moka/model/customer.rb, line 74 def update_hash { "DealerCustomerAuthentication": Moka.configuration.config_hash, "DealerCustomerRequest": { "DealerCustomerId": dealer_customer_id, "CustomerCode": customer_code, "Password": password, "FirstName": first_name, "LastName": last_name, "Gender": gender, "BirthDate": birth_date, "GsmNumber": gsm_number, "Email": email, "Address": address } } end