Class: Steam::Browser::HtmlUnit::Client
- Inherits:
-
Object
- Object
- Steam::Browser::HtmlUnit::Client
- Includes:
- Java::Com::Gargoylesoftware::Htmlunit
- Defined in:
- lib/steam/browser/html_unit/client.rb
Defined Under Namespace
Classes: SilencingListener
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Instance Method Summary collapse
- #get(request) ⇒ Object
-
#initialize(connection = nil, options = {}) ⇒ Client
constructor
A new instance of Client.
-
#log_level=(level) ⇒ Object
FIXME setLevel throws “Fail: unknown method name ‘setLevel’”.
- #method_missing(method, *args) ⇒ Object
- #perform(request_settings) ⇒ Object
- #request_settings(request) ⇒ Object
- #wait_for_javascript(timeout) ⇒ Object
Constructor Details
#initialize(connection = nil, options = {}) ⇒ Client
Returns a new instance of Client.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/steam/browser/html_unit/client.rb', line 25 def initialize(connection = nil, = {}) @connection = connection = Steam.config[:html_unit].merge() @java = WebClient.new(BrowserVersion.send([:browser_version])) @java.setCssEnabled([:css]) @java.setJavaScriptEnabled([:javascript]) @java.setPrintContentOnFailingStatusCode([:on_error_status] == :print) @java.setThrowExceptionOnFailingStatusCode([:on_error_status] == :raise) @java.setThrowExceptionOnScriptError([:on_script_error] == :raise) self.log_level = [:log_level] unless [:log_incorrectness] listener = Rjb::bind(SilencingListener.new, 'com.gargoylesoftware.htmlunit.IncorrectnessListener') @java.setIncorrectnessListener(listener) end if [:resynchronize] controller = NicelyResynchronizingAjaxController.new @java.setAjaxController(controller) end if connection connection = Rjb::bind(HtmlUnit::Connection.new(connection), 'com.gargoylesoftware.htmlunit.WebConnection') @java.setWebConnection(connection) end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
83 84 85 |
# File 'lib/steam/browser/html_unit/client.rb', line 83 def method_missing(method, *args) @java.send(method, *args) end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
23 24 25 |
# File 'lib/steam/browser/html_unit/client.rb', line 23 def connection @connection end |
Instance Method Details
#get(request) ⇒ Object
53 54 55 |
# File 'lib/steam/browser/html_unit/client.rb', line 53 def get(request) perform(self.request_settings(request)) end |
#log_level=(level) ⇒ Object
FIXME setLevel throws “Fail: unknown method name ‘setLevel’”. weird.
74 75 76 77 78 79 80 81 |
# File 'lib/steam/browser/html_unit/client.rb', line 74 def log_level=(level) [ 'com.gargoylesoftware.htmlunit', 'com.gargoylesoftware.htmlunit.html', 'com.gargoylesoftware.htmlunit.javascript', 'org.apache.commons.httpclient' ].each { |classifier| Java.logger(classifier).setLevel(Java.log_level(level)) } end |
#perform(request_settings) ⇒ Object
57 58 59 |
# File 'lib/steam/browser/html_unit/client.rb', line 57 def perform(request_settings) @java._invoke('getPage', 'Lcom.gargoylesoftware.htmlunit.WebRequestSettings;', request_settings) end |
#request_settings(request) ⇒ Object
61 62 63 64 65 66 |
# File 'lib/steam/browser/html_unit/client.rb', line 61 def request_settings(request) url = Java::Net::Url.new(request.url) settings = WebRequestSettings.new(url) request.headers.each { |name, value| settings.setAdditionalHeader(name.to_s, value.to_s) } if request.headers settings end |
#wait_for_javascript(timeout) ⇒ Object
68 69 70 71 |
# File 'lib/steam/browser/html_unit/client.rb', line 68 def wait_for_javascript(timeout) waitForBackgroundJavaScript(timeout) yield if block_given? end |