Class: Onfleet::Configuration

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key, base_url = nil, headers = {}) ⇒ Configuration

Returns a new instance of Configuration.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/configuration.rb', line 7

def initialize(api_key, base_url = nil, headers = {})
  file = File.read(File.expand_path("../../package.json", __FILE__))
  package_data = JSON.parse(file)

  @default_url = 'https://onfleet.com/api/v2'

  # ACTION: need to figure out how to include API timeout parameter
  @default_timeout = 70000
  @api_key = api_key
  @base_url = base_url ? base_url : @default_url
  @version = package_data['version']
  @name = package_data['name']

  # Default headers included in all API requests
  headers['Content-Type'] = 'application/json'
  headers['User-Agent'] = "#{@name}-#{@version}"
  @headers = headers

  @auth_validated = Onfleet.validate_authentication(@base_url, @api_key)
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



5
6
7
# File 'lib/configuration.rb', line 5

def api_key
  @api_key
end

#base_urlObject (readonly)

Returns the value of attribute base_url.



5
6
7
# File 'lib/configuration.rb', line 5

def base_url
  @base_url
end

#default_timeoutObject (readonly)

Returns the value of attribute default_timeout.



5
6
7
# File 'lib/configuration.rb', line 5

def default_timeout
  @default_timeout
end

#headersObject (readonly)

Returns the value of attribute headers.



5
6
7
# File 'lib/configuration.rb', line 5

def headers
  @headers
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/configuration.rb', line 5

def name
  @name
end

#versionObject (readonly)

Returns the value of attribute version.



5
6
7
# File 'lib/configuration.rb', line 5

def version
  @version
end