Class: HasOffersV3::Configuration

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

Constant Summary collapse

DEFAULTS =
{
  host: 'api.hasoffers.com',
  protocol: 'https',
  read_timeout: 60,
  base_path: '/v3',
  network_id: '',
  api_key: '',
  json_driver: self.default_json_driver,
  raise_errors: false,
  logger: nil,
  proxy_host: nil,
  proxy_port: nil,
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Configuration

Returns a new instance of Configuration.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/hasoffersv3/configuration.rb', line 41

def initialize(options={})
  defaults = DEFAULTS.dup
  @options = options.dup

  defaults.keys.each do |key|
    # Symbolize only keys that are needed
    @options[key] = @options[key.to_s] if @options.has_key?(key.to_s)
  end

  # Use default when option is not specified or nil
  defaults.keys.each do |key|
    @options[key] = defaults[key] if @options[key].nil?
  end
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



39
40
41
# File 'lib/hasoffersv3/configuration.rb', line 39

def options
  @options
end

Class Method Details

.default_json_driverObject



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

def self.default_json_driver
  @_default_json_driver ||=
      if defined?(Oj)
        Oj
      elsif defined?(MultiJson)
        MultiJson
      else
        JSON
      end
end

Instance Method Details

#base_uriObject



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

def base_uri
  "#{protocol}://#{host}#{base_path}"
end

#http_loggerObject



56
57
58
# File 'lib/hasoffersv3/configuration.rb', line 56

def http_logger
  @http_logger ||= HasOffersV3::Logger.new(logger)
end