Class: Walinko::Configuration
- Inherits:
-
Object
- Object
- Walinko::Configuration
- 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
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#max_retries ⇒ Object
readonly
Returns the value of attribute max_retries.
-
#open_timeout ⇒ Object
readonly
Returns the value of attribute open_timeout.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
Instance Method Summary collapse
-
#initialize(api_key:, base_url: DEFAULT_BASE_URL, timeout: DEFAULT_TIMEOUT, open_timeout: DEFAULT_OPEN_TIMEOUT, max_retries: DEFAULT_MAX_RETRIES, logger: nil) ⇒ Configuration
constructor
A new instance of Configuration.
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.
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_key ⇒ Object (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_url ⇒ Object (readonly)
Returns the value of attribute base_url.
12 13 14 |
# File 'lib/walinko/configuration.rb', line 12 def base_url @base_url end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
12 13 14 |
# File 'lib/walinko/configuration.rb', line 12 def logger @logger end |
#max_retries ⇒ Object (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_timeout ⇒ Object (readonly)
Returns the value of attribute open_timeout.
12 13 14 |
# File 'lib/walinko/configuration.rb', line 12 def open_timeout @open_timeout end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
12 13 14 |
# File 'lib/walinko/configuration.rb', line 12 def timeout @timeout end |