sentofu 0.5.6 → 0.6.0

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: 1a51d89ce6f0bf66e8ec77a7e1ffb77f785cd79b76d6187e8acd57bbeb271d92
4
- data.tar.gz: 53a52a093fa0814e93af8a853d28a4bf8148778425f9a1b4ea6d05b5cf8dbc06
3
+ metadata.gz: 6561d6b8cc61b7109c2025d15f6d5753906840f7f0bdf0dd0790498afcf74a1b
4
+ data.tar.gz: e5da524f149e0dbd50e51c4690e8ab753cab0b4eecf12a053612732bbc8a0a6b
5
5
  SHA512:
6
- metadata.gz: 8f0caad70ab9b00ef1cb6f922b8ea31084fe348c5a3dea244b6b85dc18a3f723ece8024c41581049d4566a376a1b98e7f12a77be0c57bb8d5f65aadacda7b164
7
- data.tar.gz: 86cabc05c6d18492acd8bbe0c38deb66a3255e50c08f2817f48759816ac9fa0fde87a003e49b6d42d08d2789953a9d841abd8549d32a63a23204b5ec51e0168d
6
+ metadata.gz: b990aeecef8189eb352b359a7aeb83904c68acda461cba81f17ac2a2c520dce414850309ee5c0ffaa96a71f33cfdb23a3763e01f5b755d039d01a8d490723fb1
7
+ data.tar.gz: 6b91e650302caf66fb3d3b665b0d0d1b01912a61b9ed2ea35e78186b5b038c63462e641b4d0f7024cf7a93b578f0b1a479de80eaa4e0803cd4f17d81a5b59c9f
@@ -2,6 +2,12 @@
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
+
5
11
  ## sentofu 0.5.6 released 2020-09-28
6
12
 
7
13
  * Report _code along _headers in response
@@ -1,5 +1,5 @@
1
1
 
2
- Copyright (c) 2019-2020, John Mettraux, jmettraux@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
@@ -15,7 +15,7 @@ require 'sentofu/explo'
15
15
 
16
16
  module Sentofu
17
17
 
18
- VERSION = '0.5.6'
18
+ VERSION = '0.6.0'
19
19
 
20
20
  USER_AGENT =
21
21
  "Sentofu #{Sentofu::VERSION} - " +
@@ -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,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(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
 
@@ -88,12 +90,14 @@ module Sentofu
88
90
 
89
91
  res = get(uri, token)
90
92
 
91
- fail 'something went wrong' \
92
- 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(;|$)/)
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
- 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)
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.5.6
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: 2020-09-28 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