Class: Tavily::Configuration
- Inherits:
-
Object
- Object
- Tavily::Configuration
- Defined in:
- lib/tavily/configuration.rb
Overview
Holds configuration for a Client. A global instance is available via configuration / configure; individual clients may override any value through keyword arguments to Tavily::Client#initialize.
Constant Summary collapse
- DEFAULT_BASE_URL =
Default Tavily REST API base URL.
"https://api.tavily.com"- DEFAULT_TIMEOUT =
Default read timeout, in seconds.
60- DEFAULT_OPEN_TIMEOUT =
Default connection-open timeout, in seconds.
10- DEFAULT_MAX_RETRIES =
Default number of automatic retries for transient failures.
2- DEFAULT_RETRY_BASE_DELAY =
Base delay (seconds) for exponential backoff between retries.
0.5
Instance Attribute Summary collapse
-
#api_key ⇒ String?
Tavily API key (e.g. “tvly-…”).
-
#base_url ⇒ String
API base URL.
-
#ca_file ⇒ String?
Path to a PEM CA-certificate bundle.
-
#logger ⇒ Logger?
Optional logger for request/response diagnostics.
-
#max_retries ⇒ Integer
Maximum number of retries for transient errors.
-
#open_timeout ⇒ Numeric
Open timeout in seconds.
-
#proxy ⇒ String?
Proxy URL (e.g. “user:pass@host:port”).
-
#retry_base_delay ⇒ Numeric
Base delay for exponential backoff, in seconds.
-
#timeout ⇒ Numeric
Read timeout in seconds.
-
#user_agent ⇒ String
User-Agent header sent with every request.
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#to_h ⇒ Hash
A shallow copy of the configuration as a hash.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/tavily/configuration.rb', line 42 def initialize @api_key = ENV.fetch("TAVILY_API_KEY", nil) @base_url = ENV.fetch("TAVILY_BASE_URL", DEFAULT_BASE_URL) @timeout = Float(ENV.fetch("TAVILY_TIMEOUT", DEFAULT_TIMEOUT)) @open_timeout = DEFAULT_OPEN_TIMEOUT @max_retries = Integer(ENV.fetch("TAVILY_MAX_RETRIES", DEFAULT_MAX_RETRIES)) @retry_base_delay = DEFAULT_RETRY_BASE_DELAY @proxy = ENV.fetch("TAVILY_PROXY", nil) @ca_file = ENV.fetch("SSL_CERT_FILE", nil) @logger = nil @user_agent = "tavily-ruby/#{Tavily::VERSION}" end |
Instance Attribute Details
#api_key ⇒ String?
Returns Tavily API key (e.g. “tvly-…”).
20 21 22 |
# File 'lib/tavily/configuration.rb', line 20 def api_key @api_key end |
#base_url ⇒ String
Returns API base URL.
22 23 24 |
# File 'lib/tavily/configuration.rb', line 22 def base_url @base_url end |
#ca_file ⇒ String?
Returns path to a PEM CA-certificate bundle. Defaults to ENV. Handy on Windows, where some Ruby builds ship without a usable default certificate store.
36 37 38 |
# File 'lib/tavily/configuration.rb', line 36 def ca_file @ca_file end |
#logger ⇒ Logger?
Returns optional logger for request/response diagnostics.
38 39 40 |
# File 'lib/tavily/configuration.rb', line 38 def logger @logger end |
#max_retries ⇒ Integer
Returns maximum number of retries for transient errors.
28 29 30 |
# File 'lib/tavily/configuration.rb', line 28 def max_retries @max_retries end |
#open_timeout ⇒ Numeric
Returns open timeout in seconds.
26 27 28 |
# File 'lib/tavily/configuration.rb', line 26 def open_timeout @open_timeout end |
#proxy ⇒ String?
Returns proxy URL (e.g. “user:pass@host:port”).
32 33 34 |
# File 'lib/tavily/configuration.rb', line 32 def proxy @proxy end |
#retry_base_delay ⇒ Numeric
Returns base delay for exponential backoff, in seconds.
30 31 32 |
# File 'lib/tavily/configuration.rb', line 30 def retry_base_delay @retry_base_delay end |
#timeout ⇒ Numeric
Returns read timeout in seconds.
24 25 26 |
# File 'lib/tavily/configuration.rb', line 24 def timeout @timeout end |
#user_agent ⇒ String
Returns User-Agent header sent with every request.
40 41 42 |
# File 'lib/tavily/configuration.rb', line 40 def user_agent @user_agent end |
Instance Method Details
#to_h ⇒ Hash
Returns a shallow copy of the configuration as a hash.
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/tavily/configuration.rb', line 56 def to_h { base_url: base_url, timeout: timeout, open_timeout: open_timeout, max_retries: max_retries, retry_base_delay: retry_base_delay, proxy: proxy, ca_file: ca_file, user_agent: user_agent } end |