Class: BrowsingFacade

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/browsing_facade.rb,
lib/browsing_facade/version.rb

Constant Summary collapse

VERSION =
"1.1.0"

Instance Method Summary collapse

Instance Method Details

#browserObject



40
41
42
# File 'lib/browsing_facade.rb', line 40

def browser
  @browser ||= Ferrum::Browser.new(timeout: 30)
end

#cleanupObject



26
27
28
# File 'lib/browsing_facade.rb', line 26

def cleanup
  browser.reset
end

#codeObject



16
17
18
19
20
21
22
23
24
# File 'lib/browsing_facade.rb', line 16

def code
  return @override_status if @override_status

  if browser.network.traffic[0]&.response&.status == 301
    301
  else
    browser.network.status
  end
end

#quitObject



35
36
37
38
# File 'lib/browsing_facade.rb', line 35

def quit
  browser.quit
  @browser = nil
end

#redirect_toObject

If code was 301 then redirect_to will return the new url.



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

def redirect_to
  browser.network.traffic[0].response.headers["Location"]
end

#visit(url:) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/browsing_facade.rb', line 6

def visit(url:)
  @override_status = nil
  cleanup
  browser.go_to(url)
rescue Ferrum::PendingConnectionsError,
       Ferrum::TimeoutError,
       Ferrum::StatusError
  @override_status = 500
end