Class: Zenrows::Client
- Inherits:
-
Object
- Object
- Zenrows::Client
- Defined in:
- lib/zenrows/client.rb
Overview
Main client for ZenRows proxy
The client builds configured HTTP clients that route through the ZenRows proxy with specified options.
Instance Attribute Summary collapse
-
#backend ⇒ Backends::Base
readonly
HTTP backend instance.
-
#config ⇒ Configuration
readonly
Client configuration.
-
#hooks ⇒ Hooks
readonly
Hook registry for this client.
-
#proxy ⇒ Proxy
readonly
Proxy builder instance.
Instance Method Summary collapse
-
#http(options = {}) ⇒ HTTP::Client
Build a configured HTTP client.
-
#initialize(api_key: nil, host: nil, port: nil, backend: nil) {|config| ... } ⇒ Client
constructor
Initialize a new client.
-
#proxy_config(options = {}) ⇒ Hash
Get proxy configuration for given options.
-
#proxy_url(options = {}) ⇒ String
Get proxy URL for given options.
-
#ssl_context ⇒ OpenSSL::SSL::SSLContext
Get SSL context for proxy connections.
Constructor Details
#initialize(api_key: nil, host: nil, port: nil, backend: nil) {|config| ... } ⇒ Client
Initialize a new client
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/zenrows/client.rb', line 57 def initialize(api_key: nil, host: nil, port: nil, backend: nil, &block) @config = build_config(api_key: api_key, host: host, port: port, backend: backend) @config.validate! # Build hooks: start with global, allow per-client additions @hooks = block ? build_hooks(&block) : Zenrows.configuration.hooks.dup @proxy = Proxy.new( api_key: @config.api_key, host: @config.host, port: @config.port ) @backend = build_backend end |
Instance Attribute Details
#backend ⇒ Backends::Base (readonly)
Returns HTTP backend instance.
38 39 40 |
# File 'lib/zenrows/client.rb', line 38 def backend @backend end |
#config ⇒ Configuration (readonly)
Returns Client configuration.
32 33 34 |
# File 'lib/zenrows/client.rb', line 32 def config @config end |
#hooks ⇒ Hooks (readonly)
Returns Hook registry for this client.
41 42 43 |
# File 'lib/zenrows/client.rb', line 41 def hooks @hooks end |
#proxy ⇒ Proxy (readonly)
Returns Proxy builder instance.
35 36 37 |
# File 'lib/zenrows/client.rb', line 35 def proxy @proxy end |
Instance Method Details
#http(options = {}) ⇒ HTTP::Client
Build a configured HTTP client
100 101 102 |
# File 'lib/zenrows/client.rb', line 100 def http( = {}) backend.build_client() end |
#proxy_config(options = {}) ⇒ Hash
Get proxy configuration for given options
119 120 121 |
# File 'lib/zenrows/client.rb', line 119 def proxy_config( = {}) proxy.build() end |
#proxy_url(options = {}) ⇒ String
Get proxy URL for given options
127 128 129 |
# File 'lib/zenrows/client.rb', line 127 def proxy_url( = {}) proxy.build_url() end |
#ssl_context ⇒ OpenSSL::SSL::SSLContext
Get SSL context for proxy connections
ZenRows proxy requires SSL verification to be disabled. This is automatically applied when using #http, but exposed for advanced use cases.
111 112 113 |
# File 'lib/zenrows/client.rb', line 111 def ssl_context backend.ssl_context end |