Class: Versafleet::Client
- Inherits:
-
Object
- Object
- Versafleet::Client
- Defined in:
- lib/versafleet/client.rb
Constant Summary collapse
- BASE_URL =
Default API endpoint
"https://api.versafleet.co/api"
Instance Attribute Summary collapse
-
#adapter ⇒ Symbol
readonly
Gets the Symbol key identifying a default Adapter to use.
-
#client_id ⇒ String
readonly
Gets the VersaFleet API Key.
-
#client_secret ⇒ String
readonly
Gets the VersaFleet Secret Key.
Instance Method Summary collapse
-
#connection ⇒ Faraday::Connection
Initializes a new Faraday connection.
-
#customers ⇒ CustomersResource
Customers Resource instance.
-
#drivers ⇒ DriversResource
Drivers Resource instance.
-
#initialize(client_id:, client_secret:, adapter: Faraday.default_adapter, stubs: nil) ⇒ Client
constructor
Initialize a new VersaFlet client.
-
#jobs ⇒ JobsResource
Jobs Resource instance.
-
#runsheets ⇒ RunsheetsResource
Runsheets Resource instance.
-
#tasks ⇒ TasksResource
Tasks Resource instance.
-
#vehicles ⇒ VehiclesResource
Vehicles Resource instance.
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
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
#adapter ⇒ Symbol (readonly)
Returns 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_id ⇒ String (readonly)
Returns Gets the VersaFleet API Key.
7 8 9 |
# File 'lib/versafleet/client.rb', line 7 def client_id @client_id end |
#client_secret ⇒ String (readonly)
Returns Gets the VersaFleet Secret Key.
10 11 12 |
# File 'lib/versafleet/client.rb', line 10 def client_secret @client_secret end |
Instance Method Details
#connection ⇒ Faraday::Connection
Initializes a new 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 |
#customers ⇒ CustomersResource
Customers Resource instance
72 73 74 |
# File 'lib/versafleet/client.rb', line 72 def customers CustomersResource.new(self) end |
#drivers ⇒ DriversResource
Drivers Resource instance
51 52 53 |
# File 'lib/versafleet/client.rb', line 51 def drivers DriversResource.new(self) end |
#jobs ⇒ JobsResource
Jobs Resource instance
37 38 39 |
# File 'lib/versafleet/client.rb', line 37 def jobs JobsResource.new(self) end |
#runsheets ⇒ RunsheetsResource
Runsheets Resource instance
65 66 67 |
# File 'lib/versafleet/client.rb', line 65 def runsheets RunsheetsResource.new(self) end |
#tasks ⇒ TasksResource
Tasks Resource instance
44 45 46 |
# File 'lib/versafleet/client.rb', line 44 def tasks TasksResource.new(self) end |
#vehicles ⇒ VehiclesResource
Vehicles Resource instance
58 59 60 |
# File 'lib/versafleet/client.rb', line 58 def vehicles VehiclesResource.new(self) end |