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 +4 -4
- data/lib/webclient/version.rb +2 -2
- data/lib/webclient/webclient.rb +24 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5691c3a408aba34be572800dcaacef7426b49c49
|
4
|
+
data.tar.gz: 80e99652e7a014a159b5d307afc9cae9cd9aa602
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80882b99915833bc9d42083c2252af6a3205ead8c1c6ddf22d2e9d7467f93379a94e005f2d6788f8731d64398b363a0b82e9a0bb50918179b5f5a3322a960c10
|
7
|
+
data.tar.gz: ebdf4df154cb51815280a753b1f26791d2d99dce586c1b3b2e037ab1b64dfdd7cea668c06736a9fc28a1ce32d6f04a84a850f7a439d3e3af5394947cf330fedd
|
data/lib/webclient/version.rb
CHANGED
data/lib/webclient/webclient.rb
CHANGED
@@ -8,16 +8,37 @@ class Webclient
|
|
8
8
|
def raw() @response; end
|
9
9
|
|
10
10
|
|
11
|
-
|
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
|
-
|
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.
|
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-
|
11
|
+
date: 2020-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rdoc
|