Module: NaranyaId

Extended by:
ActiveSupport::Autoload
Includes:
ActiveSupport::Configurable
Defined in:
lib/naranya_id.rb,
lib/naranya_id/models/user.rb

Defined Under Namespace

Modules: Errors Classes: User

Class Method Summary collapse

Class Method Details

.consumerObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# 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) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# 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") ⇒ Object



75
76
77
78
79
80
# 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

.loggerLogger

Note:

Will try to grab Rails’ logger first before creating a new logger

Get the logger.

with stdout.

Loggable.logger

Examples:

Get the logger.

Returns:

  • (Logger)

    The logger.

Since:

  • 3.0.0



119
120
121
122
# File 'lib/naranya_id.rb', line 119

def logger
  return @logger if defined?(@logger)
  @logger = rails_logger || default_logger
end

.logger=(logger) ⇒ Logger

Set the logger.

Loggable.logger = Logger.new($stdout)

Examples:

Set the logger.

Parameters:

  • The (Logger)

    logger to set.

Returns:

  • (Logger)

    The new logger.

Since:

  • 3.0.0



134
135
136
# File 'lib/naranya_id.rb', line 134

def logger=(logger)
  @logger = logger
end