Class: Versafleet::CustomersResource

Inherits:
Resource
  • Object
show all
Defined in:
lib/versafleet/resources/customers.rb

Instance Attribute Summary

Attributes inherited from Resource

#client

Instance Method Summary collapse

Methods inherited from Resource

#initialize

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]"})

VersaFleet API

Parameters:

  • customer (Hash)

    Customer request payload

Returns:



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)

VersaFleet API

Parameters:

  • params (Hash)

    the filter query

Returns:



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

Get Customer details

Example:

client.customers.retrieve(customer_id: 123)

VersaFleet API

Parameters:

  • customer_id (Integer|String)

    Customer ID or Customer GUID

Returns:



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"})

VersaFleet API

Parameters:

  • customer_id (Integer|String)

    Customer ID or Customer GUID

  • customer (Hash)

    Customer request payload

Returns:



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