sentofu 0.3.0 → 0.4.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: 91270abde3451876c1642617b4ac839347472f43cfbd5f191141330557d67b74
4
- data.tar.gz: 35336f324cb73e7669e05db182addea25b25c7b92c34dfb5f8e1a988985d9c0c
3
+ metadata.gz: 1cf89a26a83c77e1de102c5281a142ef68883f7f5a3b6074deddc4b4699c4b75
4
+ data.tar.gz: b3e1cf4e374db9a2e4ad7e909151b1914c5dcb9503f25000b5bb66e08766114e
5
5
  SHA512:
6
- metadata.gz: 8efe554288eae6e1815b61a4fff44149e1b02c1ffe6e6b118346de1dea1e70859b4ccc77a84d5cf96d4065026978c7d01e6c168d7b19e1ebaad7d85b604a2588
7
- data.tar.gz: 920158c6e502f3302ccaa07e6be89279525d1f9673cbbada55a72bc70b56cf7485c69117e8e26166f6961351c31a4d3d9c4481d4341003fb3d0500f3e103e181
6
+ metadata.gz: 7871ee50c8e327317c41d604217e2e8fbecb62930adba09d7b53e3ad9268cfd9deb07cbaccb8f33ee62e080d000cb6d72ea6251213d40ab6e5baf224d10af819
7
+ data.tar.gz: afa1bf96c6fca1142c4d1e60e4e5af1256d891e8c3c8abe0a5ae06d1c07eb2a796d95aa2c59d266343c7dab6e97b83e345663214f21579f22d068d48a9d83752
data/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
2
2
  # CHANGELOG.md
3
3
 
4
4
 
5
+ ## sentofu 0.4.0 released 2019-07-26
6
+
7
+ * Accept `ENV['sentofu_http_proxy']`
8
+
9
+
5
10
  ## sentofu 0.3.0 released 2019-06-05
6
11
 
7
12
  * Add Sentofu.on_response and Api#on_response
data/README.md CHANGED
@@ -3,6 +3,29 @@
3
3
 
4
4
  A Ruby client to some of the 1.0.0 Sentifi.com APIs.
5
5
 
6
+ ## proxy
7
+
8
+ Sentofu follows the vanilla `ENV['http_proxy']` Ruby proxy setting.
9
+
10
+ It also accepts a dedicated `ENV['sentofu_http_proxy']` environment variable.
11
+
12
+ In Ruby:
13
+ ```ruby
14
+ ENV['sentofu_http_proxy'] = 'http://proxy.example.com'
15
+ # or
16
+ ENV['sentofu_http_proxy'] = 'http://proxy.example.com:8080'
17
+ # or
18
+ ENV['sentofu_http_proxy'] = 'http://user:pass@proxy.example.com'
19
+ # or
20
+ ENV['sentofu_http_proxy'] = 'http://user:pass@proxy.example.com:8080'
21
+ ```
22
+
23
+ From the command line:
24
+ ```
25
+ $ http_proxy = 'http://user:pass@proxy.example.com'
26
+ $ sentofu_http_proxy = 'http://user:pass@proxy.example.com'
27
+ ```
28
+
6
29
  ## license
7
30
 
8
31
  MIT, see [LICENSE.txt](LICENSE.txt)
data/lib/sentofu/http.rb CHANGED
@@ -26,17 +26,39 @@ module Sentofu
26
26
  request(uri, make_get_req(uri, token))
27
27
  end
28
28
 
29
+ PROXY_REX = /\A(([^:@]+)(:([^@]+))?@)?([^:]+)(:(\d+))?\z/
30
+
31
+ def make_net_http(uri)
32
+
33
+ http =
34
+ if pm = PROXY_REX.match(ENV['sentofu_http_proxy'] || '')
35
+ Net::HTTP.new(
36
+ uri.host, uri.port,
37
+ pm[5], pm[7] ? pm[7].to_i : nil, # proxy host and port
38
+ pm[2], pm[4]) # proxy user and pass
39
+ else
40
+ Net::HTTP.new(
41
+ uri.host, uri.port)
42
+ end
43
+
44
+ # Nota Bene:
45
+ # even if ENV['sentofu_http_proxy'], ENV['http_proxy'] could kick in
46
+
47
+ http.use_ssl = (uri.scheme == 'https')
48
+
49
+ http
50
+ end
51
+
29
52
  def request(uri, req)
30
53
 
31
54
  u = uri.is_a?(String) ? URI(uri) : uri
32
55
 
33
56
  t0 = monow
34
57
 
35
- t = Net::HTTP.new(u.host, u.port)
36
- t.use_ssl = (u.scheme == 'https')
58
+ http = make_net_http(u)
37
59
  #t.set_debug_output($stdout) if u.to_s.match(/search/)
38
60
 
39
- res = t.request(req)
61
+ res = http.request(req)
40
62
 
41
63
  class << res; attr_accessor :_elapsed; end
42
64
  res._elapsed = monow - t0
data/lib/sentofu.rb CHANGED
@@ -14,7 +14,7 @@ require 'sentofu/explo'
14
14
 
15
15
  module Sentofu
16
16
 
17
- VERSION = '0.3.0'
17
+ VERSION = '0.4.0'
18
18
 
19
19
  USER_AGENT =
20
20
  "Sentofu #{Sentofu::VERSION} - " +
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.3.0
4
+ version: 0.4.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-06-05 00:00:00.000000000 Z
11
+ date: 2019-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec