Class: Scruber::Helpers::ProxyRotator::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/scruber/helpers/proxy_rotator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(proxy, options = {}) ⇒ Proxy

Returns a new instance of Proxy.



8
9
10
11
12
13
14
15
16
17
# 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

Instance Attribute Details

#hostObject

Returns the value of attribute host.



6
7
8
# File 'lib/scruber/helpers/proxy_rotator.rb', line 6

def host
  @host
end

#passwordObject

Returns the value of attribute password.



6
7
8
# File 'lib/scruber/helpers/proxy_rotator.rb', line 6

def password
  @password
end

#portObject

Returns the value of attribute port.



6
7
8
# File 'lib/scruber/helpers/proxy_rotator.rb', line 6

def port
  @port
end

#probabilityObject

Returns the value of attribute probability.



6
7
8
# File 'lib/scruber/helpers/proxy_rotator.rb', line 6

def probability
  @probability
end

#typeObject

Returns the value of attribute type.



6
7
8
# File 'lib/scruber/helpers/proxy_rotator.rb', line 6

def type
  @type
end

#userObject

Returns the value of attribute user.



6
7
8
# File 'lib/scruber/helpers/proxy_rotator.rb', line 6

def user
  @user
end

Instance Method Details

#addressObject



23
24
25
# File 'lib/scruber/helpers/proxy_rotator.rb', line 23

def address
  @host + ':' + @port.to_s
end

#http?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/scruber/helpers/proxy_rotator.rb', line 27

def http?
  @type == 'http'
end

#idObject



19
20
21
# File 'lib/scruber/helpers/proxy_rotator.rb', line 19

def id
  (@host + ':' + @port.to_s)
end

#proxyuserpwdObject



31
32
33
34
35
36
37
# File 'lib/scruber/helpers/proxy_rotator.rb', line 31

def proxyuserpwd
  if @user.blank?
    nil
  else
    "#{@user}:#{@password}"
  end
end