Class: DigiwinDsp::Configuration
- Inherits:
-
Object
- Object
- DigiwinDsp::Configuration
- 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
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#api_secret ⇒ Object
Returns the value of attribute api_secret.
- #base_url ⇒ Object
-
#environment ⇒ Object
Returns the value of attribute environment.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
-
#platform_id ⇒ Object
Returns the value of attribute platform_id.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #validate! ⇒ Object
Constructor Details
#initialize ⇒ Configuration
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.fetch("DIGIWIN_DSP_API_KEY", nil) @api_secret = ENV.fetch("DIGIWIN_DSP_API_SECRET", nil) @platform_id = ENV.fetch("DIGIWIN_DSP_PLATFORM_ID", nil) @environment = ENV.fetch("DIGIWIN_DSP_ENV", "sandbox").to_sym @base_url = ENV.fetch("DIGIWIN_DSP_BASE_URL", nil) @timeout = DEFAULT_TIMEOUT @open_timeout = DEFAULT_OPEN_TIMEOUT @logger = Logger.new(IO::NULL) end |
Instance Attribute Details
#api_key ⇒ Object
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_secret ⇒ Object
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_url ⇒ Object
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 |
#environment ⇒ Object
Returns the value of attribute environment.
15 16 17 |
# File 'lib/digiwin_dsp/configuration.rb', line 15 def environment @environment end |
#logger ⇒ Object
Returns the value of attribute logger.
15 16 17 |
# File 'lib/digiwin_dsp/configuration.rb', line 15 def logger @logger end |
#open_timeout ⇒ Object
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_id ⇒ Object
Returns the value of attribute platform_id.
15 16 17 |
# File 'lib/digiwin_dsp/configuration.rb', line 15 def platform_id @platform_id end |
#timeout ⇒ Object
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
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 |