sentofu 0.4.2 → 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +26 -0
- data/LICENSE.txt +1 -1
- data/Makefile +1 -1
- data/lib/sentofu.rb +4 -2
- data/lib/sentofu/api.rb +10 -2
- data/lib/sentofu/http.rb +26 -13
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4bfeac4aee97cd064de1a051ec2ffc4ff787c55f76b9f6f0c8431eedf83dc857
|
4
|
+
data.tar.gz: a74eec29f3a08cc9d61b5815711f451b32beb403a394547d0311595accff5eac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dcee31d91fa32a28bcbb62b32528b1c02be05faedf5c8bb83edc430f7856922f6cd457b237a57ea410e475aaa58c958aca8367e917fea5084698e0923e4f4d59
|
7
|
+
data.tar.gz: 99772453343ee48ae33ec348454b32c62cf47d4499edff0b577f7e4f59fbfb01eaa1bb7b6057977265a1122bf5621f1dbd33fc0a36b2979164c7c7c5a1d62253
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,32 @@
|
|
2
2
|
# CHANGELOG.md
|
3
3
|
|
4
4
|
|
5
|
+
## sentofu 0.5.4 released 2020-06-03
|
6
|
+
|
7
|
+
* Prevent failure on missing GET parameters list
|
8
|
+
|
9
|
+
|
10
|
+
## sentofu 0.5.3 released 2019-11-07
|
11
|
+
|
12
|
+
* Tighten request error interception
|
13
|
+
|
14
|
+
|
15
|
+
## sentofu 0.5.2 released 2019-09-27
|
16
|
+
|
17
|
+
* Tighten request error interception
|
18
|
+
|
19
|
+
|
20
|
+
## sentofu 0.5.1 released 2019-09-10
|
21
|
+
|
22
|
+
* Keep track of :_headers in result hashes
|
23
|
+
* Revise error handling
|
24
|
+
|
25
|
+
|
26
|
+
## sentofu 0.5.0 released 2019-08-02
|
27
|
+
|
28
|
+
* Introduce Sentofu.ssl_verify_mode attr accessor
|
29
|
+
|
30
|
+
|
5
31
|
## sentofu 0.4.2 released 2019-07-28
|
6
32
|
|
7
33
|
* Fix HTTP proxy determination code
|
data/LICENSE.txt
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
Copyright (c) 2019-
|
2
|
+
Copyright (c) 2019-2020, John Mettraux, jmettraux+flor@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
data/lib/sentofu.rb
CHANGED
@@ -5,6 +5,7 @@ require 'time'
|
|
5
5
|
require 'base64'
|
6
6
|
require 'webrick' # for the http code to message mapping
|
7
7
|
require 'ostruct'
|
8
|
+
require 'openssl'
|
8
9
|
require 'net/http'
|
9
10
|
|
10
11
|
require 'sentofu/http'
|
@@ -14,7 +15,7 @@ require 'sentofu/explo'
|
|
14
15
|
|
15
16
|
module Sentofu
|
16
17
|
|
17
|
-
VERSION = '0.4
|
18
|
+
VERSION = '0.5.4'
|
18
19
|
|
19
20
|
USER_AGENT =
|
20
21
|
"Sentofu #{Sentofu::VERSION} - " +
|
@@ -24,11 +25,12 @@ module Sentofu
|
|
24
25
|
|
25
26
|
@auth_uri = nil
|
26
27
|
@apis = {}
|
28
|
+
@ssl_verify_mode = OpenSSL::SSL::VERIFY_PEER
|
27
29
|
|
28
30
|
class << self
|
29
31
|
|
30
32
|
attr_reader :auth_uri, :apis
|
31
|
-
attr_accessor :user_agent
|
33
|
+
attr_accessor :user_agent, :ssl_verify_mode
|
32
34
|
|
33
35
|
def init(versions=%w[ common:1.0.0 company:1.0.0 markets:1.0.0 ])
|
34
36
|
|
data/lib/sentofu/api.rb
CHANGED
@@ -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
|
-
|
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
|
data/lib/sentofu/http.rb
CHANGED
@@ -51,7 +51,10 @@ module Sentofu
|
|
51
51
|
# Nota Bene:
|
52
52
|
# even if ENV['sentofu_http_proxy'], ENV['http_proxy'] could kick in
|
53
53
|
|
54
|
-
|
54
|
+
if uri.scheme == 'https'
|
55
|
+
http.use_ssl = true
|
56
|
+
http.verify_mode = Sentofu.ssl_verify_mode
|
57
|
+
end
|
55
58
|
|
56
59
|
http
|
57
60
|
end
|
@@ -67,7 +70,13 @@ module Sentofu
|
|
67
70
|
|
68
71
|
res = http.request(req)
|
69
72
|
|
70
|
-
|
73
|
+
fail "request returned a #{res.class} and not a Net::HTTPResponse" \
|
74
|
+
unless res.is_a?(Net::HTTPResponse)
|
75
|
+
|
76
|
+
class << res
|
77
|
+
attr_accessor :_elapsed
|
78
|
+
def _headers; each_header.inject({}) { |h, (k, v)| h[k] = v; h }; end
|
79
|
+
end
|
71
80
|
res._elapsed = monow - t0
|
72
81
|
|
73
82
|
res
|
@@ -76,21 +85,25 @@ module Sentofu
|
|
76
85
|
def get_and_parse(uri, token=nil)
|
77
86
|
|
78
87
|
res = get(uri, token)
|
79
|
-
r = JSON.parse(res.body)
|
80
|
-
r[:_elapsed] = res._elapsed
|
81
88
|
|
82
|
-
|
89
|
+
fail 'something went wrong' \
|
90
|
+
unless res.header['content-type'].match(/^application\/json(;|$)/)
|
83
91
|
|
84
|
-
|
92
|
+
JSON.parse(res.body)
|
93
|
+
.merge!(
|
94
|
+
_headers: res._headers,
|
95
|
+
_elapsed: res._elapsed)
|
85
96
|
|
86
|
-
|
87
|
-
h[:code] = res.code.to_i
|
88
|
-
h[:message] = WEBrick::HTTPStatus.reason_phrase(res.code)
|
89
|
-
h[:error_class] = pe.class.to_s
|
90
|
-
h[:error_message] = pe.message
|
91
|
-
h[:body] = res.body unless res.body.index('</html>')
|
97
|
+
rescue => err
|
92
98
|
|
93
|
-
|
99
|
+
{ uri: uri,
|
100
|
+
code: (res.code.to_i rescue nil),
|
101
|
+
headers: (res._headers rescue nil),
|
102
|
+
message: (WEBrick::HTTPStatus.reason_phrase(res.code) rescue nil),
|
103
|
+
error_class: err.class.to_s,
|
104
|
+
error_message: err.message,
|
105
|
+
error_trace: err.backtrace,
|
106
|
+
body: ((res.body.index('</html>') ? '<html>' : res.body) rescue nil) }
|
94
107
|
end
|
95
108
|
|
96
109
|
protected
|
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.4
|
4
|
+
version: 0.5.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Mettraux
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-06-03 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
|
-
|
68
|
-
rubygems_version: 2.7.6
|
67
|
+
rubygems_version: 3.1.4
|
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
|