class SparkApi::Configuration::YamlConfig
Constants
- DEFAULT_OAUTH2_PROVIDER
- KEY_CONFIGURATIONS
Attributes
client_keys[R]
oauth2_keys[R]
provider[R]
Public Class Methods
build(name)
click to toggle source
# File lib/spark_api/configuration/yaml.rb, line 64 def self.build(name) yaml = YamlConfig.new("#{config_path}/#{name}.yml") end
config_keys()
click to toggle source
# 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_path()
click to toggle source
Used to specify the root of where to look for SparkApi
config files
# File lib/spark_api/configuration/yaml.rb, line 51 def self.config_path path_prefix + "config/spark_api" end
exists?(name)
click to toggle source
# File lib/spark_api/configuration/yaml.rb, line 60 def self.exists?(name) File.exists? "#{config_path}/#{name}.yml" end
new(filename=nil)
click to toggle source
# File lib/spark_api/configuration/yaml.rb, line 12 def initialize(filename=nil) @oauth2 = false load_file(filename) unless filename.nil?() end
Private Class Methods
path_prefix()
click to toggle source
In a rails app, default to the rails root, regardless of where that may be
# File lib/spark_api/configuration/yaml.rb, line 102 def self.path_prefix "#{Rails.root}/" rescue => e "" end
Public Instance Methods
api_env()
click to toggle source
# 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)
click to toggle source
# 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
name()
click to toggle source
# File lib/spark_api/configuration/yaml.rb, line 34 def name @name end
oauth2?()
click to toggle source
# File lib/spark_api/configuration/yaml.rb, line 26 def oauth2? return oauth2 == true end
ssl_verify?()
click to toggle source
# File lib/spark_api/configuration/yaml.rb, line 30 def ssl_verify? return ssl_verify == true end
Protected Instance Methods
env()
click to toggle source
# File lib/spark_api/configuration/yaml.rb, line 69 def env ENV end
Private Instance Methods
load_api_auth(config={})
click to toggle source
# File lib/spark_api/configuration/yaml.rb, line 74 def load_api_auth(config={}) @client_keys = {} @oauth2_keys = {} config.each do |key,val| sym = key.to_sym if VALID_OPTION_KEYS.include?(sym) self.send("#{sym}=", val) @client_keys[sym] = val end end end
load_oauth2(config={})
click to toggle source
# File lib/spark_api/configuration/yaml.rb, line 85 def load_oauth2(config={}) @oauth2_provider = DEFAULT_OAUTH2_PROVIDER @client_keys = {:oauth2_provider => @oauth2_provider } @oauth2_keys = {} @oauth2 = true config.each do |key,val| sym = key.to_sym if VALID_OPTION_KEYS.include?(sym) self.send("#{sym}=", val) @client_keys[sym] = val elsif OAUTH2_KEYS.include? sym self.send("#{sym}=", val) @oauth2_keys[sym] = val end end end