Module: BlackStack::BaseProxy

Included in:
Proxy, RemoteProxy
Defined in:
lib/baseproxy.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.test(proxy_str) ⇒ Object

creates new connection to google.com using Faraday lib. Uses CGI::Cookie class to parse the cookie returned in the response. It then checks for the presense of “NID” cookie set by Google. If the cookie exists, proxy server is working just fine.

references:



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/baseproxy.rb', line 14

def self.test(proxy_str)
  begin
    f = Faraday.new(:proxy => { :uri => "http://" + proxy_str})
    response = f.get "http://www.google.com"
    cookie = CGI::Cookie.parse(response.headers["set-cookie"])
    if(cookie["NID"].empty?)
      raise "#{proxy_str} is NOT working."
    else
      return true
    end
  rescue
    raise "Connection to #{proxy_str} timed out"
  end
end

Instance Method Details

#chrome_switchesObject



30
31
32
# File 'lib/baseproxy.rb', line 30

def chrome_switches
  return ["--proxy-server=#{self.ip}:#{self.port}","--proxy-user-and-password=#{self.user}:#{self.password}"]      
end

#firefox_profile_parameter(agent_name = nil, profile_name = nil) ⇒ Object

Warning: Out to Date



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/baseproxy.rb', line 35

def firefox_profile_parameter(agent_name = nil, profile_name = nil)
  if (profile_name == nil)
    profile = Selenium::WebDriver::Firefox::Profile.new
  else
    profile = Selenium::WebDriver::Firefox::Profile.from_name profile_name
  end
  
  if (agent_name!=nil)
    profile['general.useragent.override'] = agent_name
  end
  
  proxy = Selenium::WebDriver::Proxy.new(:http => self.ip.to_s+":"+self.port.to_s, :ssl => self.ip.to_s+":"+self.port.to_s)
  profile.proxy = proxy
  return profile
end

#phantomjs_switchesObject

Warning: Out to Date



52
53
54
# File 'lib/baseproxy.rb', line 52

def phantomjs_switches
  return ['--proxy='+self.ip.to_s+':'+self.port.to_s, '--proxy-auth='+self.user.to_s+':'+self.password.to_s, '--ignore-ssl-errors=yes', '--ssl-protocol=any', '--load-images=false']
end