Class: ProxyService::MechanizeAgent
- Inherits:
-
Mechanize
- Object
- Mechanize
- ProxyService::MechanizeAgent
- 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
-
#initialize ⇒ MechanizeAgent
constructor
A new instance of MechanizeAgent.
- #set_proxy(proxy) ⇒ Object
Constructor Details
#initialize ⇒ MechanizeAgent
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. = 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
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 |