webclient 0.1.1 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6e556a9e6949903368d71f7b0eec721c772edbf5
4
- data.tar.gz: bf7fa4bf5f66eba5a31d1b5be692d09b4693ee7e
3
+ metadata.gz: 5691c3a408aba34be572800dcaacef7426b49c49
4
+ data.tar.gz: 80e99652e7a014a159b5d307afc9cae9cd9aa602
5
5
  SHA512:
6
- metadata.gz: 575883f59d791b4326d9dc88184875fb2e120a5676d946088dffc59aa9f4e493412621dc7b77e9b15c9cbb8edd611f0ad0ce25fdeae33b6248f574f9d3962a28
7
- data.tar.gz: 40a53603700a3d12a55bca74071d8dbd48ebfea04bda68b0889c5cac135aca17e82aab9ab08cdf5c24f0c749fb9f24ea3a7ca64ad154d267881ef3406897dae2
6
+ metadata.gz: 80882b99915833bc9d42083c2252af6a3205ead8c1c6ddf22d2e9d7467f93379a94e005f2d6788f8731d64398b363a0b82e9a0bb50918179b5f5a3322a960c10
7
+ data.tar.gz: ebdf4df154cb51815280a753b1f26791d2d99dce586c1b3b2e037ab1b64dfdd7cea668c06736a9fc28a1ce32d6f04a84a850f7a439d3e3af5394947cf330fedd
@@ -1,8 +1,8 @@
1
1
 
2
2
  class Webclient
3
3
  MAJOR = 0 ## todo: namespace inside version or something - why? why not??
4
- MINOR = 1
5
- PATCH = 1
4
+ MINOR = 2
5
+ PATCH = 0
6
6
  VERSION = [MAJOR,MINOR,PATCH].join('.')
7
7
 
8
8
  def self.version
@@ -8,16 +8,37 @@ class Webclient
8
8
  def raw() @response; end
9
9
 
10
10
 
11
- def text
11
+ ## todo/check: rename encoding to html/http-like charset - why? why not?
12
+ def text( encoding: 'UTF-8' )
12
13
  # note: Net::HTTP will NOT set encoding UTF-8 etc.
13
14
  # will be set to ASCII-8BIT == BINARY == Encoding Unknown; Raw Bytes Here
14
15
  # thus, set/force encoding to utf-8
15
16
  text = @response.body.to_s
16
- text = text.force_encoding( Encoding::UTF_8 )
17
+ if encoding.downcase == 'utf-8'
18
+ text = text.force_encoding( Encoding::UTF_8 )
19
+ else
20
+ ## [debug] GET=http://www.football-data.co.uk/mmz4281/0405/SC0.csv
21
+ ## Encoding::UndefinedConversionError: "\xA0" from ASCII-8BIT to UTF-8
22
+ ## note: 0xA0 (160) is NBSP (non-breaking space) in Windows-1252
23
+
24
+ ## note: assume windows encoding (for football-data.uk)
25
+ ## use "Windows-1252" for input and convert to utf-8
26
+ ##
27
+ ## see https://www.justinweiss.com/articles/3-steps-to-fix-encoding-problems-in-ruby/
28
+ ## see https://en.wikipedia.org/wiki/Windows-1252
29
+ ## txt = txt.force_encoding( 'Windows-1252' )
30
+ ## txt = txt.encode( 'UTF-8' )
31
+ ## Encoding::UTF_8 => 'UTF-8'
32
+ puts " [debug] converting response.text encoding from >#{encoding}< to >UTF-8<"
33
+
34
+ text = text.force_encoding( encoding )
35
+ text = text.encode( Encoding::UTF_8 )
36
+ end
37
+
17
38
  text
18
39
  end
19
40
 
20
- ## convenience helper; returns parsed json data
41
+ ## convenience helper; returns parsed json data; note: always assume utf-8 (text) encoding
21
42
  def json() JSON.parse( text ); end
22
43
 
23
44
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webclient
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-07 00:00:00.000000000 Z
11
+ date: 2020-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rdoc