Class: ApphoshiesClient::Configuration

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



2
3
4
# File 'lib/apphoshies_client/configuration.rb', line 2

def api_key
  @api_key
end

#app_idObject

Returns the value of attribute app_id.



2
3
4
# File 'lib/apphoshies_client/configuration.rb', line 2

def app_id
  @app_id
end

#siteObject

Returns the value of attribute site.



2
3
4
# File 'lib/apphoshies_client/configuration.rb', line 2

def site
  @site
end

#usernameObject

Returns the value of attribute username.



2
3
4
# File 'lib/apphoshies_client/configuration.rb', line 2

def username
  @username
end

Instance Method Details

#config(scope = 'default', cfg_path = "apphoshies.yml") ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/apphoshies_client/configuration.rb', line 4

def config(scope = 'default', cfg_path = "apphoshies.yml")
  read_config(cfg_path)
  if @config and @config[scope]
    self.username = @config[scope]['username']
    self.api_key = @config[scope]['api_key']
    self.app_id = @config[scope]['app_id']
  end
  self.site = 'https://service.apphoshies.com'
end

#read_config(cfg_path) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/apphoshies_client/configuration.rb', line 14

def read_config(cfg_path)
  if File.exists?(cfg_path)
    puts "Using config: #{cfg_path}"
    @config = YAML.load(File.read(cfg_path))
  else
    begin
      puts "Using config in your home directory"
      @config = YAML.load(File.read("#{ENV['HOME']}/.apphoshies.yml"))
    rescue Errno::ENOENT
      raise ApphoshiesClient::MissingConfigurationException, "apphoshies.yml expected in current directory or ~/.apphoshies.yml"
    end
  end
end