Class: SparkApi::Configuration::YamlConfig

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

Constant Summary collapse

KEY_CONFIGURATIONS =
VALID_OPTION_KEYS  + [:oauth2] + OAUTH2_KEYS
DEFAULT_OAUTH2_PROVIDER =
"SparkApi::Authentication::OAuth2Impl::CLIProvider"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename = nil) ⇒ YamlConfig

Returns a new instance of YamlConfig.



12
13
14
15
# File 'lib/spark_api/configuration/yaml.rb', line 12

def initialize(filename=nil)
  @oauth2 = false
  load_file(filename) unless filename.nil?()
end

Instance Attribute Details

#client_keysObject (readonly)

Returns the value of attribute client_keys.



10
11
12
# File 'lib/spark_api/configuration/yaml.rb', line 10

def client_keys
  @client_keys
end

#oauth2_keysObject (readonly)

Returns the value of attribute oauth2_keys.



10
11
12
# File 'lib/spark_api/configuration/yaml.rb', line 10

def oauth2_keys
  @oauth2_keys
end

#providerObject (readonly)

Returns the value of attribute provider.



10
11
12
# File 'lib/spark_api/configuration/yaml.rb', line 10

def provider
  @provider
end

Class Method Details

.build(name) ⇒ Object



64
65
66
# File 'lib/spark_api/configuration/yaml.rb', line 64

def self.build(name)
  yaml = YamlConfig.new("#{config_path}/#{name}.yml")
end

.config_keysObject



55
56
57
58
# File 'lib/spark_api/configuration/yaml.rb', line 55

def self.config_keys()
  files = Dir["#{config_path}/*.yml"]
  files.map {|f| File.basename(f,".yml") }
end

.config_pathObject

Used to specify the root of where to look for SparkApi config files



51
52
53
# File 'lib/spark_api/configuration/yaml.rb', line 51

def self.config_path
  path_prefix + "config/spark_api"
end

.exists?(name) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/spark_api/configuration/yaml.rb', line 60

def self.exists?(name)
  File.exists? "#{config_path}/#{name}.yml"
end

Instance Method Details

#api_envObject



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/spark_api/configuration/yaml.rb', line 38

def api_env
  if env.include? "SPARK_API_ENV"
    env["SPARK_API_ENV"]
  elsif env.include? "RAILS_ENV"
    env["RAILS_ENV"]
  elsif env.include? "RACK_ENV"
    env["RACK_ENV"]
  else
    "development"
  end
end

#load_file(file) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/spark_api/configuration/yaml.rb', line 16

def load_file(file)
  @file = file
  @name = File.basename(file, ".yml")
  config = YAML.load(ERB.new(File.read(file)).result)[api_env]
  config["oauth2"] == true  ? load_oauth2(config) : load_api_auth(config)
rescue => e
  SparkApi.logger().error("Unable to load config file #{file}[#{api_env}]")
  raise e
end

#nameObject



34
35
36
# File 'lib/spark_api/configuration/yaml.rb', line 34

def name
  @name
end

#oauth2?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/spark_api/configuration/yaml.rb', line 26

def oauth2?
  return oauth2 == true
end

#ssl_verify?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/spark_api/configuration/yaml.rb', line 30

def ssl_verify?
  return ssl_verify == true
end