Class: Versafleet::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/versafleet/client.rb

Constant Summary collapse

BASE_URL =

Default API endpoint

"https://api.versafleet.co/api"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client_id:, client_secret:, adapter: Faraday.default_adapter, stubs: nil) ⇒ Client

Initialize a new VersaFlet client

Example:

client = Versafleet::Client.new(client_id: ENV["CLIENT_ID"], client_secret: ENV["CLIENT_SECRET"])
# use Jobs resource
client.jobs.list

Parameters:

  • client_id (String)

    VersaFleet API Key

  • client_secret (String)

    VersaFleet Secret Key



25
26
27
28
29
30
31
32
# File 'lib/versafleet/client.rb', line 25

def initialize(client_id:, client_secret:, adapter: Faraday.default_adapter, stubs: nil)
  @client_id = client_id
  @client_secret = client_secret
  @adapter = adapter

  # Test stubs for requests
  @stubs = stubs
end

Instance Attribute Details

#adapterSymbol (readonly)

Returns Gets the Symbol key identifying a default Adapter to use.

Returns:

  • (Symbol)

    Gets the Symbol key identifying a default Adapter to use



13
14
15
# File 'lib/versafleet/client.rb', line 13

def adapter
  @adapter
end

#client_idString (readonly)

Returns Gets the VersaFleet API Key.

Returns:

  • (String)

    Gets the VersaFleet API Key



7
8
9
# File 'lib/versafleet/client.rb', line 7

def client_id
  @client_id
end

#client_secretString (readonly)

Returns Gets the VersaFleet Secret Key.

Returns:

  • (String)

    Gets the VersaFleet Secret Key



10
11
12
# File 'lib/versafleet/client.rb', line 10

def client_secret
  @client_secret
end

Instance Method Details

#connectionFaraday::Connection

Initializes a new Faraday connection

Returns:

  • (Faraday::Connection)


79
80
81
82
83
84
85
86
# File 'lib/versafleet/client.rb', line 79

def connection
  @connection ||= Faraday.new(params: default_params) do |conn|
    conn.url_prefix = BASE_URL
    conn.request :json
    conn.response :json, content_type: "application/json"
    conn.adapter adapter, @stubs
  end
end

#customersCustomersResource

Customers Resource instance

Returns:



72
73
74
# File 'lib/versafleet/client.rb', line 72

def customers
  CustomersResource.new(self)
end

#driversDriversResource

Drivers Resource instance

Returns:



51
52
53
# File 'lib/versafleet/client.rb', line 51

def drivers
  DriversResource.new(self)
end

#jobsJobsResource

Jobs Resource instance

Returns:



37
38
39
# File 'lib/versafleet/client.rb', line 37

def jobs
  JobsResource.new(self)
end

#runsheetsRunsheetsResource

Runsheets Resource instance

Returns:



65
66
67
# File 'lib/versafleet/client.rb', line 65

def runsheets
  RunsheetsResource.new(self)
end

#tasksTasksResource

Tasks Resource instance

Returns:



44
45
46
# File 'lib/versafleet/client.rb', line 44

def tasks
  TasksResource.new(self)
end

#vehiclesVehiclesResource

Vehicles Resource instance

Returns:



58
59
60
# File 'lib/versafleet/client.rb', line 58

def vehicles
  VehiclesResource.new(self)
end