Class: Akephalos::Client
- Inherits:
-
Object
- Object
- Akephalos::Client
- Defined in:
- lib/akephalos/client.rb,
lib/akephalos/client/filter.rb,
lib/akephalos/client/cookies.rb
Overview
Akephalos::Client wraps HtmlUnit’s WebClient class. It is the main entry point for all interaction with the browser, exposing its current page and allowing navigation.
Defined Under Namespace
Instance Attribute Summary collapse
-
#page ⇒ Page
The current page.
Instance Method Summary collapse
-
#configuration=(config) ⇒ Hash
Set the global configuration settings for Akephalos.
-
#cookies ⇒ Cookies
The cookies for this session.
-
#initialize ⇒ Client
constructor
A new instance of Client.
-
#user_agent ⇒ String
The current user agent string.
-
#user_agent=(user_agent) ⇒ Object
Set the User-Agent header for this session.
-
#visit(url) ⇒ Page
Visit the requested URL and return the page.
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/akephalos/client.rb', line 24 def initialize @_client = java.util.concurrent.FutureTask.new do client = HtmlUnit::WebClient.new Filter.new(client) client.setThrowExceptionOnFailingStatusCode(false) client.setAjaxController(HtmlUnit::NicelyResynchronizingAjaxController.new) client.setCssErrorHandler(HtmlUnit::SilentCssErrorHandler.new) client.setThrowExceptionOnScriptError(false); client end Thread.new { @_client.run } end |
Instance Attribute Details
#page ⇒ Page
Returns the current page.
83 84 85 |
# File 'lib/akephalos/client.rb', line 83 def page @page end |
Instance Method Details
#configuration=(config) ⇒ Hash
This is only used when communicating over DRb, since just a
Set the global configuration settings for Akephalos.
single client instance is exposed.
44 45 46 |
# File 'lib/akephalos/client.rb', line 44 def configuration=(config) Akephalos.configuration = config end |
#cookies ⇒ Cookies
Returns the cookies for this session.
58 59 60 |
# File 'lib/akephalos/client.rb', line 58 def @cookies ||= Cookies.new(client.getCookieManager) end |
#user_agent ⇒ String
Returns the current user agent string.
63 64 65 |
# File 'lib/akephalos/client.rb', line 63 def user_agent @user_agent || client.getBrowserVersion.getUserAgent end |
#user_agent=(user_agent) ⇒ Object
Set the User-Agent header for this session. If :default is given, the User-Agent header will be reset to the default browser’s user agent.
72 73 74 75 76 77 78 79 80 |
# File 'lib/akephalos/client.rb', line 72 def user_agent=(user_agent) if user_agent == :default @user_agent = nil client.removeRequestHeader("User-Agent") else @user_agent = user_agent client.addRequestHeader("User-Agent", user_agent) end end |
#visit(url) ⇒ Page
Visit the requested URL and return the page.
52 53 54 55 |
# File 'lib/akephalos/client.rb', line 52 def visit(url) client.getPage(url) page end |