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
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.



18
19
20
21
22
23
24
25
26
27
# File 'lib/digiwin_dsp/configuration.rb', line 18

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)
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



15
16
17
# File 'lib/digiwin_dsp/configuration.rb', line 15

def api_key
  @api_key
end

#api_secretObject

Returns the value of attribute api_secret.



15
16
17
# File 'lib/digiwin_dsp/configuration.rb', line 15

def api_secret
  @api_secret
end

#base_urlObject



29
30
31
32
33
34
35
36
# File 'lib/digiwin_dsp/configuration.rb', line 29

def base_url
  return @base_url if @base_url

  BASE_URLS.fetch(environment) do
    raise ConfigurationError,
          "unknown environment #{environment.inspect}; expected one of #{BASE_URLS.keys.inspect}"
  end
end

#environmentObject

Returns the value of attribute environment.



15
16
17
# File 'lib/digiwin_dsp/configuration.rb', line 15

def environment
  @environment
end

#loggerObject

Returns the value of attribute logger.



15
16
17
# File 'lib/digiwin_dsp/configuration.rb', line 15

def logger
  @logger
end

#open_timeoutObject

Returns the value of attribute open_timeout.



15
16
17
# File 'lib/digiwin_dsp/configuration.rb', line 15

def open_timeout
  @open_timeout
end

#platform_idObject

Returns the value of attribute platform_id.



15
16
17
# File 'lib/digiwin_dsp/configuration.rb', line 15

def platform_id
  @platform_id
end

#timeoutObject

Returns the value of attribute timeout.



15
16
17
# File 'lib/digiwin_dsp/configuration.rb', line 15

def timeout
  @timeout
end

Instance Method Details

#validate!Object

Raises:



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

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