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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4bfeac4aee97cd064de1a051ec2ffc4ff787c55f76b9f6f0c8431eedf83dc857
4
- data.tar.gz: a74eec29f3a08cc9d61b5815711f451b32beb403a394547d0311595accff5eac
3
+ metadata.gz: a22c27c7dbd12ccf93283de4c58bb65497a17638d013929ad1557a91c1dfac2b
4
+ data.tar.gz: 037d542183584b6ced637afafbae8fc98febf971413dc5846fbff6fbbd44cad5
5
5
  SHA512:
6
- metadata.gz: dcee31d91fa32a28bcbb62b32528b1c02be05faedf5c8bb83edc430f7856922f6cd457b237a57ea410e475aaa58c958aca8367e917fea5084698e0923e4f4d59
7
- data.tar.gz: 99772453343ee48ae33ec348454b32c62cf47d4499edff0b577f7e4f59fbfb01eaa1bb7b6057977265a1122bf5621f1dbd33fc0a36b2979164c7c7c5a1d62253
6
+ metadata.gz: 23f8ed539f585372700227f4f42b947166d55f47b80ad180fb08e6ccc7eeeb1dd0a2e1031b1dea9915b8583b79ee63b7380e113c090d93b95c1910804bea7a23
7
+ data.tar.gz: e6526c9c327d68c8b27e0b8ad8b1c7bd02d8a8a66c9f7cd5936622a342efcd8bc7733df572ee0c4229530fed8480062f876f3796249032f15d068032fc2e60d4
@@ -2,6 +2,11 @@
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
+
5
10
  ## sentofu 0.5.4 released 2020-06-03
6
11
 
7
12
  * Prevent failure on missing GET parameters list
@@ -1,5 +1,5 @@
1
1
 
2
- Copyright (c) 2019-2020, 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
@@ -15,7 +15,7 @@ require 'sentofu/explo'
15
15
 
16
16
  module Sentofu
17
17
 
18
- VERSION = '0.5.4'
18
+ VERSION = '0.5.5'
19
19
 
20
20
  USER_AGENT =
21
21
  "Sentofu #{Sentofu::VERSION} - " +
@@ -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)'
@@ -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,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
- @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?
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
- 'Bearer ' + @h['access_token']
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
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-06-03 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,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.1.4
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