steam 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,9 +10,10 @@ module Steam
|
|
10
10
|
class HtmlUnit
|
11
11
|
autoload :Actions, 'steam/browser/html_unit/actions'
|
12
12
|
autoload :Client, 'steam/browser/html_unit/client'
|
13
|
+
autoload :Connection, 'steam/browser/html_unit/connection'
|
13
14
|
autoload :Drb, 'steam/browser/html_unit/drb'
|
14
15
|
autoload :Forker, 'steam/browser/html_unit/forker'
|
15
|
-
autoload :
|
16
|
+
autoload :Handler, 'steam/browser/html_unit/handler'
|
16
17
|
autoload :Matchers, 'steam/browser/html_unit/matchers'
|
17
18
|
autoload :Page, 'steam/browser/html_unit/page'
|
18
19
|
autoload :WebResponse, 'steam/browser/html_unit/web_response'
|
@@ -71,6 +72,26 @@ module Steam
|
|
71
72
|
Locator.within(response.body, *args, &block)
|
72
73
|
end
|
73
74
|
|
75
|
+
def set_handler(type, &block) # TODO use delegate
|
76
|
+
@client.set_handler(type, &block)
|
77
|
+
end
|
78
|
+
|
79
|
+
def remove_handler(type)
|
80
|
+
@client.remove_handler(type)
|
81
|
+
end
|
82
|
+
|
83
|
+
def get_cookie(name)
|
84
|
+
@client.get_cookie(name)
|
85
|
+
end
|
86
|
+
|
87
|
+
def add_cookie(name, value)
|
88
|
+
@client.add_cookie(name, value)
|
89
|
+
end
|
90
|
+
|
91
|
+
def clear_cookies
|
92
|
+
@client.clear_cookies
|
93
|
+
end
|
94
|
+
|
74
95
|
protected
|
75
96
|
|
76
97
|
def respond_to
|
@@ -13,6 +13,8 @@ module Steam
|
|
13
13
|
Java.import 'com.gargoylesoftware.htmlunit.BrowserVersion'
|
14
14
|
Java.import 'com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController'
|
15
15
|
Java.import 'com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException'
|
16
|
+
Java.import 'org.apache.commons.httpclient.Cookie', 'Java::Com::Gargoylesoftware::Htmlunit::Cookie'
|
17
|
+
# Java.import 'com.gargoylesoftware.htmlunit.util.Cookie'
|
16
18
|
|
17
19
|
include Java::Com::Gargoylesoftware::Htmlunit
|
18
20
|
|
@@ -20,10 +22,11 @@ module Steam
|
|
20
22
|
def notify(message, origin); end
|
21
23
|
end
|
22
24
|
|
23
|
-
attr_reader :connection
|
25
|
+
attr_reader :connection, :handlers
|
24
26
|
|
25
27
|
def initialize(connection = nil, options = {})
|
26
28
|
@connection = connection
|
29
|
+
@handlers = {}
|
27
30
|
options = Steam.config[:html_unit].merge(options)
|
28
31
|
|
29
32
|
@java = WebClient.new(BrowserVersion.send(options[:browser_version]))
|
@@ -53,11 +56,11 @@ module Steam
|
|
53
56
|
def get(request)
|
54
57
|
perform(self.request_settings(request))
|
55
58
|
end
|
56
|
-
|
59
|
+
|
57
60
|
def perform(request_settings)
|
58
61
|
@java._invoke('getPage', 'Lcom.gargoylesoftware.htmlunit.WebRequestSettings;', request_settings)
|
59
62
|
end
|
60
|
-
|
63
|
+
|
61
64
|
def request_settings(request)
|
62
65
|
url = Java::Net::Url.new(request.url)
|
63
66
|
settings = WebRequestSettings.new(url)
|
@@ -70,7 +73,30 @@ module Steam
|
|
70
73
|
yield if block_given?
|
71
74
|
end
|
72
75
|
|
73
|
-
|
76
|
+
def set_handler(type, &block)
|
77
|
+
@java.send(:"set#{type.to_s.camelize}Handler", Handler.create(type, block))
|
78
|
+
end
|
79
|
+
|
80
|
+
def remove_handler(type)
|
81
|
+
@java.send(:"set#{type.to_s.camelize}Handler", nil)
|
82
|
+
end
|
83
|
+
|
84
|
+
def get_cookie(name)
|
85
|
+
cookie = @java.getCookieManager.getCookie(name)
|
86
|
+
cookie ? cookie.getValue : nil
|
87
|
+
end
|
88
|
+
|
89
|
+
def add_cookie(name, value) # TODO what about domain, path, expires etc?
|
90
|
+
cookie = Cookie.new
|
91
|
+
cookie.setName(name)
|
92
|
+
cookie.setValue(value)
|
93
|
+
@java.getCookieManager.addCookie(cookie)
|
94
|
+
end
|
95
|
+
|
96
|
+
def clear_cookies
|
97
|
+
@java.getCookieManager.clearCookies
|
98
|
+
end
|
99
|
+
|
74
100
|
def log_level=(level)
|
75
101
|
[ 'com.gargoylesoftware.htmlunit',
|
76
102
|
'com.gargoylesoftware.htmlunit.html',
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Steam
|
2
|
+
module Browser
|
3
|
+
class HtmlUnit
|
4
|
+
module Handler
|
5
|
+
class << self
|
6
|
+
def create(type, proc)
|
7
|
+
type = type.to_s.camelize
|
8
|
+
handler = self.const_get(type).new(proc)
|
9
|
+
Rjb::bind(handler, "com.gargoylesoftware.htmlunit.#{type}Handler")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class Base
|
14
|
+
attr_reader :proc
|
15
|
+
|
16
|
+
def initialize(proc)
|
17
|
+
@proc = proc
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class Alert < Base
|
22
|
+
def handleAlert(page, message)
|
23
|
+
proc.call(page, message)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class Confirm < Base
|
28
|
+
def handleConfirm(page, message)
|
29
|
+
result = proc.call(page, message)
|
30
|
+
result.nil? || !!result
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/steam/version.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 6
|
9
|
+
version: 0.0.6
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Sven Fuchs
|
@@ -65,6 +65,7 @@ files:
|
|
65
65
|
- lib/steam/browser/html_unit/client.rb
|
66
66
|
- lib/steam/browser/html_unit/connection.rb
|
67
67
|
- lib/steam/browser/html_unit/drb.rb
|
68
|
+
- lib/steam/browser/html_unit/handler.rb
|
68
69
|
- lib/steam/browser/html_unit/page.rb
|
69
70
|
- lib/steam/browser/html_unit/web_response.rb
|
70
71
|
- lib/steam/browser/html_unit.rb
|