wikk_webbrowser 0.9.6 → 0.9.8

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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/History.txt +12 -0
  3. data/lib/wikk_webbrowser.rb +72 -10
  4. data/version +1 -1
  5. metadata +5 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b68922378ce9c4777c7810d94449ec8c4cdd738d9480b80430aa9f8829cd0d97
4
- data.tar.gz: 33654b9c6d202036b39895c2b41facba850bfcee44e211866cca373a45443c8f
3
+ metadata.gz: 97d467b1c73719e5792766843f0022dfc1e3b66aa6f80d5627cce822c295a6a2
4
+ data.tar.gz: 8c7bbc76ec4290ed8277beb7a624f9c9a4b4db95ac362a4c22d29790608f093d
5
5
  SHA512:
6
- metadata.gz: a3ed4f35c54b8d96baddfe7e21afc0fdf674706daf36aa5a97a0da5717a3fb513a1bbda23c7840765b9891d314a3ff26601847272b8c146b34bf196c7c9f0534
7
- data.tar.gz: 9bafdc4f3fd1b77d92b749b5970e224811a631a3f1fc8c9f48cbf59b07a884f8a12d9431620ef331bd8afc0e99d4cbb6a109f09c315f1e5722eb4a2ae569b680
6
+ metadata.gz: b6dde99ae5e31f08eefc8a06abb4cb55e7778af435523199a03e50d5bdc62bbdcb249c1a7e9e5c54aa91c13c86e2cf1ac668ab1ef0478dd9df42d71863b6ac26
7
+ data.tar.gz: 92575280201954924c2aa9eb1da7ab424939ba3a204ea6046dc7ca6a21620f1b637750dd086eb24a332aa7e4910dc589e9afa786d464ffde3f11b7dce121ffb4
data/History.txt CHANGED
@@ -1,3 +1,15 @@
1
+ robertburrowes Tue Sep 20 11:54:06 2022 +1200
2
+ Fix broken post, when we should be converting 'data' into json, but weren't
3
+ robertburrowes Mon Jun 13 17:53:47 2022 +1200
4
+ use bash
5
+ robertburrowes Mon Jun 13 13:46:47 2022 +1200
6
+ scripts should be bash
7
+ robertburrowes Mon Jun 13 12:22:50 2022 +1200
8
+ comment
9
+ robertburrowes Sun May 15 10:06:52 2022 +1200
10
+ Push tags too
11
+ robertburrowes Mon May 9 17:02:06 2022 +1200
12
+ Duplicated Put, changing all Puts to Patch
1
13
  robertburrowes Mon Sep 20 12:14:31 2021 +1200
2
14
  Add aliases for put,post,get and delete
3
15
  robertburrowes Mon Sep 20 12:14:09 2021 +1200
@@ -1,4 +1,5 @@
1
- module WIKK # :nodoc:
1
+ # Stay in our own namespace
2
+ module WIKK
2
3
  require 'net/http'
3
4
  require 'net/https'
4
5
  require 'uri'
@@ -13,7 +14,7 @@ module WIKK # :nodoc:
13
14
  # response = get_page(query: ,'/')
14
15
  # end
15
16
  class WebBrowser
16
- VERSION = '0.9.6'
17
+ VERSION = '0.9.8'
17
18
 
18
19
  class Error < RuntimeError # :nodoc:
19
20
  attr_accessor :web_return_code
@@ -241,14 +242,14 @@ module WIKK # :nodoc:
241
242
 
242
243
  if data.nil?
243
244
  req.body = ''
244
- elsif data.instance_of?(Hash)
245
- if content_type =~ /application\/octet-stream/
246
- req.set_form_data(data, '&')
247
- else
248
- req.set_form_data.to_j
249
- end
250
- else
251
- req.body = data # If json as a string or raw string
245
+ elsif data.instance_of?(String)
246
+ req.body = data # If we are given a String, just use it as is
247
+ elsif content_type =~ /application\/json/
248
+ req.body = data.to_j # Encode data as json. It wasn't already a String.
249
+ elsif content_type =~ /application\/octet-stream/ && (data.instance_of?(Hash) || data.instance_of?(Array))
250
+ req.set_form_data(data, '&') # Should handle Array as multiple entries with the same key, and Hash
251
+ else # Assuming data can become a string that makes sense to the other end
252
+ req.body = data.to_s # raw string
252
253
  end
253
254
 
254
255
  @response = @session.request(req)
@@ -387,6 +388,67 @@ module WIKK # :nodoc:
387
388
 
388
389
  alias put put_req
389
390
 
391
+ # send a PATCH query to the server and return the response.
392
+ # @param query [String] URL, less the 'http://host/' part
393
+ # @param authorization [String] If present, add Authorization header, using this string
394
+ # @param content_type [String] Posted content type
395
+ # @param data [String] Text to add to body of post to the web server
396
+ # @param extra_headers [Hash] Add these to standard headers
397
+ # @param extra_cookies [Hash] Add these to standard cookies
398
+ # @return [String] The Net::HTTPResponse.body text response from the web server
399
+ def patch_req(query:, authorization: nil, content_type: '"application/octet-stream"', data: nil, extra_headers: {}, extra_cookies: {})
400
+ url = URI.parse("#{@use_ssl ? 'https' : 'http'}://#{@host}/#{query}")
401
+ req = Net::HTTP::Patch.new(url.path)
402
+
403
+ header = { 'HOST' => @host }
404
+ header['Accept'] = '*/*'
405
+ header['Accept-Encoding'] = 'gzip, deflate, br'
406
+ header['Accept-Language'] = 'en-US,en;q=0.5'
407
+ header['Connection'] = 'keep-alive'
408
+ header['User-Agent'] = 'Mozilla/5.0'
409
+ header['Content-Type'] = content_type
410
+ add_cookies(extra_cookies)
411
+ header['Cookie'] = cookies_to_s if @cookies.length > 0
412
+ header['DNT'] = '1'
413
+ header['Authorization'] = authorization if authorization != nil
414
+
415
+ extra_headers.each do |k, v|
416
+ header[k] = v
417
+ end
418
+ req.initialize_http_header( header )
419
+
420
+ if data.nil?
421
+ req.body = ''
422
+ elsif data.instance_of?(Hash)
423
+ if content_type =~ /application\/octet-stream/
424
+ req.set_form_data(data, '&')
425
+ else
426
+ req.set_form_data.to_j
427
+ end
428
+ else
429
+ req.body = data # If json as a string or raw string
430
+ end
431
+
432
+ @response = @session.request(req)
433
+ save_cookies(@response)
434
+
435
+ if @response.code.to_i >= 300
436
+ if @response.code.to_i == 302
437
+ # ignore the redirects.
438
+ # puts "302"
439
+ # @response.each {|key, val| printf "%s = %s\n", key, val } #Location seems to have cgi params removed. End up with .../cginame?&
440
+ # puts "Redirect of Post to #{@response['location']}" #Location seems to have cgi params removed. End up with .../cginame?&
441
+ return
442
+ end
443
+
444
+ raise Error.new(web_return_code: @response.code, message: "#{@response.code} #{@response.message} #{query} #{data} #{@response.body}")
445
+ end
446
+
447
+ return @response.body
448
+ end
449
+
450
+ alias patch patch_req
451
+
390
452
  # Extract form field values from the html body.
391
453
  # @param body [String] The html response body
392
454
  # @return [Hash] Keys are the field names, values are the field values
data/version CHANGED
@@ -1,2 +1,2 @@
1
1
  PROJECT="wikk_webbrowser"
2
- VERSION="0.9.6"
2
+ VERSION="0.9.8"
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.6
4
+ version: 0.9.8
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-09-20 00:00:00.000000000 Z
11
+ date: 2022-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.23'
73
+ version: '3.25'
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.23'
80
+ version: '3.25'
81
81
  description: |-
82
82
  Wrapper around ruby http and https libraries.
83
83
 
@@ -122,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
122
  - !ruby/object:Gem::Version
123
123
  version: '0'
124
124
  requirements: []
125
- rubygems_version: 3.1.4
125
+ rubygems_version: 3.3.7
126
126
  signing_key:
127
127
  specification_version: 4
128
128
  summary: Wrapper around ruby http and https libraries