Class: VaucharAPI::Customer

Inherits:
Base
  • Object
show all
Defined in:
lib/vauchar_api/resources/customer.rb

Overview

Examples

Create
new_customer = VaucharAPI::Customer.new({
  user_id: "12345",
  name: "max",
  email: "[email protected]",
  phone: "+886912345678",
  birthday: "1990-03-25",
})
new_customer.save

Read
customer = VaucharAPI::Customer.find("cust-15507323535c6e4c416c697")
customers = VaucharAPI::Customer.all

Update
customer = VaucharAPI::Customer.find("cust-15507323535c6e4c416c697")
customer.name = "test update"
customer.save

Delete
customer = VaucharAPI::Customer.find("cust-15507323535c6e4c416c697")
customer.destroy

Redemptions
customer = VaucharAPI::Customer.find("cust-15507323535c6e4c416c697")
voucher = customer.redemptions({deal_id: "en-deal-15499589715c627f3b57837"})
voucher.voucher_code # => "DA2C2J65JFVNY"

Instance Method Summary collapse

Methods inherited from Base

#encode, init_prefix, init_prefix_explicit, password, user

Instance Method Details

#accepts_attributesObject



33
34
35
36
37
# File 'lib/vauchar_api/resources/customer.rb', line 33

def accepts_attributes
  accepts = [:name, :email, :phone, :birthday, :created, :last_seen, :total_purchase]
  accepts.push :user_id if self.new?
  accepts
end

#redemptions(params) ⇒ Object



39
40
41
42
# File 'lib/vauchar_api/resources/customer.rb', line 39

def redemptions(params)
  resource = post("deals/#{params[:deal_id]}/redemptions", {}, only_id)
  self.class.format.decode(resource.body)
end