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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dc1b63ccb50a7452fa826049c091e5f0cd989f2060ec670b91352601eea74ef1
4
- data.tar.gz: 2edb5a28019ceb9de9081851e60b183e0fdaa03ee057340749bd40e7c1df632c
3
+ metadata.gz: 68e190d7c3fe485d068af8a08d0fc2186a5f88a88190dcc7a847502f8be41c43
4
+ data.tar.gz: 1f78480b5d3d29d2c427b1834eead05e825457afe644c6e5f9fba880d4c34b00
5
5
  SHA512:
6
- metadata.gz: 6da37664e8512e07d13780af65fe4470389b71a1f5cf902a00a17d7b55b91eebea56a73a85b59428d7159490ba0a7ffd057185e8d1b0355ae0fe3250579627f0
7
- data.tar.gz: 0ad3181e2d696bb627025f4de4fa61a4903260c83872239d693a5cb27669680b4e600d63dfeb5977ba663e7ca276125e9414fb7c824998c617a0a4b3f3eb9841
6
+ metadata.gz: 855aa75755835c002c54c99e6d6bd5bbc49d82a03181296029da3c8a27a437afdd05b40ddd88a8a69756f2ec9c7885eb703301b15857959fbd6143ff61b9d303
7
+ data.tar.gz: a79ae6b30586c97d5f3781e4ea27a28cf406df24da887717812b674e949cc5f489abc2f71048322eb46e23d377846b6bf0f860ec2b2687bd5b13154c4d416037
data/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
  # CHANGELOG.md
3
3
 
4
4
 
5
+ ## sentofu 0.5.1 released 2019-09-10
6
+
7
+ * Keep track of :_headers in result hashes
8
+ * Revise error handling
9
+
10
+
5
11
  ## sentofu 0.5.0 released 2019-08-02
6
12
 
7
13
  * Introduce Sentofu.ssl_verify_mode attr accessor
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; attr_accessor :_elapsed; end
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
- r
86
+ fail 'something went wrong' \
87
+ unless res.header['content-type'].match(/^application\/json(;|$)/)
86
88
 
87
- rescue JSON::ParserError => pe
89
+ JSON.parse(res.body)
90
+ .merge!(
91
+ _headers: res._headers,
92
+ _elapsed: res._elapsed)
88
93
 
89
- h = {}
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
- h
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
@@ -15,7 +15,7 @@ require 'sentofu/explo'
15
15
 
16
16
  module Sentofu
17
17
 
18
- VERSION = '0.5.0'
18
+ VERSION = '0.5.1'
19
19
 
20
20
  USER_AGENT =
21
21
  "Sentofu #{Sentofu::VERSION} - " +
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.0
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-08-02 00:00:00.000000000 Z
11
+ date: 2019-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec