Class: ElevenlabsClient::Configuration
- Inherits:
-
Object
- Object
- ElevenlabsClient::Configuration
- Defined in:
- lib/elevenlabs_client/configuration.rb
Overview
Configuration management for the ElevenLabs client
Constant Summary collapse
- DEFAULT_BASE_URL =
"https://api.elevenlabs.io"- DEFAULT_API_KEY_ENV =
"ELEVENLABS_API_KEY"- DEFAULT_BASE_URL_ENV =
"ELEVENLABS_BASE_URL"
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#api_key_env ⇒ Object
Returns the value of attribute api_key_env.
-
#base_url ⇒ Object
Returns the value of attribute base_url.
-
#base_url_env ⇒ Object
Returns the value of attribute base_url_env.
-
#log_level ⇒ Object
Returns the value of attribute log_level.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
-
#retry_count ⇒ Object
Returns the value of attribute retry_count.
-
#retry_delay ⇒ Object
Returns the value of attribute retry_delay.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#user_agent ⇒ Object
Returns the value of attribute user_agent.
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#reset! ⇒ Object
Reset configuration to defaults.
-
#resolved_api_key ⇒ Object
Get API key from configuration, environment, or Settings.
-
#resolved_base_url ⇒ Object
Get base URL from configuration, environment, or Settings.
-
#to_h ⇒ Object
Create a hash representation of the configuration.
-
#validate! ⇒ Object
Validate configuration.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/elevenlabs_client/configuration.rb', line 13 def initialize @api_key = nil @base_url = DEFAULT_BASE_URL @api_key_env = DEFAULT_API_KEY_ENV @base_url_env = DEFAULT_BASE_URL_ENV @timeout = 30 @open_timeout = 10 @retry_count = 3 @retry_delay = 1 @user_agent = "ElevenlabsClient/#{ElevenlabsClient::VERSION}" @logger = nil @log_level = :info end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
10 11 12 |
# File 'lib/elevenlabs_client/configuration.rb', line 10 def api_key @api_key end |
#api_key_env ⇒ Object
Returns the value of attribute api_key_env.
10 11 12 |
# File 'lib/elevenlabs_client/configuration.rb', line 10 def api_key_env @api_key_env end |
#base_url ⇒ Object
Returns the value of attribute base_url.
10 11 12 |
# File 'lib/elevenlabs_client/configuration.rb', line 10 def base_url @base_url end |
#base_url_env ⇒ Object
Returns the value of attribute base_url_env.
10 11 12 |
# File 'lib/elevenlabs_client/configuration.rb', line 10 def base_url_env @base_url_env end |
#log_level ⇒ Object
Returns the value of attribute log_level.
10 11 12 |
# File 'lib/elevenlabs_client/configuration.rb', line 10 def log_level @log_level end |
#logger ⇒ Object
Returns the value of attribute logger.
10 11 12 |
# File 'lib/elevenlabs_client/configuration.rb', line 10 def logger @logger end |
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
10 11 12 |
# File 'lib/elevenlabs_client/configuration.rb', line 10 def open_timeout @open_timeout end |
#retry_count ⇒ Object
Returns the value of attribute retry_count.
10 11 12 |
# File 'lib/elevenlabs_client/configuration.rb', line 10 def retry_count @retry_count end |
#retry_delay ⇒ Object
Returns the value of attribute retry_delay.
10 11 12 |
# File 'lib/elevenlabs_client/configuration.rb', line 10 def retry_delay @retry_delay end |
#timeout ⇒ Object
Returns the value of attribute timeout.
10 11 12 |
# File 'lib/elevenlabs_client/configuration.rb', line 10 def timeout @timeout end |
#user_agent ⇒ Object
Returns the value of attribute user_agent.
10 11 12 |
# File 'lib/elevenlabs_client/configuration.rb', line 10 def user_agent @user_agent end |
Instance Method Details
#reset! ⇒ Object
Reset configuration to defaults
91 92 93 |
# File 'lib/elevenlabs_client/configuration.rb', line 91 def reset! initialize end |
#resolved_api_key ⇒ Object
Get API key from configuration, environment, or Settings
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/elevenlabs_client/configuration.rb', line 28 def resolved_api_key return @api_key if @api_key # Try Settings first if Settings.properties&.dig(:elevenlabs_api_key) return Settings.elevenlabs_api_key end # Then try environment variable env_key = ENV.fetch(@api_key_env) do raise AuthenticationError, "#{@api_key_env} environment variable is required but not set and " \ "Settings.properties[:elevenlabs_api_key] is not configured" end env_key end |
#resolved_base_url ⇒ Object
Get base URL from configuration, environment, or Settings
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/elevenlabs_client/configuration.rb', line 47 def resolved_base_url return @base_url if @base_url != DEFAULT_BASE_URL # Try Settings first if Settings.properties&.dig(:elevenlabs_base_uri) return Settings.elevenlabs_base_uri end # Then try environment variable, with default fallback ENV.fetch(@base_url_env, DEFAULT_BASE_URL) end |
#to_h ⇒ Object
Create a hash representation of the configuration
77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/elevenlabs_client/configuration.rb', line 77 def to_h { api_key: api_key ? "[REDACTED]" : nil, base_url: resolved_base_url, timeout: timeout, open_timeout: open_timeout, retry_count: retry_count, retry_delay: retry_delay, user_agent: user_agent, log_level: log_level } end |
#validate! ⇒ Object
Validate configuration
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/elevenlabs_client/configuration.rb', line 60 def validate! resolved_api_key # This will raise if API key is missing unless resolved_base_url.match?(/\Ahttps?:\/\//) raise ArgumentError, "Invalid base URL: #{resolved_base_url}" end unless timeout.is_a?(Numeric) && timeout > 0 raise ArgumentError, "Timeout must be a positive number" end unless retry_count.is_a?(Integer) && retry_count >= 0 raise ArgumentError, "Retry count must be a non-negative integer" end end |