Module: Orderspace::Endpoint::Customers

Includes:
Structs
Included in:
Client::CustomersEndpoint
Defined in:
lib/orderspace/endpoint/customers.rb

Overview

Contains the methods to interact with the customers endpoint.

Instance Method Summary collapse

Methods included from Structs

from, hashify, validate

Instance Method Details

#create_customer(customer) ⇒ Orderspace::Structs::Customer

Used to add a customer to your orderspace account

Parameters:

Returns:

See Also:



18
19
20
21
# File 'lib/orderspace/endpoint/customers.rb', line 18

def create_customer(customer)
  response = client.post('customers', { customer: Orderspace::Structs.hashify(customer) })
  Orderspace::Structs.from(JSON.parse(response.body)['customer'], Customer)
end

#edit_customer(customer) ⇒ Object

Allows to edit the customer and change it’s attributes

Parameters:



53
54
55
56
57
# File 'lib/orderspace/endpoint/customers.rb', line 53

def edit_customer(customer)
  response = client.put("customers/#{customer.id}", { customer: Orderspace::Structs.hashify(customer) })

  Orderspace::Structs.from(JSON.parse(response.body)['customer'], Customer)
end

#get_customer(customer_id) ⇒ Orderspace::Structs::Customer

Returns a customer searching by it’s id

Parameters:

  • customer_id (String)

    the id of the customer we are looking for.

Returns:



44
45
46
47
48
# File 'lib/orderspace/endpoint/customers.rb', line 44

def get_customer(customer_id)
  response = client.get("customers/#{customer_id}")

  Orderspace::Structs.from(JSON.parse(response.body)['customer'], Customer)
end

#list_customers(options = {}) ⇒ Object

Lists all the customers in your account.

You can pass in options like so: { query: { starting_after: ‘cu_53zjgvnm’, limit: 1 } }

Check tho orderspace API documentation to know all the options available.



34
35
36
37
38
# File 'lib/orderspace/endpoint/customers.rb', line 34

def list_customers(options = {})
  response = client.get('customers', options)

  Orderspace::Structs.from(JSON.parse(response.body), CustomerList)
end