sentofu 0.5.1 → 0.5.6

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: 68e190d7c3fe485d068af8a08d0fc2186a5f88a88190dcc7a847502f8be41c43
4
- data.tar.gz: 1f78480b5d3d29d2c427b1834eead05e825457afe644c6e5f9fba880d4c34b00
3
+ metadata.gz: 1a51d89ce6f0bf66e8ec77a7e1ffb77f785cd79b76d6187e8acd57bbeb271d92
4
+ data.tar.gz: 53a52a093fa0814e93af8a853d28a4bf8148778425f9a1b4ea6d05b5cf8dbc06
5
5
  SHA512:
6
- metadata.gz: 855aa75755835c002c54c99e6d6bd5bbc49d82a03181296029da3c8a27a437afdd05b40ddd88a8a69756f2ec9c7885eb703301b15857959fbd6143ff61b9d303
7
- data.tar.gz: a79ae6b30586c97d5f3781e4ea27a28cf406df24da887717812b674e949cc5f489abc2f71048322eb46e23d377846b6bf0f860ec2b2687bd5b13154c4d416037
6
+ metadata.gz: 8f0caad70ab9b00ef1cb6f922b8ea31084fe348c5a3dea244b6b85dc18a3f723ece8024c41581049d4566a376a1b98e7f12a77be0c57bb8d5f65aadacda7b164
7
+ data.tar.gz: 86cabc05c6d18492acd8bbe0c38deb66a3255e50c08f2817f48759816ac9fa0fde87a003e49b6d42d08d2789953a9d841abd8549d32a63a23204b5ec51e0168d
@@ -2,6 +2,31 @@
2
2
  # CHANGELOG.md
3
3
 
4
4
 
5
+ ## sentofu 0.5.6 released 2020-09-28
6
+
7
+ * Report _code along _headers in response
8
+
9
+
10
+ ## sentofu 0.5.5 released 2020-09-25
11
+
12
+ * Report _uri and _proxy along _headers in response
13
+
14
+
15
+ ## sentofu 0.5.4 released 2020-06-03
16
+
17
+ * Prevent failure on missing GET parameters list
18
+
19
+
20
+ ## sentofu 0.5.3 released 2019-11-07
21
+
22
+ * Tighten request error interception
23
+
24
+
25
+ ## sentofu 0.5.2 released 2019-09-27
26
+
27
+ * Tighten request error interception
28
+
29
+
5
30
  ## sentofu 0.5.1 released 2019-09-10
6
31
 
7
32
  * Keep track of :_headers in result hashes
@@ -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.1'
18
+ VERSION = '0.5.6'
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,15 +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
73
  class << res
74
- attr_accessor :_elapsed
74
+ attr_accessor :_uri, :_elapsed, :_proxy
75
75
  def _headers; each_header.inject({}) { |h, (k, v)| h[k] = v; h }; end
76
76
  end
77
+ res._uri = uri.to_s
77
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)
78
83
 
79
84
  res
80
85
  end
@@ -84,23 +89,26 @@ module Sentofu
84
89
  res = get(uri, token)
85
90
 
86
91
  fail 'something went wrong' \
87
- unless res.header['content-type'].match(/^application\/json(;|$)/)
92
+ unless res.header['content-type'].match?(/^application\/json(;|$)/)
88
93
 
89
94
  JSON.parse(res.body)
90
95
  .merge!(
96
+ _uri: res._uri,
91
97
  _headers: res._headers,
92
- _elapsed: res._elapsed)
98
+ _code: res.code.to_i,
99
+ _elapsed: res._elapsed,
100
+ _proxy: res._proxy)
93
101
 
94
- rescue => e
102
+ rescue => err
95
103
 
96
104
  { 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) }
105
+ code: (res.code.to_i rescue nil),
106
+ headers: (res._headers rescue nil),
107
+ message: (WEBrick::HTTPStatus.reason_phrase(res.code) rescue nil),
108
+ error_class: err.class.to_s,
109
+ error_message: err.message,
110
+ error_trace: err.backtrace,
111
+ body: ((res.body.index('</html>') ? '<html>' : res.body) rescue nil) }
104
112
  end
105
113
 
106
114
  protected
@@ -136,6 +144,17 @@ module Sentofu
136
144
 
137
145
  OpenStruct.new(YAML.load(File.read(fname)))
138
146
  end
147
+
148
+ def detail_proxy(http)
149
+
150
+ if http.proxy_address
151
+ { address: http.proxy_address,
152
+ port: http.proxy_port,
153
+ user: http.proxy_user }
154
+ else
155
+ nil
156
+ end
157
+ end
139
158
  end
140
159
  end
141
160
 
@@ -145,7 +164,19 @@ module Sentofu
145
164
 
146
165
  @h = JSON.parse(res.body)
147
166
  @h[:_elapsed] = res._elapsed
148
- @expires_at = Time.now + @h['expires_in']
167
+ @h[:_proxy] = res._proxy
168
+
169
+ @expires_at = @h['expires_in'] ? Time.now + @h['expires_in'] : 0
170
+ end
171
+
172
+ def errors
173
+
174
+ @h['errors'] || []
175
+ end
176
+
177
+ def sound?
178
+
179
+ errors.empty?
149
180
  end
150
181
 
151
182
  def not_expired?
@@ -155,7 +186,7 @@ module Sentofu
155
186
 
156
187
  def header_value
157
188
 
158
- 'Bearer ' + @h['access_token']
189
+ "Bearer #{@h['access_token'] || 'SENTOFU_INVALID_TOKEN_:-('}"
159
190
  end
160
191
  end
161
192
  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.1
4
+ version: 0.5.6
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-10 00:00:00.000000000 Z
11
+ date: 2020-09-28 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