Class: Invoance::Config
- Inherits:
-
Object
- Object
- Invoance::Config
- Defined in:
- lib/invoance/config.rb
Overview
Resolved, immutable SDK configuration.
All fields are optional at the client boundary — when omitted the SDK reads from environment variables:
* INVOANCE_API_KEY — API key (required)
* INVOANCE_BASE_URL — API host (defaults to https://api.invoance.com)
Constant Summary collapse
- DEFAULT_BASE_URL =
"https://api.invoance.com"- DEFAULT_TIMEOUT =
30- ENV_API_KEY =
"INVOANCE_API_KEY"- ENV_BASE_URL =
"INVOANCE_BASE_URL"
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#api_version ⇒ Object
readonly
Returns the value of attribute api_version.
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#extra_headers ⇒ Object
readonly
Returns the value of attribute extra_headers.
-
#idempotency_key ⇒ Object
readonly
Returns the value of attribute idempotency_key.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
Instance Method Summary collapse
-
#initialize(api_key: nil, base_url: nil, api_version: "v1", timeout: DEFAULT_TIMEOUT, idempotency_key: nil, extra_headers: {}) ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize(api_key: nil, base_url: nil, api_version: "v1", timeout: DEFAULT_TIMEOUT, idempotency_key: nil, extra_headers: {}) ⇒ Config
Returns a new instance of Config.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/invoance/config.rb', line 25 def initialize(api_key: nil, base_url: nil, api_version: "v1", timeout: DEFAULT_TIMEOUT, idempotency_key: nil, extra_headers: {}) resolved_key = api_key || ENV[ENV_API_KEY] || "" if resolved_key.empty? raise ArgumentError, "api_key is required. Pass it explicitly or set the #{ENV_API_KEY} environment variable." end @api_key = resolved_key @base_url = (base_url || ENV[ENV_BASE_URL] || DEFAULT_BASE_URL).sub(%r{/+\z}, "") @api_version = (api_version || "v1").gsub(%r{\A/+|/+\z}, "") @timeout = timeout || DEFAULT_TIMEOUT @idempotency_key = idempotency_key @extra_headers = extra_headers || {} end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
17 18 19 |
# File 'lib/invoance/config.rb', line 17 def api_key @api_key end |
#api_version ⇒ Object (readonly)
Returns the value of attribute api_version.
17 18 19 |
# File 'lib/invoance/config.rb', line 17 def api_version @api_version end |
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
17 18 19 |
# File 'lib/invoance/config.rb', line 17 def base_url @base_url end |
#extra_headers ⇒ Object (readonly)
Returns the value of attribute extra_headers.
17 18 19 |
# File 'lib/invoance/config.rb', line 17 def extra_headers @extra_headers end |
#idempotency_key ⇒ Object (readonly)
Returns the value of attribute idempotency_key.
17 18 19 |
# File 'lib/invoance/config.rb', line 17 def idempotency_key @idempotency_key end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
17 18 19 |
# File 'lib/invoance/config.rb', line 17 def timeout @timeout end |