sentofu 0.5.0 → 0.5.5

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
  SHA256:
3
- metadata.gz: dc1b63ccb50a7452fa826049c091e5f0cd989f2060ec670b91352601eea74ef1
4
- data.tar.gz: 2edb5a28019ceb9de9081851e60b183e0fdaa03ee057340749bd40e7c1df632c
3
+ metadata.gz: a22c27c7dbd12ccf93283de4c58bb65497a17638d013929ad1557a91c1dfac2b
4
+ data.tar.gz: 037d542183584b6ced637afafbae8fc98febf971413dc5846fbff6fbbd44cad5
5
5
  SHA512:
6
- metadata.gz: 6da37664e8512e07d13780af65fe4470389b71a1f5cf902a00a17d7b55b91eebea56a73a85b59428d7159490ba0a7ffd057185e8d1b0355ae0fe3250579627f0
7
- data.tar.gz: 0ad3181e2d696bb627025f4de4fa61a4903260c83872239d693a5cb27669680b4e600d63dfeb5977ba663e7ca276125e9414fb7c824998c617a0a4b3f3eb9841
6
+ metadata.gz: 23f8ed539f585372700227f4f42b947166d55f47b80ad180fb08e6ccc7eeeb1dd0a2e1031b1dea9915b8583b79ee63b7380e113c090d93b95c1910804bea7a23
7
+ data.tar.gz: e6526c9c327d68c8b27e0b8ad8b1c7bd02d8a8a66c9f7cd5936622a342efcd8bc7733df572ee0c4229530fed8480062f876f3796249032f15d068032fc2e60d4
@@ -2,6 +2,32 @@
2
2
  # CHANGELOG.md
3
3
 
4
4
 
5
+ ## sentofu 0.5.5 released 2020-09-25
6
+
7
+ * Report _uri and _proxy along _headers in response
8
+
9
+
10
+ ## sentofu 0.5.4 released 2020-06-03
11
+
12
+ * Prevent failure on missing GET parameters list
13
+
14
+
15
+ ## sentofu 0.5.3 released 2019-11-07
16
+
17
+ * Tighten request error interception
18
+
19
+
20
+ ## sentofu 0.5.2 released 2019-09-27
21
+
22
+ * Tighten request error interception
23
+
24
+
25
+ ## sentofu 0.5.1 released 2019-09-10
26
+
27
+ * Keep track of :_headers in result hashes
28
+ * Revise error handling
29
+
30
+
5
31
  ## sentofu 0.5.0 released 2019-08-02
6
32
 
7
33
  * Introduce Sentofu.ssl_verify_mode attr accessor
@@ -1,5 +1,5 @@
1
1
 
2
- Copyright (c) 2019-2019, John Mettraux, jmettraux+flor@gmail.com
2
+ Copyright (c) 2019-2020, John Mettraux, jmettraux@gmail.com
3
3
 
4
4
  Permission is hereby granted, free of charge, to any person obtaining a copy
5
5
  of this software and associated documentation files (the "Software"), to deal
data/Makefile CHANGED
@@ -31,7 +31,7 @@ build: gemspec_validate
31
31
  mv $(NAME)-$(VERSION).gem pkg/
32
32
 
33
33
  push: build
34
- gem push pkg/$(NAME)-$(VERSION).gem
34
+ gem push --otp "$(OTP)" pkg/$(NAME)-$(VERSION).gem
35
35
 
36
36
  spec:
37
37
  bundle exec rspec
@@ -15,7 +15,7 @@ require 'sentofu/explo'
15
15
 
16
16
  module Sentofu
17
17
 
18
- VERSION = '0.5.0'
18
+ VERSION = '0.5.5'
19
19
 
20
20
  USER_AGENT =
21
21
  "Sentofu #{Sentofu::VERSION} - " +
@@ -102,7 +102,7 @@ module Sentofu
102
102
  end
103
103
  h }
104
104
 
105
- point['get']['parameters']
105
+ (point['get']['parameters'] || [])
106
106
  .each { |par|
107
107
 
108
108
  next if par['in'] != 'query'
@@ -146,7 +146,15 @@ module Sentofu
146
146
 
147
147
  def initialize(name, spec)
148
148
 
149
- super(nil, spec['servers'].first['url'])
149
+ u = spec['servers'].first['url'] rescue nil
150
+ unless u.is_a?(String) && u.match?(/\Ahttps?:\/\//)
151
+ #p name; pp spec; p u
152
+ c = spec['code'] rescue -1
153
+ m = spec['message'] rescue '(no message)'
154
+ fail "cannot setup #{name.inspect} API - HTTP #{c} - #{m.inspect}"
155
+ end
156
+
157
+ super(nil, u)
150
158
 
151
159
  @name = name
152
160
  @spec = spec
@@ -33,10 +33,19 @@ module Sentofu
33
33
  puts
34
34
 
35
35
  list_apis.each do |h|
36
- n = h['n']; n = "auth" if n.match(/auth/i)
36
+
37
+ n =
38
+ case nn = h['n']
39
+ when /auth/i then 'auth'
40
+ when /ESG Score API/ then 'escore'
41
+ else nn
42
+ end
43
+
37
44
  fn = "api_#{n}_#{h['v']}.yaml"
45
+
38
46
  res = Sentofu::Http.get(h['u'] + '/swagger.yaml')
39
47
  File.open(fn, 'wb') { |f| f.write(res.body) }
48
+
40
49
  puts " wrote #{fn}"
41
50
  end
42
51
  end
@@ -66,12 +66,20 @@ module Sentofu
66
66
  t0 = monow
67
67
 
68
68
  http = make_net_http(u)
69
- #t.set_debug_output($stdout) if u.to_s.match(/search/)
69
+ #t.set_debug_output($stdout) if u.to_s.match?(/search/)
70
70
 
71
71
  res = http.request(req)
72
72
 
73
- class << res; attr_accessor :_elapsed; end
73
+ class << res
74
+ attr_accessor :_uri, :_elapsed, :_proxy
75
+ def _headers; each_header.inject({}) { |h, (k, v)| h[k] = v; h }; end
76
+ end
77
+ res._uri = uri.to_s
74
78
  res._elapsed = monow - t0
79
+ res._proxy = detail_proxy(http)
80
+
81
+ fail "request returned a #{res.class} and not a Net::HTTPResponse" \
82
+ unless res.is_a?(Net::HTTPResponse)
75
83
 
76
84
  res
77
85
  end
@@ -79,21 +87,27 @@ module Sentofu
79
87
  def get_and_parse(uri, token=nil)
80
88
 
81
89
  res = get(uri, token)
82
- r = JSON.parse(res.body)
83
- r[:_elapsed] = res._elapsed
84
-
85
- r
86
-
87
- rescue JSON::ParserError => pe
88
90
 
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>')
95
-
96
- h
91
+ fail 'something went wrong' \
92
+ unless res.header['content-type'].match?(/^application\/json(;|$)/)
93
+
94
+ JSON.parse(res.body)
95
+ .merge!(
96
+ _uri: res._uri,
97
+ _headers: res._headers,
98
+ _elapsed: res._elapsed,
99
+ _proxy: res._proxy)
100
+
101
+ rescue => err
102
+
103
+ { uri: uri,
104
+ code: (res.code.to_i rescue nil),
105
+ headers: (res._headers rescue nil),
106
+ message: (WEBrick::HTTPStatus.reason_phrase(res.code) rescue nil),
107
+ error_class: err.class.to_s,
108
+ error_message: err.message,
109
+ error_trace: err.backtrace,
110
+ body: ((res.body.index('</html>') ? '<html>' : res.body) rescue nil) }
97
111
  end
98
112
 
99
113
  protected
@@ -129,6 +143,17 @@ module Sentofu
129
143
 
130
144
  OpenStruct.new(YAML.load(File.read(fname)))
131
145
  end
146
+
147
+ def detail_proxy(http)
148
+
149
+ if http.proxy_address
150
+ { address: http.proxy_address,
151
+ port: http.proxy_port,
152
+ user: http.proxy_user }
153
+ else
154
+ nil
155
+ end
156
+ end
132
157
  end
133
158
  end
134
159
 
@@ -138,7 +163,19 @@ module Sentofu
138
163
 
139
164
  @h = JSON.parse(res.body)
140
165
  @h[:_elapsed] = res._elapsed
141
- @expires_at = Time.now + @h['expires_in']
166
+ @h[:_proxy] = res._proxy
167
+
168
+ @expires_at = @h['expires_in'] ? Time.now + @h['expires_in'] : 0
169
+ end
170
+
171
+ def errors
172
+
173
+ @h['errors'] || []
174
+ end
175
+
176
+ def sound?
177
+
178
+ errors.empty?
142
179
  end
143
180
 
144
181
  def not_expired?
@@ -148,7 +185,7 @@ module Sentofu
148
185
 
149
186
  def header_value
150
187
 
151
- 'Bearer ' + @h['access_token']
188
+ "Bearer #{@h['access_token'] || 'SENTOFU_INVALID_TOKEN_:-('}"
152
189
  end
153
190
  end
154
191
  end
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.5
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: 2020-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -64,8 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
64
  - !ruby/object:Gem::Version
65
65
  version: '0'
66
66
  requirements: []
67
- rubyforge_project:
68
- rubygems_version: 2.7.6
67
+ rubygems_version: 3.0.3
69
68
  signing_key:
70
69
  specification_version: 4
71
70
  summary: A Ruby client to some of the 1.0.0 Sentifi.com APIs