wikk_webbrowser 0.9.5 → 0.9.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.
- checksums.yaml +4 -4
- data/History.txt +8 -0
- data/lib/wikk_webbrowser.rb +144 -122
- data/version +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b68922378ce9c4777c7810d94449ec8c4cdd738d9480b80430aa9f8829cd0d97
|
4
|
+
data.tar.gz: 33654b9c6d202036b39895c2b41facba850bfcee44e211866cca373a45443c8f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3ed4f35c54b8d96baddfe7e21afc0fdf674706daf36aa5a97a0da5717a3fb513a1bbda23c7840765b9891d314a3ff26601847272b8c146b34bf196c7c9f0534
|
7
|
+
data.tar.gz: 9bafdc4f3fd1b77d92b749b5970e224811a631a3f1fc8c9f48cbf59b07a884f8a12d9431620ef331bd8afc0e99d4cbb6a109f09c315f1e5722eb4a2ae569b680
|
data/History.txt
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
robertburrowes Mon Sep 20 12:14:31 2021 +1200
|
2
|
+
Add aliases for put,post,get and delete
|
3
|
+
robertburrowes Mon Sep 20 12:14:09 2021 +1200
|
4
|
+
Added optional form arguments to delete_req Added optional data/content arguments to delete_req
|
5
|
+
robertburrowes Sat Sep 18 17:49:31 2021 +1200
|
6
|
+
Rubocop Beautifier
|
7
|
+
robertburrowes Sat Sep 18 17:23:58 2021 +1200
|
8
|
+
Rubocop beautifier reformat
|
1
9
|
robertburrowes Wed Apr 21 19:03:05 2021 +1200
|
2
10
|
Dependency version was wrong
|
3
11
|
robertburrowes Wed Apr 21 18:54:00 2021 +1200
|
data/lib/wikk_webbrowser.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
module WIKK
|
1
|
+
module WIKK # :nodoc:
|
2
2
|
require 'net/http'
|
3
3
|
require 'net/https'
|
4
4
|
require 'uri'
|
@@ -12,18 +12,17 @@ module WIKK
|
|
12
12
|
# WIKK_WebBrowser.new.https_session(host: 'www.blah.com') do |session|
|
13
13
|
# response = get_page(query: ,'/')
|
14
14
|
# end
|
15
|
-
|
16
15
|
class WebBrowser
|
17
|
-
VERSION = '0.9.
|
18
|
-
|
19
|
-
class Error < RuntimeError
|
16
|
+
VERSION = '0.9.6'
|
17
|
+
|
18
|
+
class Error < RuntimeError # :nodoc:
|
20
19
|
attr_accessor :web_return_code
|
20
|
+
|
21
21
|
def initialize(web_return_code:, message:)
|
22
22
|
super(message)
|
23
23
|
@web_return_code = web_return_code
|
24
24
|
end
|
25
25
|
end
|
26
|
-
|
27
26
|
|
28
27
|
attr_reader :host
|
29
28
|
attr_accessor :session
|
@@ -35,7 +34,6 @@ module WIKK
|
|
35
34
|
attr_accessor :port
|
36
35
|
attr_accessor :use_ssl
|
37
36
|
attr_accessor :response
|
38
|
-
|
39
37
|
|
40
38
|
# Create a WIKK_WebBrowser instance
|
41
39
|
#
|
@@ -46,11 +44,11 @@ module WIKK
|
|
46
44
|
# @return [WIKK_WebBrowser]
|
47
45
|
#
|
48
46
|
def initialize(host:, port: nil, use_ssl: false, cookies: {}, verify_cert: true, debug: false)
|
49
|
-
@host = host
|
50
|
-
@cookies = cookies
|
47
|
+
@host = host # Need to do this, as passing nil is different to passing nothing to initialize!
|
48
|
+
@cookies = cookies.nil? ? {} : cookies
|
51
49
|
@debug = debug
|
52
50
|
@use_ssl = use_ssl
|
53
|
-
@port = port
|
51
|
+
@port = port.nil? ? ( use_ssl ? 443 : 80 ) : port
|
54
52
|
@verify_cert = verify_cert
|
55
53
|
@response = nil
|
56
54
|
end
|
@@ -78,7 +76,7 @@ module WIKK
|
|
78
76
|
# @param host [String] the host we want to connect to
|
79
77
|
# @param port [Fixnum] (443) the port the remote web server is running on
|
80
78
|
# @param verify_cert [Boolean] Validate certificate if true (Nb lots of embedded devices have self signed certs, so verify will fail)
|
81
|
-
# @param block [Proc]
|
79
|
+
# @param block [Proc]
|
82
80
|
# @yieldparam [WIKK_WebBrowser] the session descriptor for further calls.
|
83
81
|
def self.https_session(host:, port: nil, verify_cert: true, cookies: {}, debug: false)
|
84
82
|
wb = self.new(host: host, port: port, cookies: cookies, use_ssl: true, verify_cert: verify_cert, debug: debug)
|
@@ -88,62 +86,62 @@ module WIKK
|
|
88
86
|
end
|
89
87
|
|
90
88
|
# Creating a session for http connection
|
91
|
-
#
|
89
|
+
# attached block would then call get or post NET::HTTP calls
|
92
90
|
# @param port [Fixnum] Optional http server port
|
93
91
|
# @param use_ssl [Boolean] Use https, if true
|
94
92
|
# @param verify_cert [Boolean] Validate certificate if true (Nb lots of embedded devices have self signed certs, so verify will fail)
|
95
|
-
# @param block [Proc]
|
93
|
+
# @param block [Proc]
|
96
94
|
def http_session
|
97
|
-
@http = Net::HTTP.new(@host, @port)
|
95
|
+
@http = Net::HTTP.new(@host, @port)
|
98
96
|
@http.set_debug_output($stdout) if @debug
|
99
|
-
@http.use_ssl = @use_ssl
|
100
|
-
@http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
101
|
-
@http.start do |session| #ensure we close the session after the block
|
102
|
-
@session = session
|
103
|
-
yield
|
97
|
+
@http.use_ssl = @use_ssl
|
98
|
+
@http.verify_mode = OpenSSL::SSL::VERIFY_NONE if ! @use_ssl || ! @verify_cert
|
99
|
+
@http.start do |session| # ensure we close the session after the block
|
100
|
+
@session = session
|
101
|
+
yield
|
104
102
|
end
|
105
103
|
end
|
106
|
-
|
104
|
+
|
107
105
|
# Web basic authentication (not exactly secure)
|
108
106
|
# @param user [String] Account name
|
109
107
|
# @param password [String] Accounts password
|
110
108
|
# @return [String] Base64 encoded concatentation of user + ':' + password
|
111
109
|
def basic_authorization(user:, password:)
|
112
|
-
#req.basic_auth( user, password) if user != nil
|
110
|
+
# req.basic_auth( user, password) if user != nil
|
113
111
|
'Basic ' + Base64.encode64( "#{user}:#{password}" )
|
114
112
|
end
|
115
|
-
|
113
|
+
|
116
114
|
# Dropbox style token authentication
|
117
115
|
# @param token [String] Token, as issued by dropbox
|
118
116
|
# @return [String] Concatenation of 'Bearer ' + token
|
119
117
|
def bearer_authorization(token:)
|
120
|
-
|
118
|
+
'Bearer ' + token
|
121
119
|
end
|
122
|
-
|
120
|
+
|
123
121
|
# Add additional cookies
|
124
122
|
# @param cookies [Hash] cookie_name => cookie_value
|
125
123
|
def add_cookies(cookies)
|
126
124
|
cookies.each { |cookie_name, cookie_value| @cookies[cookie_name] = cookie_value }
|
127
125
|
end
|
128
|
-
|
129
|
-
# Save cookies returned by last html get/post.
|
126
|
+
|
127
|
+
# Save cookies returned by last html get/post.
|
130
128
|
# Removes previous cookies.
|
131
129
|
# @param response [Net::HTTPResponse] result from HTTP calls
|
132
130
|
def save_cookies(response)
|
133
|
-
if(cookie_lines = response.get_fields('set-cookie')) != nil
|
134
|
-
cookie_lines.each do |
|
135
|
-
cookies = cookie_line.split('; ').map { |v| v.split('=')}
|
131
|
+
if (cookie_lines = response.get_fields('set-cookie')) != nil
|
132
|
+
cookie_lines.each do |cookie_line|
|
133
|
+
cookies = cookie_line.split('; ').map { |v| v.split('=') }
|
136
134
|
cookies.each { |c| @cookies[c[0]] = c[1] }
|
137
135
|
end
|
138
136
|
end
|
139
137
|
end
|
140
|
-
|
138
|
+
|
141
139
|
# Convert @cookies to ; separated strings
|
142
140
|
# @return cookies string
|
143
141
|
def cookies_to_s
|
144
142
|
@cookies.to_a.map { |v| v.join('=') }.join('; ')
|
145
143
|
end
|
146
|
-
|
144
|
+
|
147
145
|
# Get a header value, from the last response
|
148
146
|
#
|
149
147
|
# @param key [String] header key
|
@@ -161,13 +159,13 @@ module WIKK
|
|
161
159
|
# @param extra_headers [Hash] Add these to standard headers
|
162
160
|
# @param extra_cookies [Hash] Add these to standard cookies
|
163
161
|
# @return [String] The Net::HTTPResponse.body text response from the web server
|
164
|
-
def get_page(query
|
165
|
-
$stderr.puts
|
166
|
-
query += form_values_to_s(form_values, query.index('?') != nil) #Should be using req.set_form_data, but it seems to by stripping the leading / and then the query fails.
|
167
|
-
url = URI.parse("#{@use_ssl ?
|
162
|
+
def get_page(query:, form_values: nil, authorization: nil, extra_headers: {}, extra_cookies: {})
|
163
|
+
$stderr.puts 'Debugging On' if @debug
|
164
|
+
query += form_values_to_s(form_values, query.index('?') != nil) # Should be using req.set_form_data, but it seems to by stripping the leading / and then the query fails.
|
165
|
+
url = URI.parse("#{@use_ssl ? 'https' : 'http'}://#{@host}/#{query.gsub(/^\//, '')}")
|
168
166
|
$stderr.puts url if @debug
|
169
|
-
|
170
|
-
req = Net::HTTP::Get.new(url.request_uri)
|
167
|
+
|
168
|
+
req = Net::HTTP::Get.new(url.request_uri)
|
171
169
|
|
172
170
|
header = { 'HOST' => @host }
|
173
171
|
header['Accept'] = '*/*'
|
@@ -175,41 +173,44 @@ module WIKK
|
|
175
173
|
header['Accept-Language'] = 'en-US,en;q=0.5'
|
176
174
|
header['Connection'] = 'keep-alive'
|
177
175
|
header['User-Agent'] = 'Mozilla/5.0'
|
178
|
-
header['Content-Type'] = 'application/x-www-form-urlencoded'
|
176
|
+
header['Content-Type'] = 'application/x-www-form-urlencoded'
|
179
177
|
add_cookies(extra_cookies)
|
180
178
|
header['Cookie'] = cookies_to_s if @cookies.length > 0
|
181
|
-
header['DNT'] =
|
179
|
+
header['DNT'] = '1'
|
182
180
|
header['Authorization'] = authorization if authorization != nil
|
183
181
|
|
184
|
-
extra_headers.each do |k,v|
|
182
|
+
extra_headers.each do |k, v|
|
185
183
|
header[k] = v
|
186
184
|
end
|
187
|
-
|
185
|
+
|
188
186
|
req.initialize_http_header( header )
|
189
187
|
|
190
|
-
@response = @session.request(req)
|
188
|
+
@response = @session.request(req)
|
191
189
|
save_cookies(@response)
|
192
|
-
|
190
|
+
|
193
191
|
$stderr.puts @response.code.to_i if @debug
|
194
192
|
|
195
|
-
if
|
196
|
-
if
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
193
|
+
if @response.code.to_i >= 300
|
194
|
+
if @response.code.to_i == 302
|
195
|
+
# ignore the redirects.
|
196
|
+
# $stderr.puts "302"
|
197
|
+
# @response.each {|key, val| $stderr.printf "%s = %s\n", key, val } #Location seems to have cgi params removed. End up with .../cginame?&
|
198
|
+
# $stderr.puts "Redirect to #{@response['location']}" #Location seems to have cgi params removed. End up with .../cginame?&
|
199
|
+
# $stderr.puts
|
202
200
|
return
|
203
201
|
elsif @response.code.to_i >= 400 && @response.code.to_i < 500
|
204
202
|
return @response.body
|
205
203
|
end
|
204
|
+
|
206
205
|
raise Error.new(web_return_code: @response.code.to_i, message: "#{@response.code} #{@response.message} #{query} #{form_values} #{@response.body}")
|
207
206
|
end
|
208
207
|
|
209
208
|
return @response.body
|
210
209
|
end
|
211
210
|
|
212
|
-
|
211
|
+
alias get get_page
|
212
|
+
|
213
|
+
# send a POST query to the server and return the response.
|
213
214
|
# @param query [String] URL, less the 'http://host/' part
|
214
215
|
# @param authorization [String] If present, add Authorization header, using this string
|
215
216
|
# @param content_type [String] Posted content type
|
@@ -218,9 +219,9 @@ module WIKK
|
|
218
219
|
# @param extra_cookies [Hash] Add these to standard cookies
|
219
220
|
# @return [String] The Net::HTTPResponse.body text response from the web server
|
220
221
|
def post_page(query:, authorization: nil, content_type: 'application/x-www-form-urlencoded', data: nil, extra_headers: {}, extra_cookies: {})
|
221
|
-
url = URI.parse("#{@use_ssl ?
|
222
|
+
url = URI.parse("#{@use_ssl ? 'https' : 'http'}://#{@host}/#{query}")
|
222
223
|
req = Net::HTTP::Post.new(url.path)
|
223
|
-
|
224
|
+
|
224
225
|
header = { 'HOST' => @host }
|
225
226
|
header['Accept'] = '*/*'
|
226
227
|
header['Accept-Encoding'] = 'gzip, deflate, br'
|
@@ -230,80 +231,102 @@ module WIKK
|
|
230
231
|
header['Content-Type'] = content_type
|
231
232
|
add_cookies(extra_cookies)
|
232
233
|
header['Cookie'] = cookies_to_s if @cookies.length > 0
|
233
|
-
header['DNT'] =
|
234
|
+
header['DNT'] = '1'
|
234
235
|
header['Authorization'] = authorization if authorization != nil
|
235
|
-
|
236
|
-
extra_headers.each do |k,v|
|
236
|
+
|
237
|
+
extra_headers.each do |k, v|
|
237
238
|
header[k] = v
|
238
239
|
end
|
239
240
|
req.initialize_http_header( header )
|
240
|
-
|
241
|
-
if data
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
req.set_form_data.to_j
|
247
|
-
end
|
241
|
+
|
242
|
+
if data.nil?
|
243
|
+
req.body = ''
|
244
|
+
elsif data.instance_of?(Hash)
|
245
|
+
if content_type =~ /application\/octet-stream/
|
246
|
+
req.set_form_data(data, '&')
|
248
247
|
else
|
249
|
-
req.
|
248
|
+
req.set_form_data.to_j
|
250
249
|
end
|
251
250
|
else
|
252
|
-
req.body =
|
251
|
+
req.body = data # If json as a string or raw string
|
253
252
|
end
|
254
|
-
|
253
|
+
|
255
254
|
@response = @session.request(req)
|
256
255
|
save_cookies(@response)
|
257
256
|
|
258
|
-
if
|
259
|
-
if
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
257
|
+
if @response.code.to_i >= 300
|
258
|
+
if @response.code.to_i == 302
|
259
|
+
# ignore the redirects.
|
260
|
+
# puts "302"
|
261
|
+
# @response.each {|key, val| printf "%s = %s\n", key, val } #Location seems to have cgi params removed. End up with .../cginame?&
|
262
|
+
# puts "Redirect of Post to #{@response['location']}" #Location seems to have cgi params removed. End up with .../cginame?&
|
264
263
|
return
|
265
264
|
end
|
265
|
+
|
266
266
|
raise Error.new(web_return_code: @response.code, message: "#{@response.code} #{@response.message} #{query} #{data} #{@response.body}")
|
267
267
|
end
|
268
|
-
|
268
|
+
|
269
269
|
return @response.body
|
270
270
|
end
|
271
271
|
|
272
|
-
|
272
|
+
alias post post_page
|
273
|
+
|
274
|
+
# send a DELETE query to the server and return the response.
|
273
275
|
# @param query [String] URL, less the 'http://host/' part
|
274
276
|
# @param authorization [String] If present, add Authorization header, using this string
|
277
|
+
# @param form_values [Hash{String=>Object-with-to_s}] The parameter passed to the web server eg. ?key1=value1&key2=value2...
|
278
|
+
# @param content_type [String] Posted content type. Only meaningful if there is data
|
279
|
+
# @param data [String] Text to add to body of DELETE to the web server. Not always supported at the server end.
|
275
280
|
# @param extra_headers [Hash] Add these to standard headers
|
276
281
|
# @param extra_cookies [Hash] Add these to standard cookies
|
277
282
|
# @return [String] The Net::HTTPResponse.body text response from the web server
|
278
|
-
def delete_req(query:, authorization: nil, extra_headers: {}, extra_cookies: {})
|
279
|
-
|
283
|
+
def delete_req(query:, authorization: nil, form_values: nil, content_type: '"application/octet-stream"', data: nil, extra_headers: {}, extra_cookies: {})
|
284
|
+
$stderr.puts 'Debugging On' if @debug
|
285
|
+
|
286
|
+
query += form_values_to_s(form_values, query.index('?') != nil)
|
287
|
+
url = URI.parse("#{@use_ssl ? 'https' : 'http'}://#{@host}/#{query.gsub(/^\//, '')}")
|
280
288
|
req = Net::HTTP::Delete.new(query)
|
281
|
-
|
289
|
+
|
282
290
|
header = { 'HOST' => @host }
|
283
291
|
add_cookies(extra_cookies)
|
284
292
|
header['Cookie'] = cookies_to_s if @cookies.length > 0
|
285
293
|
header['Authorization'] = authorization if authorization != nil
|
286
|
-
|
287
|
-
extra_headers.each do |k,v|
|
294
|
+
|
295
|
+
extra_headers.each do |k, v|
|
288
296
|
header[k] = v
|
289
297
|
end
|
290
298
|
req.initialize_http_header( header )
|
291
299
|
|
300
|
+
if data.nil?
|
301
|
+
req.body = ''
|
302
|
+
elsif data.instance_of?(Hash)
|
303
|
+
if content_type =~ /application\/octet-stream/
|
304
|
+
req.set_form_data(data, '&')
|
305
|
+
else
|
306
|
+
req.set_form_data.to_j
|
307
|
+
end
|
308
|
+
else
|
309
|
+
req.body = data # If json as a string or raw string
|
310
|
+
end
|
311
|
+
|
292
312
|
begin
|
293
313
|
@response = @session.request(req)
|
294
314
|
save_cookies(@response)
|
295
|
-
|
296
|
-
if
|
315
|
+
|
316
|
+
if @response.code.to_i >= 300
|
297
317
|
raise "#{url} : #{@response.code} #{@response.message}"
|
298
318
|
end
|
319
|
+
|
299
320
|
return @response.body
|
300
321
|
rescue StandardError => e
|
301
322
|
puts "#{e}"
|
302
323
|
return nil
|
303
324
|
end
|
304
325
|
end
|
305
|
-
|
306
|
-
|
326
|
+
|
327
|
+
alias delete delete_req
|
328
|
+
|
329
|
+
# send a PUT query to the server and return the response.
|
307
330
|
# @param query [String] URL, less the 'http://host/' part
|
308
331
|
# @param authorization [String] If present, add Authorization header, using this string
|
309
332
|
# @param content_type [String] Posted content type
|
@@ -312,9 +335,9 @@ module WIKK
|
|
312
335
|
# @param extra_cookies [Hash] Add these to standard cookies
|
313
336
|
# @return [String] The Net::HTTPResponse.body text response from the web server
|
314
337
|
def put_req(query:, authorization: nil, content_type: '"application/octet-stream"', data: nil, extra_headers: {}, extra_cookies: {})
|
315
|
-
url = URI.parse("#{@use_ssl ?
|
338
|
+
url = URI.parse("#{@use_ssl ? 'https' : 'http'}://#{@host}/#{query}")
|
316
339
|
req = Net::HTTP::Put.new(url.path)
|
317
|
-
|
340
|
+
|
318
341
|
header = { 'HOST' => @host }
|
319
342
|
header['Accept'] = '*/*'
|
320
343
|
header['Accept-Encoding'] = 'gzip, deflate, br'
|
@@ -324,85 +347,84 @@ module WIKK
|
|
324
347
|
header['Content-Type'] = content_type
|
325
348
|
add_cookies(extra_cookies)
|
326
349
|
header['Cookie'] = cookies_to_s if @cookies.length > 0
|
327
|
-
header['DNT'] =
|
350
|
+
header['DNT'] = '1'
|
328
351
|
header['Authorization'] = authorization if authorization != nil
|
329
|
-
|
330
|
-
extra_headers.each do |k,v|
|
352
|
+
|
353
|
+
extra_headers.each do |k, v|
|
331
354
|
header[k] = v
|
332
355
|
end
|
333
356
|
req.initialize_http_header( header )
|
334
|
-
|
335
|
-
if data
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
req.set_form_data.to_j
|
341
|
-
end
|
357
|
+
|
358
|
+
if data.nil?
|
359
|
+
req.body = ''
|
360
|
+
elsif data.instance_of?(Hash)
|
361
|
+
if content_type =~ /application\/octet-stream/
|
362
|
+
req.set_form_data(data, '&')
|
342
363
|
else
|
343
|
-
req.
|
364
|
+
req.set_form_data.to_j
|
344
365
|
end
|
345
366
|
else
|
346
|
-
req.body =
|
367
|
+
req.body = data # If json as a string or raw string
|
347
368
|
end
|
348
|
-
|
369
|
+
|
349
370
|
@response = @session.request(req)
|
350
371
|
save_cookies(@response)
|
351
372
|
|
352
|
-
if
|
353
|
-
if
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
373
|
+
if @response.code.to_i >= 300
|
374
|
+
if @response.code.to_i == 302
|
375
|
+
# ignore the redirects.
|
376
|
+
# puts "302"
|
377
|
+
# @response.each {|key, val| printf "%s = %s\n", key, val } #Location seems to have cgi params removed. End up with .../cginame?&
|
378
|
+
# puts "Redirect of Post to #{@response['location']}" #Location seems to have cgi params removed. End up with .../cginame?&
|
358
379
|
return
|
359
380
|
end
|
381
|
+
|
360
382
|
raise Error.new(web_return_code: @response.code, message: "#{@response.code} #{@response.message} #{query} #{data} #{@response.body}")
|
361
383
|
end
|
362
|
-
|
384
|
+
|
363
385
|
return @response.body
|
364
386
|
end
|
365
387
|
|
366
|
-
|
388
|
+
alias put put_req
|
389
|
+
|
390
|
+
# Extract form field values from the html body.
|
367
391
|
# @param body [String] The html response body
|
368
392
|
# @return [Hash] Keys are the field names, values are the field values
|
369
393
|
def extract_input_fields(body)
|
370
|
-
entry = true
|
371
394
|
@inputs = {}
|
372
395
|
doc = Nokogiri::HTML(body)
|
373
|
-
doc.xpath(
|
396
|
+
doc.xpath('//form/input').each do |f|
|
374
397
|
@inputs[f.get_attribute('name')] = f.get_attribute('value')
|
375
398
|
end
|
376
399
|
end
|
377
400
|
|
378
|
-
#Extract links from the html body.
|
401
|
+
# Extract links from the html body.
|
379
402
|
# @param body [String] The html response body
|
380
403
|
# @return [Hash] Keys are the link text, values are the html links
|
381
404
|
def extract_link_fields(body)
|
382
|
-
entry = true
|
383
405
|
@inputs = {}
|
384
406
|
doc = Nokogiri::HTML(body)
|
385
|
-
doc.xpath(
|
386
|
-
return URI.parse( f.get_attribute('href') ).path if
|
407
|
+
doc.xpath('//a').each do |f|
|
408
|
+
return URI.parse( f.get_attribute('href') ).path if f.get_attribute('name') == 'URL$1'
|
387
409
|
end
|
388
410
|
return nil
|
389
411
|
end
|
390
412
|
|
391
|
-
#Take a hash of the params to the post and generate a safe URL string.
|
413
|
+
# Take a hash of the params to the post and generate a safe URL string.
|
392
414
|
# @param form_values [Hash] Keys are the field names, values are the field values
|
393
415
|
# @param has_q [Boolean] We have a leading ? for the html get, so don't need to add one.
|
394
416
|
# @return [String] The 'safe' text for fields the get or post query to the web server
|
395
|
-
def form_values_to_s(form_values=nil, has_q = false)
|
396
|
-
return
|
397
|
-
|
417
|
+
def form_values_to_s(form_values = nil, has_q = false)
|
418
|
+
return '' if form_values.nil? || form_values.length == 0
|
419
|
+
|
420
|
+
s = (has_q == true ? '' : '?')
|
398
421
|
first = true
|
399
|
-
form_values.each do |key,value|
|
400
|
-
s +=
|
401
|
-
s += "#{CGI
|
422
|
+
form_values.each do |key, value|
|
423
|
+
s += '&' unless first
|
424
|
+
s += "#{CGI.escape(key.to_s)}=#{CGI.escape(value.to_s)}"
|
402
425
|
first = false
|
403
426
|
end
|
404
427
|
return s
|
405
428
|
end
|
406
429
|
end
|
407
430
|
end
|
408
|
-
|
data/version
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
PROJECT="wikk_webbrowser"
|
2
|
-
VERSION="0.9.
|
2
|
+
VERSION="0.9.6"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wikk_webbrowser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob Burrowes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-09-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -70,14 +70,14 @@ dependencies:
|
|
70
70
|
requirements:
|
71
71
|
- - "~>"
|
72
72
|
- !ruby/object:Gem::Version
|
73
|
-
version: '3.
|
73
|
+
version: '3.23'
|
74
74
|
type: :development
|
75
75
|
prerelease: false
|
76
76
|
version_requirements: !ruby/object:Gem::Requirement
|
77
77
|
requirements:
|
78
78
|
- - "~>"
|
79
79
|
- !ruby/object:Gem::Version
|
80
|
-
version: '3.
|
80
|
+
version: '3.23'
|
81
81
|
description: |-
|
82
82
|
Wrapper around ruby http and https libraries.
|
83
83
|
|