Class: Zenrows::Configuration
- Inherits:
-
Object
- Object
- Zenrows::Configuration
- Includes:
- MonitorMixin
- Defined in:
- lib/zenrows/configuration.rb
Overview
Global configuration for Zenrows client
Constant Summary collapse
- DEFAULTS =
Default configuration values
{ host: "superproxy.zenrows.com", port: 1337, api_endpoint: "https://api.zenrows.com/v1/", connect_timeout: 5, read_timeout: 180, backend: :http_rb }.freeze
Instance Attribute Summary collapse
-
#api_endpoint ⇒ String
ZenRows API endpoint for ApiClient.
-
#api_key ⇒ String?
ZenRows API key (required).
-
#backend ⇒ Symbol
HTTP backend to use (:http_rb, :faraday, :net_http).
-
#connect_timeout ⇒ Integer
Default connection timeout in seconds.
-
#host ⇒ String
ZenRows proxy host.
-
#logger ⇒ Logger?
Logger instance for debug output.
-
#port ⇒ Integer
ZenRows proxy port.
-
#read_timeout ⇒ Integer
Default read timeout in seconds.
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#reset! ⇒ void
Reset configuration to defaults.
-
#to_h ⇒ Hash
Convert configuration to hash.
-
#valid? ⇒ Boolean
Check if configuration is valid.
-
#validate! ⇒ true
Validate that required configuration is present.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
58 59 60 61 |
# File 'lib/zenrows/configuration.rb', line 58 def initialize super # Initialize MonitorMixin reset! end |
Instance Attribute Details
#api_endpoint ⇒ String
Returns ZenRows API endpoint for ApiClient.
46 47 48 |
# File 'lib/zenrows/configuration.rb', line 46 def api_endpoint @api_endpoint end |
#api_key ⇒ String?
Returns ZenRows API key (required).
25 26 27 |
# File 'lib/zenrows/configuration.rb', line 25 def api_key @api_key end |
#backend ⇒ Symbol
Returns HTTP backend to use (:http_rb, :faraday, :net_http).
40 41 42 |
# File 'lib/zenrows/configuration.rb', line 40 def backend @backend end |
#connect_timeout ⇒ Integer
Returns Default connection timeout in seconds.
34 35 36 |
# File 'lib/zenrows/configuration.rb', line 34 def connect_timeout @connect_timeout end |
#host ⇒ String
Returns ZenRows proxy host.
28 29 30 |
# File 'lib/zenrows/configuration.rb', line 28 def host @host end |
#logger ⇒ Logger?
Returns Logger instance for debug output.
43 44 45 |
# File 'lib/zenrows/configuration.rb', line 43 def logger @logger end |
#port ⇒ Integer
Returns ZenRows proxy port.
31 32 33 |
# File 'lib/zenrows/configuration.rb', line 31 def port @port end |
#read_timeout ⇒ Integer
Returns Default read timeout in seconds.
37 38 39 |
# File 'lib/zenrows/configuration.rb', line 37 def read_timeout @read_timeout end |
Instance Method Details
#reset! ⇒ void
This method returns an undefined value.
Reset configuration to defaults
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/zenrows/configuration.rb', line 66 def reset! synchronize do @api_key = nil @host = DEFAULTS[:host] @port = DEFAULTS[:port] @api_endpoint = DEFAULTS[:api_endpoint] @connect_timeout = DEFAULTS[:connect_timeout] @read_timeout = DEFAULTS[:read_timeout] @backend = DEFAULTS[:backend] @logger = nil end end |
#to_h ⇒ Hash
Convert configuration to hash
102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/zenrows/configuration.rb', line 102 def to_h { api_key: api_key, host: host, port: port, api_endpoint: api_endpoint, connect_timeout: connect_timeout, read_timeout: read_timeout, backend: backend } end |
#valid? ⇒ Boolean
Check if configuration is valid
92 93 94 95 96 97 |
# File 'lib/zenrows/configuration.rb', line 92 def valid? validate! true rescue ConfigurationError false end |
#validate! ⇒ true
Validate that required configuration is present
83 84 85 86 87 |
# File 'lib/zenrows/configuration.rb', line 83 def validate! raise ConfigurationError, "api_key is required" if api_key.nil? || api_key.empty? true end |