class Scruber::Helpers::ProxyRotator::Proxy

Attributes

host[RW]
password[RW]
port[RW]
probability[RW]
type[RW]
user[RW]

Public Class Methods

new(proxy, options={}) click to toggle source
# File lib/scruber/helpers/proxy_rotator.rb, line 8
def initialize(proxy, options={})
  @host = proxy.split(':', 2).first
  raise Scruber::ArgumentError.new("You need to specify proxy address") if @host.blank?
  @port = options.fetch(:port) { proxy.split(':', 2)[1] }.to_i rescue nil
  raise Scruber::ArgumentError.new("You need to specify :port for this proxy or pass full proxy address like 127.0.0.1:100") if @port.nil? || @port.zero?
  @type = options.fetch(:type) { 'http' }
  @user = options.fetch(:user) { nil }
  @password = options.fetch(:password) { nil }
  @probability = options.fetch(:probability) { 1 }
end

Public Instance Methods

address() click to toggle source
# File lib/scruber/helpers/proxy_rotator.rb, line 23
def address
  @host + ':' + @port.to_s
end
http?() click to toggle source
# File lib/scruber/helpers/proxy_rotator.rb, line 27
def http?
  @type == 'http'
end
id() click to toggle source
# File lib/scruber/helpers/proxy_rotator.rb, line 19
def id
  (@host + ':' + @port.to_s)
end
proxyuserpwd() click to toggle source
# File lib/scruber/helpers/proxy_rotator.rb, line 31
def proxyuserpwd
  if @user.blank?
    nil
  else
    "#{@user}:#{@password}"
  end
end