class Undead::Driver
Constants
- DEFAULT_TIMEOUT
Attributes
options[RW]
Public Class Methods
new(options = {})
click to toggle source
# File lib/undead/driver.rb, line 11 def initialize(options = {}) @options = options headers = options.fetch(:headers, {}) end
Public Instance Methods
browser()
click to toggle source
# File lib/undead/driver.rb, line 16 def browser @browser ||= begin browser = Undead::Browser.new(server, client, logger) browser.js_errors = options[:js_errors] if options.key?(:js_errors) browser.debug = true if options[:debug] browser end end
client()
click to toggle source
# File lib/undead/driver.rb, line 29 def client @client ||= Undead::Client.start(server, :path => options[:phantomjs], :window_size => options[:window_size], :phantomjs_options => phantomjs_options, :phantomjs_logger => phantomjs_logger ) end
headers()
click to toggle source
# File lib/undead/driver.rb, line 57 def headers browser.get_headers end
headers=(headers)
click to toggle source
# File lib/undead/driver.rb, line 61 def headers=(headers) browser.set_headers(headers) end
html()
click to toggle source
# File lib/undead/driver.rb, line 69 def html browser.body end
logger()
click to toggle source
# File lib/undead/driver.rb, line 49 def logger options[:logger] || (options[:debug] && STDERR) end
phantomjs_logger()
click to toggle source
# File lib/undead/driver.rb, line 53 def phantomjs_logger options.fetch(:phantomjs_logger, nil) end
phantomjs_options()
click to toggle source
# File lib/undead/driver.rb, line 38 def phantomjs_options list = options[:phantomjs_options] || [] # PhantomJS defaults to only using SSLv3, which since POODLE (Oct 2014) # many sites have dropped from their supported protocols (eg PayPal, # Braintree). list += ["--ignore-ssl-errors=yes"] unless list.grep(/ignore-ssl-errors/).any? list += ["--ssl-protocol=TLSv1"] unless list.grep(/ssl-protocol/).any? list end
server()
click to toggle source
# File lib/undead/driver.rb, line 25 def server @server ||= Undead::Server.new(options[:port], options.fetch(:timeout) { DEFAULT_TIMEOUT }) end
visit(url)
click to toggle source
# File lib/undead/driver.rb, line 65 def visit(url) browser.visit(url) end