Class: Poodle::Configuration
- Inherits:
-
Object
- Object
- Poodle::Configuration
- Defined in:
- lib/poodle/configuration.rb
Overview
Configuration class for Poodle SDK settings
Constant Summary collapse
- DEFAULT_BASE_URL =
Default API base URL
"https://api.usepoodle.com"
- DEFAULT_TIMEOUT =
Default timeout in seconds
30
- DEFAULT_CONNECT_TIMEOUT =
Default connect timeout in seconds
10
- MAX_CONTENT_SIZE =
Maximum content size in bytes (10MB)
10 * 1024 * 1024
- SDK_VERSION =
SDK version
Poodle::VERSION
Instance Attribute Summary collapse
-
#api_key ⇒ String
readonly
The API key for authentication.
-
#base_url ⇒ String
readonly
The base URL for the API.
-
#connect_timeout ⇒ Integer
readonly
The connection timeout in seconds.
-
#debug ⇒ Boolean
readonly
Whether debug mode is enabled.
-
#http_options ⇒ Hash
readonly
Additional HTTP client options.
-
#timeout ⇒ Integer
readonly
The request timeout in seconds.
Instance Method Summary collapse
-
#debug? ⇒ Boolean
Check if debug mode is enabled.
-
#initialize(**options) ⇒ Configuration
constructor
Initialize a new Configuration.
-
#url_for(endpoint) ⇒ String
Get the full URL for an endpoint.
-
#user_agent ⇒ String
Get the User-Agent string for HTTP requests.
-
#validate! ⇒ Object
private
Validate the configuration.
-
#validate_timeout!(value, field) ⇒ Object
private
Validate a timeout value.
-
#validate_url!(url, field) ⇒ Object
private
Validate a URL.
Constructor Details
#initialize(**options) ⇒ Configuration
Initialize a new Configuration
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/poodle/configuration.rb', line 70 def initialize(**) api_key = [:api_key] base_url = [:base_url] timeout = [:timeout] connect_timeout = [:connect_timeout] debug = .fetch(:debug, false) = .fetch(:http_options, {}) @api_key = api_key || ENV.fetch("POODLE_API_KEY", nil) @base_url = base_url || ENV["POODLE_BASE_URL"] || DEFAULT_BASE_URL @timeout = timeout || ENV.fetch("POODLE_TIMEOUT", DEFAULT_TIMEOUT).to_i @connect_timeout = connect_timeout || ENV.fetch("POODLE_CONNECT_TIMEOUT", DEFAULT_CONNECT_TIMEOUT).to_i @debug = debug || ENV["POODLE_DEBUG"] == "true" @http_options = validate! end |
Instance Attribute Details
#api_key ⇒ String (readonly)
Returns the API key for authentication.
40 41 42 |
# File 'lib/poodle/configuration.rb', line 40 def api_key @api_key end |
#base_url ⇒ String (readonly)
Returns the base URL for the API.
43 44 45 |
# File 'lib/poodle/configuration.rb', line 43 def base_url @base_url end |
#connect_timeout ⇒ Integer (readonly)
Returns the connection timeout in seconds.
49 50 51 |
# File 'lib/poodle/configuration.rb', line 49 def connect_timeout @connect_timeout end |
#debug ⇒ Boolean (readonly)
Returns whether debug mode is enabled.
52 53 54 |
# File 'lib/poodle/configuration.rb', line 52 def debug @debug end |
#http_options ⇒ Hash (readonly)
Returns additional HTTP client options.
55 56 57 |
# File 'lib/poodle/configuration.rb', line 55 def @http_options end |
#timeout ⇒ Integer (readonly)
Returns the request timeout in seconds.
46 47 48 |
# File 'lib/poodle/configuration.rb', line 46 def timeout @timeout end |
Instance Method Details
#debug? ⇒ Boolean
Check if debug mode is enabled
105 106 107 |
# File 'lib/poodle/configuration.rb', line 105 def debug? @debug end |
#url_for(endpoint) ⇒ String
Get the full URL for an endpoint
98 99 100 |
# File 'lib/poodle/configuration.rb', line 98 def url_for(endpoint) "#{@base_url}/#{endpoint.gsub(%r{^/}, '')}" end |
#user_agent ⇒ String
Get the User-Agent string for HTTP requests
90 91 92 |
# File 'lib/poodle/configuration.rb', line 90 def user_agent "poodle-ruby/#{SDK_VERSION} (Ruby #{RUBY_VERSION})" end |
#validate! ⇒ Object (private)
Validate the configuration
114 115 116 117 118 119 120 |
# File 'lib/poodle/configuration.rb', line 114 def validate! raise ArgumentError, "API key is required" if @api_key.nil? || @api_key.empty? validate_url!(@base_url, "base_url") validate_timeout!(@timeout, "timeout") validate_timeout!(@connect_timeout, "connect_timeout") end |
#validate_timeout!(value, field) ⇒ Object (private)
Validate a timeout value
141 142 143 |
# File 'lib/poodle/configuration.rb', line 141 def validate_timeout!(value, field) raise ArgumentError, "#{field} must be a positive integer" unless value.is_a?(Integer) && value.positive? end |
#validate_url!(url, field) ⇒ Object (private)
Validate a URL
127 128 129 130 131 132 133 134 |
# File 'lib/poodle/configuration.rb', line 127 def validate_url!(url, field) return if url.nil? || url.empty? uri = URI.parse(url) raise ArgumentError, "#{field} must be a valid HTTP or HTTPS URL" unless %w[http https].include?(uri.scheme) rescue URI::InvalidURIError raise ArgumentError, "#{field} must be a valid URL" end |