Class: EcwidApi::Api::Customers

Inherits:
Base
  • Object
show all
Defined in:
lib/ecwid_api/api/customers.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from EcwidApi::Api::Base

Instance Method Details

#all(params = {}) ⇒ Object

Public: Get all of the Customer objects for the Ecwid store

Returns an Array of Customer objects



9
10
11
12
13
# File 'lib/ecwid_api/api/customers.rb', line 9

def all(params = {})
  PagedEcwidResponse.new(client, "customers", params) do |customer_hash|
    Customer.new(customer_hash, client: client)
  end
end

#create(params) ⇒ Object

params - a Hash

Raises an Error if there is a problem

Returns a Customer object



34
35
36
37
# File 'lib/ecwid_api/api/customers.rb', line 34

def create(params)
  response = client.post("customers", params)
  find(response.body["id"])
end

#find(id) ⇒ Object

id - an Ecwid customer ID

Returns a Customer object, or nil if one can’t be found



20
21
22
23
24
25
# File 'lib/ecwid_api/api/customers.rb', line 20

def find(id)
  response = client.get("customers/#{id}")
  if response.success?
    Customer.new(response.body, client: client)
  end
end

#update(id, params) ⇒ Object

id - the Ecwid customer ID params - a Hash

Raises an Error if there is a problem

Returns a Customer object



47
48
49
50
# File 'lib/ecwid_api/api/customers.rb', line 47

def update(id, params)
  client.put("customers/#{id}", params)
  find(id)
end