Class: VehiclesDB::Client

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

Overview

A thin client over the VehiclesDB HTTP API. Standalone: construct one directly, or use ‘VehiclesDB.client` (which reads the global configuration).

client = VehiclesDB::Client.new(api_key: "vdb_...")
client.configured?   # => true

The request plumbing (auth header, JSON, timeout, error mapping) is ready; resource methods (e.g. ‘model`, `image`) are added as the API ships — they’ll build on the private ‘get` below. Kept deliberately small for now: this release reserves the gem and sets the shape.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key: nil, api_base_url: nil, timeout: nil) ⇒ Client

Returns a new instance of Client.



19
20
21
22
23
24
# File 'lib/vehiclesdb/client.rb', line 19

def initialize(api_key: nil, api_base_url: nil, timeout: nil)
  config        = VehiclesDB.configuration
  @api_key      = api_key      || config.api_key
  @api_base_url = api_base_url || config.api_base_url
  @timeout      = timeout      || config.timeout
end

Instance Attribute Details

#api_base_urlObject (readonly)

Returns the value of attribute api_base_url.



17
18
19
# File 'lib/vehiclesdb/client.rb', line 17

def api_base_url
  @api_base_url
end

#api_keyObject (readonly)

Returns the value of attribute api_key.



17
18
19
# File 'lib/vehiclesdb/client.rb', line 17

def api_key
  @api_key
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



17
18
19
# File 'lib/vehiclesdb/client.rb', line 17

def timeout
  @timeout
end

Instance Method Details

#configured?Boolean

True when an API key is present (the client can authenticate).

Returns:

  • (Boolean)


27
28
29
# File 'lib/vehiclesdb/client.rb', line 27

def configured?
  !api_key.to_s.empty?
end