Class: DigiwinDsp::Configuration

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

Constant Summary collapse

DEFAULT_TIMEOUT =
10
DEFAULT_OPEN_TIMEOUT =
5
DEFAULT_ALLOWED_HOSTS =
["digiwindsp.digiwin.com"].freeze
BASE_URLS =
{
  sandbox: "https://digiwindsp.digiwin.com/DSP_UAT/api/DSP",
  production: "https://digiwindsp.digiwin.com/DSP/api/DSP"
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/digiwin_dsp/configuration.rb', line 21

def initialize
  @api_key       = ENV["DIGIWIN_DSP_API_KEY"]
  @api_secret    = ENV["DIGIWIN_DSP_API_SECRET"]
  @platform_id   = ENV["DIGIWIN_DSP_PLATFORM_ID"]
  @environment   = ENV.fetch("DIGIWIN_DSP_ENV") { "sandbox" }.to_sym
  @base_url      = ENV["DIGIWIN_DSP_BASE_URL"]
  @timeout       = DEFAULT_TIMEOUT
  @open_timeout  = DEFAULT_OPEN_TIMEOUT
  @logger        = Logger.new(IO::NULL)
  @allowed_hosts = DEFAULT_ALLOWED_HOSTS.dup
end

Instance Attribute Details

#allowed_hostsObject

Returns the value of attribute allowed_hosts.



17
18
19
# File 'lib/digiwin_dsp/configuration.rb', line 17

def allowed_hosts
  @allowed_hosts
end

#api_keyObject

Returns the value of attribute api_key.



17
18
19
# File 'lib/digiwin_dsp/configuration.rb', line 17

def api_key
  @api_key
end

#api_secretObject

Returns the value of attribute api_secret.



17
18
19
# File 'lib/digiwin_dsp/configuration.rb', line 17

def api_secret
  @api_secret
end

#base_urlObject



33
34
35
36
37
# File 'lib/digiwin_dsp/configuration.rb', line 33

def base_url
  url = @base_url || resolve_default_base_url
  validate_url!(url)
  url
end

#environmentObject

Returns the value of attribute environment.



17
18
19
# File 'lib/digiwin_dsp/configuration.rb', line 17

def environment
  @environment
end

#loggerObject

Returns the value of attribute logger.



17
18
19
# File 'lib/digiwin_dsp/configuration.rb', line 17

def logger
  @logger
end

#open_timeoutObject

Returns the value of attribute open_timeout.



17
18
19
# File 'lib/digiwin_dsp/configuration.rb', line 17

def open_timeout
  @open_timeout
end

#platform_idObject

Returns the value of attribute platform_id.



17
18
19
# File 'lib/digiwin_dsp/configuration.rb', line 17

def platform_id
  @platform_id
end

#timeoutObject

Returns the value of attribute timeout.



17
18
19
# File 'lib/digiwin_dsp/configuration.rb', line 17

def timeout
  @timeout
end

Instance Method Details

#validate!Object

Raises:



39
40
41
42
43
44
# File 'lib/digiwin_dsp/configuration.rb', line 39

def validate!
  return unless api_key.nil? || api_key.to_s.empty?

  raise ConfigurationError,
        "api_key is required (set via DigiwinDsp.configure or DIGIWIN_DSP_API_KEY)"
end