Class: LetMeSendEmail::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/letmesendemail/config.rb

Overview

Validated client configuration.

Constant Summary collapse

DEFAULT_BASE_URL =
'https://letmesend.email/api/v1'
DEFAULT_TIMEOUT_MS =
30_000
DEFAULT_RETRIES =
0
MAX_RETRIES =
20

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key) ⇒ Config

Returns a new instance of Config.

Parameters:

  • api_key (String)

    API bearer token



17
18
19
20
21
22
# File 'lib/letmesendemail/config.rb', line 17

def initialize(api_key)
  @api_key = api_key
  @base_url = DEFAULT_BASE_URL
  @timeout_ms = DEFAULT_TIMEOUT_MS
  @retries = DEFAULT_RETRIES
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



14
15
16
# File 'lib/letmesendemail/config.rb', line 14

def api_key
  @api_key
end

#base_urlObject

Returns the value of attribute base_url.



13
14
15
# File 'lib/letmesendemail/config.rb', line 13

def base_url
  @base_url
end

#retriesObject

Returns the value of attribute retries.



14
15
16
# File 'lib/letmesendemail/config.rb', line 14

def retries
  @retries
end

#timeout_msObject

Returns the value of attribute timeout_ms.



14
15
16
# File 'lib/letmesendemail/config.rb', line 14

def timeout_ms
  @timeout_ms
end

Instance Method Details

#validate!self

Validates and normalizes configuration before use.

Returns:

  • (self)

Raises:

  • (ArgumentError)

    for unsafe or unsupported configuration



33
34
35
36
37
38
39
40
41
# File 'lib/letmesendemail/config.rb', line 33

def validate!
  validate_api_key!
  validate_base_url!
  validate_timeout!
  validate_retries!
  @api_key = api_key.dup.freeze
  @base_url = base_url.dup.freeze
  self
end