Class: Versafleet::DriversResource
- Defined in:
- lib/versafleet/resources/drivers.rb
Instance Attribute Summary
Attributes inherited from Resource
Instance Method Summary collapse
-
#create(driver:) ⇒ Driver
Create a Driver.
-
#list(**params) ⇒ Collection
List All Drivers.
-
#retrieve(driver_id:) ⇒ Driver
Get Driver details.
-
#update(driver_id:, driver:) ⇒ Driver
Update Driver.
Methods inherited from Resource
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"})
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)
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
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"})
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 |