Class: Klepto::Browser

Inherits:
Object
  • Object
show all
Includes:
Capybara::DSL
Defined in:
lib/klepto/browser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Browser

Returns a new instance of Browser.



6
7
8
9
# File 'lib/klepto/browser.rb', line 6

def initialize(*args)
  Klepto.logger.debug("===== Initializing new browser. =====")
  super
end

Instance Attribute Details

#url_to_structureObject (readonly)

Returns the value of attribute url_to_structure.



5
6
7
# File 'lib/klepto/browser.rb', line 5

def url_to_structure
  @url_to_structure
end

Instance Method Details

#failure?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/klepto/browser.rb', line 31

def failure?
  !success?
end

#fetch!(_url) ⇒ Object



56
57
58
59
60
61
62
# File 'lib/klepto/browser.rb', line 56

def fetch!(_url)
  @url_to_structure = _url
  Klepto.logger.debug("Fetching (#{@use_driver}) #{@url_to_structure}")

  visit @url_to_structure
  page
end

#set_driver(using_driver) ⇒ Object



11
12
13
# File 'lib/klepto/browser.rb', line 11

def set_driver(using_driver)
  @use_driver = Capybara.current_driver = Capybara.javascript_driver = using_driver
end

#set_headers(headers) ⇒ Object



19
20
21
# File 'lib/klepto/browser.rb', line 19

def set_headers(headers)
  page.driver.headers = headers
end

#similar_url?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/klepto/browser.rb', line 39

def similar_url?
  @url_to_structure.downcase == page.current_url.downcase
end

#statusObject



23
24
25
# File 'lib/klepto/browser.rb', line 23

def status
  page.status_code
end

#statusesObject

Capybara automatically follows redirects… Checking the page here to see if it has changed, and if so add it on to the stack of statuses. statuses is an array because it holds the actually HTTP response code and an approximate code (2xx for example). :redirect will be pushed onto the stack if a redirect happened.



48
49
50
# File 'lib/klepto/browser.rb', line 48

def statuses
  [status, statusx]
end

#statusxObject



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

def statusx
  page.status_code.to_s[0..-3] + "xx"
end

#success?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/klepto/browser.rb', line 27

def success?
  page.status_code == 200
end

#use_driverObject



15
16
17
# File 'lib/klepto/browser.rb', line 15

def use_driver
  @use_driver || :poltergeist
end

#was_redirected?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/klepto/browser.rb', line 35

def was_redirected?
  @url_to_structure != page.current_url
end