sentofu 0.5.4 → 0.5.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/LICENSE.txt +1 -1
- data/lib/sentofu.rb +1 -1
- data/lib/sentofu/api.rb +1 -1
- data/lib/sentofu/explo.rb +10 -1
- data/lib/sentofu/http.rb +36 -9
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a22c27c7dbd12ccf93283de4c58bb65497a17638d013929ad1557a91c1dfac2b
|
4
|
+
data.tar.gz: 037d542183584b6ced637afafbae8fc98febf971413dc5846fbff6fbbd44cad5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23f8ed539f585372700227f4f42b947166d55f47b80ad180fb08e6ccc7eeeb1dd0a2e1031b1dea9915b8583b79ee63b7380e113c090d93b95c1910804bea7a23
|
7
|
+
data.tar.gz: e6526c9c327d68c8b27e0b8ad8b1c7bd02d8a8a66c9f7cd5936622a342efcd8bc7733df572ee0c4229530fed8480062f876f3796249032f15d068032fc2e60d4
|
data/CHANGELOG.md
CHANGED
data/LICENSE.txt
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
Copyright (c) 2019-2020, John Mettraux, jmettraux
|
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/lib/sentofu.rb
CHANGED
data/lib/sentofu/api.rb
CHANGED
@@ -147,7 +147,7 @@ module Sentofu
|
|
147
147
|
def initialize(name, spec)
|
148
148
|
|
149
149
|
u = spec['servers'].first['url'] rescue nil
|
150
|
-
unless u.is_a?(String) && u.match(/\Ahttps?:\/\//)
|
150
|
+
unless u.is_a?(String) && u.match?(/\Ahttps?:\/\//)
|
151
151
|
#p name; pp spec; p u
|
152
152
|
c = spec['code'] rescue -1
|
153
153
|
m = spec['message'] rescue '(no message)'
|
data/lib/sentofu/explo.rb
CHANGED
@@ -33,10 +33,19 @@ module Sentofu
|
|
33
33
|
puts
|
34
34
|
|
35
35
|
list_apis.each do |h|
|
36
|
-
|
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
|
data/lib/sentofu/http.rb
CHANGED
@@ -66,18 +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
|
-
fail "request returned a #{res.class} and not a Net::HTTPResponse" \
|
74
|
-
unless res.is_a?(Net::HTTPResponse)
|
75
|
-
|
76
73
|
class << res
|
77
|
-
attr_accessor :_elapsed
|
74
|
+
attr_accessor :_uri, :_elapsed, :_proxy
|
78
75
|
def _headers; each_header.inject({}) { |h, (k, v)| h[k] = v; h }; end
|
79
76
|
end
|
77
|
+
res._uri = uri.to_s
|
80
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)
|
81
83
|
|
82
84
|
res
|
83
85
|
end
|
@@ -87,12 +89,14 @@ module Sentofu
|
|
87
89
|
res = get(uri, token)
|
88
90
|
|
89
91
|
fail 'something went wrong' \
|
90
|
-
unless res.header['content-type'].match(/^application\/json(;|$)/)
|
92
|
+
unless res.header['content-type'].match?(/^application\/json(;|$)/)
|
91
93
|
|
92
94
|
JSON.parse(res.body)
|
93
95
|
.merge!(
|
96
|
+
_uri: res._uri,
|
94
97
|
_headers: res._headers,
|
95
|
-
_elapsed: res._elapsed
|
98
|
+
_elapsed: res._elapsed,
|
99
|
+
_proxy: res._proxy)
|
96
100
|
|
97
101
|
rescue => err
|
98
102
|
|
@@ -139,6 +143,17 @@ module Sentofu
|
|
139
143
|
|
140
144
|
OpenStruct.new(YAML.load(File.read(fname)))
|
141
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
|
142
157
|
end
|
143
158
|
end
|
144
159
|
|
@@ -148,7 +163,19 @@ module Sentofu
|
|
148
163
|
|
149
164
|
@h = JSON.parse(res.body)
|
150
165
|
@h[:_elapsed] = res._elapsed
|
151
|
-
@
|
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?
|
152
179
|
end
|
153
180
|
|
154
181
|
def not_expired?
|
@@ -158,7 +185,7 @@ module Sentofu
|
|
158
185
|
|
159
186
|
def header_value
|
160
187
|
|
161
|
-
|
188
|
+
"Bearer #{@h['access_token'] || 'SENTOFU_INVALID_TOKEN_:-('}"
|
162
189
|
end
|
163
190
|
end
|
164
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.
|
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: 2020-
|
11
|
+
date: 2020-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -64,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
64
|
- !ruby/object:Gem::Version
|
65
65
|
version: '0'
|
66
66
|
requirements: []
|
67
|
-
rubygems_version: 3.
|
67
|
+
rubygems_version: 3.0.3
|
68
68
|
signing_key:
|
69
69
|
specification_version: 4
|
70
70
|
summary: A Ruby client to some of the 1.0.0 Sentifi.com APIs
|