Class: DogWatch::Model::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/dogwatch/model/config.rb

Overview

Manages API configuration. Currently handles credential only.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key = nil, app_key = nil, timeout = 5) ⇒ Config

Returns a new instance of Config.

Parameters:

  • api_key (String) (defaults to: nil)
  • app_key (String) (defaults to: nil)
  • timeout (Integer) (defaults to: 5)


17
18
19
20
21
22
23
24
# File 'lib/dogwatch/model/config.rb', line 17

def initialize(api_key = nil, app_key = nil, timeout = 5)
  @api_key = api_key unless api_key.nil?
  @app_key = app_key unless app_key.nil?
  @timeout = timeout
  return unless app_key.nil? || api_key.nil?

  from_file
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



10
11
12
# File 'lib/dogwatch/model/config.rb', line 10

def api_key
  @api_key
end

#app_keyObject

Returns the value of attribute app_key.



11
12
13
# File 'lib/dogwatch/model/config.rb', line 11

def app_key
  @app_key
end

#timeoutObject

Returns the value of attribute timeout.



12
13
14
# File 'lib/dogwatch/model/config.rb', line 12

def timeout
  @timeout
end

Instance Method Details

#from_fileObject



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/dogwatch/model/config.rb', line 26

def from_file
  begin
    config_file = IO.read("#{Dir.home}/.dogwatch/credentials")
  rescue
    raise('No credentials supplied')
  end

  credentials = YAML.load(config_file)
  @api_key = credentials['api_key']
  @app_key = credentials['app_key']
end