Class: Versafleet::CustomersResource
- Defined in:
- lib/versafleet/resources/customers.rb
Instance Attribute Summary
Attributes inherited from Resource
Instance Method Summary collapse
-
#create(customer:) ⇒ Customer
Create a Customer.
-
#list(**params) ⇒ Collection
List All Customers.
-
#retrieve(customer_id:) ⇒ Customer
Get Customer details.
-
#update(customer_id:, customer:) ⇒ Customer
Update Customer.
Methods inherited from Resource
Constructor Details
This class inherits a constructor from Versafleet::Resource
Instance Method Details
#create(customer:) ⇒ Customer
Create a Customer
Example:
client.customers.create(customer: {name: "John Doe", email: "[email protected]"})
46 47 48 49 |
# File 'lib/versafleet/resources/customers.rb', line 46 def create(customer:) payload = {customer: customer} Customer.new post_request("customers", body: payload).body.dig("customer") end |
#list(**params) ⇒ Collection
List All Customers
Examples:
client.customers.list
# set per page to 20
client.customers.list(per_page: 20)
# move to page 2
client.customers.list(page: 2, per_page: 20)
17 18 19 20 |
# File 'lib/versafleet/resources/customers.rb', line 17 def list(**params) response = get_request("customers", params: params) Collection.from_response(response, key: "customers", type: Customer) end |
#retrieve(customer_id:) ⇒ Customer
32 33 34 |
# File 'lib/versafleet/resources/customers.rb', line 32 def retrieve(customer_id:) Customer.new get_request("customers/#{customer_id}").body.dig("customer") end |
#update(customer_id:, customer:) ⇒ Customer
Update Customer
Example:
client.customers.update(customer_id: 123, customer: {name: "Bourne"})
62 63 64 65 |
# File 'lib/versafleet/resources/customers.rb', line 62 def update(customer_id:, customer:) payload = {customer: customer} Customer.new put_request("customers/#{customer_id}", body: payload).body.dig("customer") end |