Class: Versafleet::DriversResource

Inherits:
Resource
  • Object
show all
Defined in:
lib/versafleet/resources/drivers.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(driver:) ⇒ Driver

Create a Driver

Examples:

client.drivers.create(driver: {name: "Yolo", dob: "1990-09-09"})

VersaFleet API

Parameters:

  • driver (Hash)

    Driver request payload

Returns:



46
47
48
49
# File 'lib/versafleet/resources/drivers.rb', line 46

def create(driver:)
  payload = {driver: driver}
  Driver.new post_request("drivers", body: payload).body.dig("driver")
end

#list(**params) ⇒ Collection

List All Drivers

Examples:

client.drivers.list
# set per page to 20
client.drivers.list(per_page: 20)
# move to page 2
client.drivers.list(page: 2, per_page: 20)

VersaFleet API

Parameters:

  • params (Hash)

    the filter query

Returns:



17
18
19
20
# File 'lib/versafleet/resources/drivers.rb', line 17

def list(**params)
  response = get_request("drivers", params: params)
  Collection.from_response(response, key: "drivers", type: Driver)
end

#retrieve(driver_id:) ⇒ Driver

Get Driver details

Examples:

client.drivers.retrieve(driver_id: 123)

VersaFleet API

Parameters:

  • driver_id (Integer)

    Driver ID

Returns:



32
33
34
# File 'lib/versafleet/resources/drivers.rb', line 32

def retrieve(driver_id:)
  Driver.new get_request("drivers/#{driver_id}").body.dig("driver")
end

#update(driver_id:, driver:) ⇒ Driver

Update Driver

Examples:

client.drivers.update(driver_id: 123, driver: {name: "John"})

VersaFleet API

Parameters:

  • driver_id (Integer)

    Driver ID

  • driver (Hash)

    Driver request payload

Returns:



62
63
64
65
# File 'lib/versafleet/resources/drivers.rb', line 62

def update(driver_id:, driver:)
  payload = {driver: driver}
  Driver.new put_request("drivers/#{driver_id}", body: payload).body.dig("driver")
end