Class: Undead::Driver
- Inherits:
-
Object
- Object
- Undead::Driver
- Defined in:
- lib/undead/driver.rb
Constant Summary collapse
- DEFAULT_TIMEOUT =
30
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #browser ⇒ Object
- #client ⇒ Object
- #headers ⇒ Object
- #headers=(headers) ⇒ Object
- #html ⇒ Object
-
#initialize(options = {}) ⇒ Driver
constructor
A new instance of Driver.
- #logger ⇒ Object
- #phantomjs_logger ⇒ Object
- #phantomjs_options ⇒ Object
- #server ⇒ Object
- #visit(url) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Driver
Returns a new instance of Driver.
11 12 13 14 |
# File 'lib/undead/driver.rb', line 11 def initialize( = {}) @options = headers = .fetch(:headers, {}) end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
9 10 11 |
# File 'lib/undead/driver.rb', line 9 def @options end |
Instance Method Details
#browser ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/undead/driver.rb', line 16 def browser @browser ||= begin browser = Undead::Browser.new(server, client, logger) browser.js_errors = [:js_errors] if .key?(:js_errors) browser.debug = true if [:debug] browser end end |
#client ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/undead/driver.rb', line 29 def client @client ||= Undead::Client.start(server, :path => [:phantomjs], :window_size => [:window_size], :phantomjs_options => , :phantomjs_logger => phantomjs_logger ) end |
#headers ⇒ Object
57 58 59 |
# File 'lib/undead/driver.rb', line 57 def headers browser.get_headers end |
#headers=(headers) ⇒ Object
61 62 63 |
# File 'lib/undead/driver.rb', line 61 def headers=(headers) browser.set_headers(headers) end |
#html ⇒ Object
69 70 71 |
# File 'lib/undead/driver.rb', line 69 def html browser.body end |
#logger ⇒ Object
49 50 51 |
# File 'lib/undead/driver.rb', line 49 def logger [:logger] || ([:debug] && STDERR) end |
#phantomjs_logger ⇒ Object
53 54 55 |
# File 'lib/undead/driver.rb', line 53 def phantomjs_logger .fetch(:phantomjs_logger, nil) end |
#phantomjs_options ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/undead/driver.rb', line 38 def list = [: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 ⇒ Object
25 26 27 |
# File 'lib/undead/driver.rb', line 25 def server @server ||= Undead::Server.new([:port], .fetch(:timeout) { DEFAULT_TIMEOUT }) end |
#visit(url) ⇒ Object
65 66 67 |
# File 'lib/undead/driver.rb', line 65 def visit(url) browser.visit(url) end |