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
63
64
# File 'lib/klepto/browser.rb', line 56

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

  #Capybara.using_driver use_driver do
    visit @url_to_structure
    page
  #end
end

#set_headers(headers) ⇒ Object

def use_driver

@use_driver || :poltergeist

end



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

#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