Class: Versafleet::VehiclesResource

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

Create a Vehicle

Examples:

client.vehicles.create(vehicle: {plate_number: "SK1212", model: "Honda", speed: 50})

VersaFleet API

Parameters:

  • vehicle (Hash)

    Vehicle request payload

Returns:



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)

VersaFleet API

Parameters:

  • params (Hash)

    the filter query

Returns:



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

Get Vehicle details

Examples:

client.vehicles.retrieve(vehicle_id: 123)

VersaFleet API

Parameters:

  • vehicle_id (Integer)

    Vehicle ID

Returns:



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

VersaFleet API

Parameters:

  • vehicle_id (Integer)

    Vehicle ID

  • vehicle (Hash)

    Vehicle request payload

Returns:



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