Class: ProxyService::MechanizeAgent

Inherits:
Mechanize
  • Object
show all
Defined in:
lib/proxy_service/mechanize_agent.rb

Constant Summary collapse

USER_AGENT_ALIASES =
['Windows Mozilla', 'Mac Safari', 'Mac FireFox', 'Mac Mozilla', 'Linux Mozilla', 'Linux Firefox']

Instance Method Summary collapse

Constructor Details

#initializeMechanizeAgent

Returns a new instance of MechanizeAgent.



6
7
8
9
10
11
12
13
14
15
# File 'lib/proxy_service/mechanize_agent.rb', line 6

def initialize
  super Mechanize.new do |mech|
    mech.open_timeout = 10
    mech.read_timeout = 10
    mech.follow_meta_refresh = true
    mech.keep_alive = true
    mech.max_history = 1
    mech.user_agent_alias = USER_AGENT_ALIASES.sample
  end
end

Instance Method Details

#set_proxy(proxy) ⇒ Object

Note:

proxy.ip should only be nil in the case where it’s held by a NullWorker

Parameters:

  • proxy (#ip, #port)

    object that holds the ip and port



19
20
21
22
# File 'lib/proxy_service/mechanize_agent.rb', line 19

def set_proxy(proxy)
  return unless proxy.ip
  __getobj__.set_proxy(proxy.ip, proxy.port, ProxyService.username, ProxyService.password)
end