sentofu 0.5.6 → 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 +4 -4
- data/CHANGELOG.md +6 -0
- data/LICENSE.txt +1 -1
- data/lib/sentofu.rb +1 -1
- data/lib/sentofu/http.rb +19 -12
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6561d6b8cc61b7109c2025d15f6d5753906840f7f0bdf0dd0790498afcf74a1b
|
4
|
+
data.tar.gz: e5da524f149e0dbd50e51c4690e8ab753cab0b4eecf12a053612732bbc8a0a6b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b990aeecef8189eb352b359a7aeb83904c68acda461cba81f17ac2a2c520dce414850309ee5c0ffaa96a71f33cfdb23a3763e01f5b755d039d01a8d490723fb1
|
7
|
+
data.tar.gz: 6b91e650302caf66fb3d3b665b0d0d1b01912a61b9ed2ea35e78186b5b038c63462e641b4d0f7024cf7a93b578f0b1a479de80eaa4e0803cd4f17d81a5b59c9f
|
data/CHANGELOG.md
CHANGED
data/LICENSE.txt
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
Copyright (c) 2019-
|
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/lib/sentofu.rb
CHANGED
data/lib/sentofu/http.rb
CHANGED
@@ -13,19 +13,23 @@ module Sentofu
|
|
13
13
|
|
14
14
|
a = Base64.encode64("#{cs.id}:#{cs.secret}").strip
|
15
15
|
|
16
|
-
|
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(
|
25
|
+
Sentofu::Token.new(request(u, req))
|
24
26
|
end
|
25
27
|
|
26
28
|
def get(uri, token=nil)
|
27
29
|
|
28
|
-
|
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,12 +65,10 @@ 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(
|
69
|
-
#
|
70
|
+
http = make_net_http(uri)
|
71
|
+
#http.set_debug_output($stderr)
|
70
72
|
|
71
73
|
res = http.request(req)
|
72
74
|
|
@@ -88,12 +90,14 @@ module Sentofu
|
|
88
90
|
|
89
91
|
res = get(uri, token)
|
90
92
|
|
91
|
-
fail
|
92
|
-
|
93
|
+
fail(
|
94
|
+
"#{WEBrick::HTTPStatus.reason_phrase(res.code) rescue ''} - " +
|
95
|
+
"#{res._uri.to_s}"
|
96
|
+
) unless res.header['content-type'].match?(/^application\/json(;|$)/)
|
93
97
|
|
94
98
|
JSON.parse(res.body)
|
95
99
|
.merge!(
|
96
|
-
_uri: res._uri,
|
100
|
+
_uri: res._uri.to_s,
|
97
101
|
_headers: res._headers,
|
98
102
|
_code: res.code.to_i,
|
99
103
|
_elapsed: res._elapsed,
|
@@ -101,7 +105,7 @@ module Sentofu
|
|
101
105
|
|
102
106
|
rescue => err
|
103
107
|
|
104
|
-
{ uri: uri,
|
108
|
+
{ uri: uri.to_s,
|
105
109
|
code: (res.code.to_i rescue nil),
|
106
110
|
headers: (res._headers rescue nil),
|
107
111
|
message: (WEBrick::HTTPStatus.reason_phrase(res.code) rescue nil),
|
@@ -117,7 +121,10 @@ module Sentofu
|
|
117
121
|
|
118
122
|
def make_get_req(uri, token)
|
119
123
|
|
120
|
-
|
124
|
+
u = [ uri.path, uri.query ].compact.join('?')
|
125
|
+
u = '/' if u.length < 1
|
126
|
+
|
127
|
+
req = Net::HTTP::Get.new(u)
|
121
128
|
req.instance_eval { @header.clear }
|
122
129
|
def req.set_header(k, v); @header[k] = [ v ]; end
|
123
130
|
|
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
|
+
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:
|
11
|
+
date: 2021-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|