sentofu 0.5.2 → 0.6.0

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: 6b5960cd3b7ffcfe6824b87fb368fb50a7f780235bbc253962c3f4a4c2c981bd
4
- data.tar.gz: 4f5ff2b170ce25c694bbbf7a9371183e60171a03b410989f20e70619c5b4e633
3
+ metadata.gz: 6561d6b8cc61b7109c2025d15f6d5753906840f7f0bdf0dd0790498afcf74a1b
4
+ data.tar.gz: e5da524f149e0dbd50e51c4690e8ab753cab0b4eecf12a053612732bbc8a0a6b
5
5
  SHA512:
6
- metadata.gz: d3d393682b233664d071b45259ab59bb05504d52a013c16ede4f28fda80608bc1f6cf8a91b1a2ff5cdf12a433a242cb37621b2d5813472d3a02339e79f9464b8
7
- data.tar.gz: 7e95877e0cd10deb29f684f0e31ce93f97a8b5f5a908b8a17aa8d406466cdf10571e5cf8b3a9e123ca68a30c9d04bbf48d72bb4ae7edebc994ca416b1f24ead7
6
+ metadata.gz: b990aeecef8189eb352b359a7aeb83904c68acda461cba81f17ac2a2c520dce414850309ee5c0ffaa96a71f33cfdb23a3763e01f5b755d039d01a8d490723fb1
7
+ data.tar.gz: 6b91e650302caf66fb3d3b665b0d0d1b01912a61b9ed2ea35e78186b5b038c63462e641b4d0f7024cf7a93b578f0b1a479de80eaa4e0803cd4f17d81a5b59c9f
@@ -2,6 +2,32 @@
2
2
  # CHANGELOG.md
3
3
 
4
4
 
5
+ ## sentofu 0.6.0 released 2021-01-05
6
+
7
+ * Make error messages more informative
8
+ * Stop passing the full URI to GET and POST
9
+
10
+
11
+ ## sentofu 0.5.6 released 2020-09-28
12
+
13
+ * Report _code along _headers in response
14
+
15
+
16
+ ## sentofu 0.5.5 released 2020-09-25
17
+
18
+ * Report _uri and _proxy along _headers in response
19
+
20
+
21
+ ## sentofu 0.5.4 released 2020-06-03
22
+
23
+ * Prevent failure on missing GET parameters list
24
+
25
+
26
+ ## sentofu 0.5.3 released 2019-11-07
27
+
28
+ * Tighten request error interception
29
+
30
+
5
31
  ## sentofu 0.5.2 released 2019-09-27
6
32
 
7
33
  * Tighten request error interception
@@ -1,5 +1,5 @@
1
1
 
2
- Copyright (c) 2019-2019, John Mettraux, jmettraux+flor@gmail.com
2
+ Copyright (c) 2019-2021, 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.2'
18
+ VERSION = '0.6.0'
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
@@ -13,19 +13,23 @@ module Sentofu
13
13
 
14
14
  a = Base64.encode64("#{cs.id}:#{cs.secret}").strip
15
15
 
16
- req = Net::HTTP::Post.new(Sentofu.auth_uri)
16
+ u = URI(Sentofu.auth_uri)
17
+
18
+ req = Net::HTTP::Post.new(u.path)
17
19
  req.add_field('Content-Type', 'application/json')
18
20
  req.add_field('Authorization', a)
19
21
 
20
22
  req.body = JSON.dump(
21
23
  grant_type: 'password', username: cs.user, password: cs.pass)
22
24
 
23
- Sentofu::Token.new(request(Sentofu.auth_uri, req))
25
+ Sentofu::Token.new(request(u, req))
24
26
  end
25
27
 
26
28
  def get(uri, token=nil)
27
29
 
28
- request(uri, make_get_req(uri, token))
30
+ u = URI(uri)
31
+
32
+ request(u, make_get_req(u, token))
29
33
  end
30
34
 
31
35
  def make_net_http(uri)
@@ -61,23 +65,23 @@ module Sentofu
61
65
 
62
66
  def request(uri, req)
63
67
 
64
- u = uri.is_a?(String) ? URI(uri) : uri
65
-
66
68
  t0 = monow
67
69
 
68
- http = make_net_http(u)
69
- #t.set_debug_output($stdout) if u.to_s.match(/search/)
70
+ http = make_net_http(uri)
71
+ #http.set_debug_output($stderr)
70
72
 
71
73
  res = http.request(req)
72
74
 
73
- fail "request returned a #{res.class} and not a Net::HTTPResponse" \
74
- unless res.is_a?(Net::HTTPResponse)
75
-
76
75
  class << res
77
- attr_accessor :_elapsed
76
+ attr_accessor :_uri, :_elapsed, :_proxy
78
77
  def _headers; each_header.inject({}) { |h, (k, v)| h[k] = v; h }; end
79
78
  end
79
+ res._uri = uri.to_s
80
80
  res._elapsed = monow - t0
81
+ res._proxy = detail_proxy(http)
82
+
83
+ fail "request returned a #{res.class} and not a Net::HTTPResponse" \
84
+ unless res.is_a?(Net::HTTPResponse)
81
85
 
82
86
  res
83
87
  end
@@ -86,19 +90,24 @@ module Sentofu
86
90
 
87
91
  res = get(uri, token)
88
92
 
89
- fail 'something went wrong' \
90
- unless res.header['content-type'].match(/^application\/json(;|$)/)
93
+ fail(
94
+ "#{WEBrick::HTTPStatus.reason_phrase(res.code) rescue ''} - " +
95
+ "#{res._uri.to_s}"
96
+ ) unless res.header['content-type'].match?(/^application\/json(;|$)/)
91
97
 
92
98
  JSON.parse(res.body)
93
99
  .merge!(
100
+ _uri: res._uri.to_s,
94
101
  _headers: res._headers,
95
- _elapsed: res._elapsed)
102
+ _code: res.code.to_i,
103
+ _elapsed: res._elapsed,
104
+ _proxy: res._proxy)
96
105
 
97
106
  rescue => err
98
107
 
99
- { uri: uri,
108
+ { uri: uri.to_s,
100
109
  code: (res.code.to_i rescue nil),
101
- headers: res._headers,
110
+ headers: (res._headers rescue nil),
102
111
  message: (WEBrick::HTTPStatus.reason_phrase(res.code) rescue nil),
103
112
  error_class: err.class.to_s,
104
113
  error_message: err.message,
@@ -112,7 +121,10 @@ module Sentofu
112
121
 
113
122
  def make_get_req(uri, token)
114
123
 
115
- req = Net::HTTP::Get.new(uri.to_s)
124
+ u = [ uri.path, uri.query ].compact.join('?')
125
+ u = '/' if u.length < 1
126
+
127
+ req = Net::HTTP::Get.new(u)
116
128
  req.instance_eval { @header.clear }
117
129
  def req.set_header(k, v); @header[k] = [ v ]; end
118
130
 
@@ -139,6 +151,17 @@ module Sentofu
139
151
 
140
152
  OpenStruct.new(YAML.load(File.read(fname)))
141
153
  end
154
+
155
+ def detail_proxy(http)
156
+
157
+ if http.proxy_address
158
+ { address: http.proxy_address,
159
+ port: http.proxy_port,
160
+ user: http.proxy_user }
161
+ else
162
+ nil
163
+ end
164
+ end
142
165
  end
143
166
  end
144
167
 
@@ -148,7 +171,19 @@ module Sentofu
148
171
 
149
172
  @h = JSON.parse(res.body)
150
173
  @h[:_elapsed] = res._elapsed
151
- @expires_at = Time.now + @h['expires_in']
174
+ @h[:_proxy] = res._proxy
175
+
176
+ @expires_at = @h['expires_in'] ? Time.now + @h['expires_in'] : 0
177
+ end
178
+
179
+ def errors
180
+
181
+ @h['errors'] || []
182
+ end
183
+
184
+ def sound?
185
+
186
+ errors.empty?
152
187
  end
153
188
 
154
189
  def not_expired?
@@ -158,7 +193,7 @@ module Sentofu
158
193
 
159
194
  def header_value
160
195
 
161
- 'Bearer ' + @h['access_token']
196
+ "Bearer #{@h['access_token'] || 'SENTOFU_INVALID_TOKEN_:-('}"
162
197
  end
163
198
  end
164
199
  end
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.platform = Gem::Platform::RUBY
11
11
  s.authors = [ 'John Mettraux' ]
12
12
  s.email = [ 'jmettraux@gmail.com' ]
13
- s.homepage = 'http://github.com/jmettraux/sentofu'
13
+ s.homepage = 'https://github.com/jmettraux/sentofu'
14
14
  s.license = 'MIT'
15
15
  s.summary = 'A Ruby client to some of the 1.0.0 Sentifi.com APIs'
16
16
 
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.2
4
+ version: 0.6.0
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-09-27 00:00:00.000000000 Z
11
+ date: 2021-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -40,15 +40,15 @@ files:
40
40
  - lib/sentofu/explo.rb
41
41
  - lib/sentofu/http.rb
42
42
  - sentofu.gemspec
43
- homepage: http://github.com/jmettraux/sentofu
43
+ homepage: https://github.com/jmettraux/sentofu
44
44
  licenses:
45
45
  - MIT
46
46
  metadata:
47
- changelog_uri: http://github.com/jmettraux/sentofu/blob/master/CHANGELOG.md
48
- documentation_uri: http://github.com/jmettraux/sentofu
49
- bug_tracker_uri: http://github.com/jmettraux/sentofu/issues
50
- homepage_uri: http://github.com/jmettraux/sentofu
51
- source_code_uri: http://github.com/jmettraux/sentofu
47
+ changelog_uri: https://github.com/jmettraux/sentofu/blob/master/CHANGELOG.md
48
+ documentation_uri: https://github.com/jmettraux/sentofu
49
+ bug_tracker_uri: https://github.com/jmettraux/sentofu/issues
50
+ homepage_uri: https://github.com/jmettraux/sentofu
51
+ source_code_uri: https://github.com/jmettraux/sentofu
52
52
  post_install_message:
53
53
  rdoc_options: []
54
54
  require_paths:
@@ -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