module NaranyaId
Public Class Methods
consumer()
click to toggle source
# File lib/naranya_id.rb, line 46 def consumer unless config.consumer_key.present? && config.consumer_secret.present? logger.warn "No Naranya ID consumer key or secret configured at SDK level... using environment variables." logger.warn "Current Naranya ID config: #{config.inspect}" end # TODO: WTF??? Porqué no carga la config default????? config.client_options[:site] = ENV.fetch('NARANYA_ID_WEB_URL', 'https://id.naranya.net') config.client_options[:api_site] = ENV.fetch('NARANYA_ID_API_URL', 'https://id.naranya.net:89') config.client_options[:api_path] = ENV.fetch('NARANYA_ID_API_PATH', '/api') consumer_key = config.consumer_key || ENV['NARANYA_ID_API_KEY'] consumer_secret = config.consumer_secret || ENV['NARANYA_ID_API_SECRET'] consumer = ::OAuth::Consumer.new( consumer_key, consumer_secret, config.client_options.merge(site: config.client_options[:api_site]) ) consumer.http.open_timeout = config.open_timeout if config.open_timeout consumer.http.read_timeout = config.read_timeout if config.read_timeout # Se habilita el output sólo si en las opciones debug_oauth es true: consumer.http.set_debug_output($stderr) if config.debug_oauth consumer end
load_config_from_hash!(given_hash)
click to toggle source
# File lib/naranya_id.rb, line 82 def load_config_from_hash!(given_hash) configure do |config| given_hash.each do |key, value| existing_value = config.send(key.to_sym) if existing_value.nil? || existing_value.is_a?(TrueClass) && value.is_a?(FalseClass) || existing_value.is_a?(FalseClass) && value.is_a?(TrueClass) # Existing value was nil, or a boolean with a different value: config.send "#{key}=".to_sym, value else if existing_value.is_a?(Hash) && value.is_a?(Hash) # Merge hashes: config.send "#{key}=".to_sym, existing_value.merge(value) elsif existing_value.is_a?(Array) && value.is_a?(Array) # Concat arrays: config.send "#{key}=".to_sym, (existing_value + value).uniq else # Assign directly: config.send "#{key}=".to_sym, value end end end end end
load_config_from_yml!(yml_path, env="production")
click to toggle source
# File lib/naranya_id.rb, line 75 def load_config_from_yml!(yml_path, env="production") raise "YAML file doesn't exist" unless File.exist?(yml_path) yml_config = YAML::load(ERB.new(File.read(yml_path)).result) yml_config = yml_config[env] if yml_config.has_key?(env) load_config_from_hash!(yml_config) end
logger()
click to toggle source
Get the logger.
@note Will try to grab Rails’ logger first before creating a new logger with stdout.
@example Get the logger. Loggable.logger
@return [ Logger ] The logger.
@since 3.0.0
# File lib/naranya_id.rb, line 119 def logger return @logger if defined?(@logger) @logger = rails_logger || default_logger end
logger=(logger)
click to toggle source
Set the logger.
@example Set the logger. Loggable.logger = Logger.new($stdout)
@param [ Logger ] The logger to set.
@return [ Logger ] The new logger.
@since 3.0.0
# File lib/naranya_id.rb, line 134 def logger=(logger) @logger = logger end
Private Class Methods
default_logger()
click to toggle source
Gets the default Mongoid logger - stdout.
@api private
@example Get the default logger. Loggable.default_logger
@return [ Logger ] The default logger.
@since 3.0.0
# File lib/naranya_id.rb, line 150 def default_logger logger = Logger.new($stdout) logger.level = Logger::INFO logger end
rails_logger()
click to toggle source