Class: Zenrows::Proxy
- Inherits:
-
Object
- Object
- Zenrows::Proxy
- Defined in:
- lib/zenrows/proxy.rb
Overview
Builds ZenRows proxy configuration
ZenRows proxy encodes options in the password field of the proxy URL. Format: http://API_KEY-opt1=val1&opt2=val2:@host:port
Constant Summary collapse
- MAX_WAIT_MS =
Maximum wait time in milliseconds (3 minutes)
180_000- VALID_STICKY_TTL =
Valid sticky TTL values for HTTP proxy
%w[30s 5m 30m 1h 1d].freeze
- VALID_REGIONS =
Valid region codes for HTTP proxy
{ "africa" => "af", "af" => "af", "asia pacific" => "ap", "ap" => "ap", "europe" => "eu", "eu" => "eu", "middle east" => "me", "me" => "me", "north america" => "na", "na" => "na", "south america" => "sa", "sa" => "sa", "global" => nil }.freeze
Instance Attribute Summary collapse
-
#api_key ⇒ String
readonly
ZenRows API key.
-
#host ⇒ String
readonly
Proxy host.
-
#port ⇒ Integer
readonly
Proxy port.
Instance Method Summary collapse
-
#build(options = {}) ⇒ Hash
Build proxy configuration hash for HTTP client.
-
#build_array(options = {}) ⇒ Array<String, Integer, String, String>
Build proxy configuration as array [host, port, username, password].
-
#build_url(options = {}) ⇒ String
Build proxy URL string.
-
#initialize(api_key:, host:, port:) ⇒ Proxy
constructor
A new instance of Proxy.
Constructor Details
#initialize(api_key:, host:, port:) ⇒ Proxy
Returns a new instance of Proxy.
57 58 59 60 61 |
# File 'lib/zenrows/proxy.rb', line 57 def initialize(api_key:, host:, port:) @api_key = api_key @host = host @port = port end |
Instance Attribute Details
#api_key ⇒ String (readonly)
Returns ZenRows API key.
46 47 48 |
# File 'lib/zenrows/proxy.rb', line 46 def api_key @api_key end |
#host ⇒ String (readonly)
Returns Proxy host.
49 50 51 |
# File 'lib/zenrows/proxy.rb', line 49 def host @host end |
#port ⇒ Integer (readonly)
Returns Proxy port.
52 53 54 |
# File 'lib/zenrows/proxy.rb', line 52 def port @port end |
Instance Method Details
#build(options = {}) ⇒ Hash
Build proxy configuration hash for HTTP client
88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/zenrows/proxy.rb', line 88 def build( = {}) opts = .dup proxy_params = build_params(opts) { host: host, port: port, username: api_key, password: proxy_params.map { |k, v| "#{k}=#{v}" }.join("&") } end |
#build_array(options = {}) ⇒ Array<String, Integer, String, String>
Build proxy configuration as array [host, port, username, password]
114 115 116 117 |
# File 'lib/zenrows/proxy.rb', line 114 def build_array( = {}) config = build() [config[:host], config[:port], config[:username], config[:password]] end |
#build_url(options = {}) ⇒ String
Build proxy URL string
104 105 106 107 108 |
# File 'lib/zenrows/proxy.rb', line 104 def build_url( = {}) config = build() password = config[:password].empty? ? "" : config[:password] "http://#{config[:username]}:#{password}@#{config[:host]}:#{config[:port]}" end |