Class: DogWatch::Model::Config
- Inherits:
-
Object
- Object
- DogWatch::Model::Config
- Defined in:
- lib/dogwatch/model/config.rb
Overview
Manages API configuration. Currently handles credential only.
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#app_key ⇒ Object
Returns the value of attribute app_key.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Instance Method Summary collapse
- #from_file ⇒ Object
-
#initialize(api_key = nil, app_key = nil, timeout = 5) ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize(api_key = nil, app_key = nil, timeout = 5) ⇒ Config
Returns a new instance of Config.
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_key ⇒ Object
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_key ⇒ Object
Returns the value of attribute app_key.
11 12 13 |
# File 'lib/dogwatch/model/config.rb', line 11 def app_key @app_key end |
#timeout ⇒ Object
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_file ⇒ Object
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 |