sentofu 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/sentofu/http.rb +19 -12
- data/lib/sentofu.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68e190d7c3fe485d068af8a08d0fc2186a5f88a88190dcc7a847502f8be41c43
|
4
|
+
data.tar.gz: 1f78480b5d3d29d2c427b1834eead05e825457afe644c6e5f9fba880d4c34b00
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 855aa75755835c002c54c99e6d6bd5bbc49d82a03181296029da3c8a27a437afdd05b40ddd88a8a69756f2ec9c7885eb703301b15857959fbd6143ff61b9d303
|
7
|
+
data.tar.gz: a79ae6b30586c97d5f3781e4ea27a28cf406df24da887717812b674e949cc5f489abc2f71048322eb46e23d377846b6bf0f860ec2b2687bd5b13154c4d416037
|
data/CHANGELOG.md
CHANGED
data/lib/sentofu/http.rb
CHANGED
@@ -70,7 +70,10 @@ module Sentofu
|
|
70
70
|
|
71
71
|
res = http.request(req)
|
72
72
|
|
73
|
-
class << res
|
73
|
+
class << res
|
74
|
+
attr_accessor :_elapsed
|
75
|
+
def _headers; each_header.inject({}) { |h, (k, v)| h[k] = v; h }; end
|
76
|
+
end
|
74
77
|
res._elapsed = monow - t0
|
75
78
|
|
76
79
|
res
|
@@ -79,21 +82,25 @@ module Sentofu
|
|
79
82
|
def get_and_parse(uri, token=nil)
|
80
83
|
|
81
84
|
res = get(uri, token)
|
82
|
-
r = JSON.parse(res.body)
|
83
|
-
r[:_elapsed] = res._elapsed
|
84
85
|
|
85
|
-
|
86
|
+
fail 'something went wrong' \
|
87
|
+
unless res.header['content-type'].match(/^application\/json(;|$)/)
|
86
88
|
|
87
|
-
|
89
|
+
JSON.parse(res.body)
|
90
|
+
.merge!(
|
91
|
+
_headers: res._headers,
|
92
|
+
_elapsed: res._elapsed)
|
88
93
|
|
89
|
-
|
90
|
-
h[:code] = res.code.to_i
|
91
|
-
h[:message] = WEBrick::HTTPStatus.reason_phrase(res.code)
|
92
|
-
h[:error_class] = pe.class.to_s
|
93
|
-
h[:error_message] = pe.message
|
94
|
-
h[:body] = res.body unless res.body.index('</html>')
|
94
|
+
rescue => e
|
95
95
|
|
96
|
-
|
96
|
+
{ uri: uri,
|
97
|
+
code: res.code.to_i,
|
98
|
+
headers: res._headers,
|
99
|
+
message: WEBrick::HTTPStatus.reason_phrase(res.code),
|
100
|
+
error_class: e.class.to_s,
|
101
|
+
error_message: e.message,
|
102
|
+
error_trace: e.backtrace,
|
103
|
+
body: (res.body.index('</html>') ? '<html>' : res.body) }
|
97
104
|
end
|
98
105
|
|
99
106
|
protected
|
data/lib/sentofu.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sentofu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Mettraux
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-09-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|