Class: Versafleet::VehiclesResource
- Defined in:
- lib/versafleet/resources/vehicles.rb
Instance Attribute Summary
Attributes inherited from Resource
Instance Method Summary collapse
-
#create(vehicle:) ⇒ Vehicle
Create a Vehicle.
-
#list(**params) ⇒ Collection
List All Vehicles.
-
#retrieve(vehicle_id:) ⇒ Vehicle
Get Vehicle details.
-
#update(vehicle_id:, vehicle:) ⇒ Vehicle
Update Vehicle.
Methods inherited from Resource
Constructor Details
This class inherits a constructor from Versafleet::Resource
Instance Method Details
#create(vehicle:) ⇒ Vehicle
Create a Vehicle
Examples:
client.vehicles.create(vehicle: {plate_number: "SK1212", model: "Honda", speed: 50})
46 47 48 49 |
# File 'lib/versafleet/resources/vehicles.rb', line 46 def create(vehicle:) payload = {vehicle: vehicle} Vehicle.new post_request("vehicles", body: payload).body.dig("vehicle") end |
#list(**params) ⇒ Collection
List All Vehicles
Examples:
client.vehicles.list
# set per page to 20
client.vehicles.list(per_page: 20)
# move to page 2
client.vehicles.list(page: 2, per_page: 20)
17 18 19 20 |
# File 'lib/versafleet/resources/vehicles.rb', line 17 def list(**params) response = get_request("vehicles", params: params) Collection.from_response(response, key: "vehicles", type: Vehicle) end |
#retrieve(vehicle_id:) ⇒ Vehicle
32 33 34 |
# File 'lib/versafleet/resources/vehicles.rb', line 32 def retrieve(vehicle_id:) Vehicle.new get_request("vehicles/#{vehicle_id}").body.dig("vehicle") end |
#update(vehicle_id:, vehicle:) ⇒ Vehicle
Update Vehicle
Examples:
client.vehicles.update(vehicle_id: 123, vehicle: {model: "Mercedes", speed: 70})
62 63 64 65 |
# File 'lib/versafleet/resources/vehicles.rb', line 62 def update(vehicle_id:, vehicle:) payload = {vehicle: vehicle} Vehicle.new put_request("vehicles/#{vehicle_id}", body: payload).body.dig("vehicle") end |