Class: Walinko::Configuration

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

Overview

Immutable configuration captured by ‘Walinko::Client.new`. Validates required fields and applies defaults.

Constant Summary collapse

DEFAULT_BASE_URL =
'https://api.walinko.com'
DEFAULT_TIMEOUT =
30
DEFAULT_OPEN_TIMEOUT =
10
DEFAULT_MAX_RETRIES =
2

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key:, base_url: DEFAULT_BASE_URL, timeout: DEFAULT_TIMEOUT, open_timeout: DEFAULT_OPEN_TIMEOUT, max_retries: DEFAULT_MAX_RETRIES, logger: nil) ⇒ Configuration

Returns a new instance of Configuration.

Parameters:

  • api_key (String)

    required, e.g. “walk_live_<keyId>.<secret>”

  • base_url (String) (defaults to: DEFAULT_BASE_URL)

    defaults to “api.walinko.com

  • timeout (Integer) (defaults to: DEFAULT_TIMEOUT)

    per-request read timeout in seconds

  • open_timeout (Integer) (defaults to: DEFAULT_OPEN_TIMEOUT)

    TCP/TLS connection-setup timeout in seconds

  • max_retries (Integer) (defaults to: DEFAULT_MAX_RETRIES)

    retries on idempotent failures (network, 429, 5xx)

  • logger (#info, #warn, #error) (defaults to: nil)

    optional structured logger

Raises:

  • (ArgumentError)


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/walinko/configuration.rb', line 21

def initialize(api_key:,
               base_url:     DEFAULT_BASE_URL,
               timeout:      DEFAULT_TIMEOUT,
               open_timeout: DEFAULT_OPEN_TIMEOUT,
               max_retries:  DEFAULT_MAX_RETRIES,
               logger:       nil)
  raise ArgumentError, 'api_key is required' if api_key.nil? || api_key.to_s.empty?
  raise ArgumentError, 'base_url is required' if base_url.nil? || base_url.to_s.empty?
  raise ArgumentError, 'timeout must be > 0' if timeout.to_i <= 0
  raise ArgumentError, 'open_timeout must be > 0' if open_timeout.to_i <= 0
  raise ArgumentError, 'max_retries must be >= 0' if max_retries.to_i.negative?

  @api_key      = api_key.to_s
  @base_url     = base_url.to_s.sub(%r{/+$}, '')
  @timeout      = timeout.to_i
  @open_timeout = open_timeout.to_i
  @max_retries  = max_retries.to_i
  @logger       = logger
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



12
13
14
# File 'lib/walinko/configuration.rb', line 12

def api_key
  @api_key
end

#base_urlObject (readonly)

Returns the value of attribute base_url.



12
13
14
# File 'lib/walinko/configuration.rb', line 12

def base_url
  @base_url
end

#loggerObject (readonly)

Returns the value of attribute logger.



12
13
14
# File 'lib/walinko/configuration.rb', line 12

def logger
  @logger
end

#max_retriesObject (readonly)

Returns the value of attribute max_retries.



12
13
14
# File 'lib/walinko/configuration.rb', line 12

def max_retries
  @max_retries
end

#open_timeoutObject (readonly)

Returns the value of attribute open_timeout.



12
13
14
# File 'lib/walinko/configuration.rb', line 12

def open_timeout
  @open_timeout
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



12
13
14
# File 'lib/walinko/configuration.rb', line 12

def timeout
  @timeout
end