Module: Steam

Defined in:
lib/steam/session.rb,
lib/steam.rb,
lib/steam/java.rb,
lib/steam/browser.rb,
lib/steam/process.rb,
lib/steam/request.rb,
lib/steam/version.rb,
lib/steam/response.rb,
lib/steam/connection.rb,
lib/steam/session/rails.rb,
lib/steam/connection/mock.rb,
lib/steam/connection/rails.rb,
lib/steam/browser/html_unit.rb,
lib/steam/connection/static.rb,
lib/steam/connection/net_http.rb,
lib/steam/connection/open_uri.rb,
lib/steam/browser/html_unit/drb.rb,
lib/steam/browser/html_unit/page.rb,
lib/steam/browser/html_unit/client.rb,
lib/steam/browser/html_unit/actions.rb,
lib/steam/browser/html_unit/handler.rb,
lib/steam/browser/html_unit/connection.rb,
lib/steam/browser/html_unit/web_response.rb

Overview

Mimicks the com.gargoylesoftware.htmlunit.WebRequestSettings api so it can be returned by an object that mimicks com.gargoylesoftware.htmlunit.WebConnection Not currently used in Steam, but useful for experimental stuff.

Defined Under Namespace

Modules: Browser, Connection, Java Classes: ElementNotFound, Process, Request, Response, Session

Constant Summary collapse

VERSION =
"0.0.7"

Class Method Summary collapse

Class Method Details

.configObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/steam.rb', line 19

def config
  @@config ||= {
    :request_url       => 'http://localhost',
    :server_name       => 'localhost',
    :server_port       => '3000',
    :url_scheme        => 'http',
    :charset           => 'utf-8',
    :java_load_params  => '-Xmx1024M',
    :drb_uri           => 'druby://127.0.0.1:9000',
    :html_unit => {
      :java_path         => File.expand_path("../../vendor/htmlunit-2.6/", __FILE__),
      :browser_version   => :FIREFOX_3,
      :css               => true,
      :javascript        => true,
      :resynchronize     => true,
      :js_timeout        => 5000,
      :log_level         => :warning,
      :log_incorrectness => false,
      :on_error_status   => nil, # set to :raise to raise an exception on error status, :print to print content
      :on_script_error   => nil  # set to :raise to raise an exception on javascript exceptions
    }
  }
end

.open_in_browser(filename) ⇒ Object



51
52
53
54
55
56
# File 'lib/steam.rb', line 51

def open_in_browser(filename)
  require "launchy"
  Launchy::Browser.run(filename)
rescue LoadError
  warn "Sorry, you need to install launchy to open pages: `gem install launchy`"
end

.rewrite_assets(url, html) ⇒ Object



58
59
60
61
62
# File 'lib/steam.rb', line 58

def rewrite_assets(url, html)
  url = url.gsub(URI.parse(url).path, '')
  pattern = %r(<script [^>]*src=['"]+([^'"]*)|<link[^>]* href=['"]?([^'"]+))
  html.gsub(pattern) { |path| path.gsub($1 || $2, "#{url}#{$1 || $2}") }
end

.save_and_open(url, response) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/steam.rb', line 43

def save_and_open(url, response)
  filename = "/tmp/steam/#{url.gsub(/[^\w\-\/]/, '_')}.html"
  body = rewrite_assets(url, response.body)
  FileUtils.mkdir_p(File.dirname(filename))
  File.open(filename, "w") { |f| f.write body }
  open_in_browser(filename)
end