exception_notification-idobata 1.0.2 → 1.1.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
  SHA1:
3
- metadata.gz: df660b8a1356591bf0e7ba36631fba5b7156826f
4
- data.tar.gz: 010e9b45bfb289ee787e9348537812a7e2b7bc94
3
+ metadata.gz: fa728904929bc8fd75fa221be571995ebf26df70
4
+ data.tar.gz: 6301680b8f61911bcc20f861fdd3dc0819a83a15
5
5
  SHA512:
6
- metadata.gz: 78c4117317c8676cf218b7273eb58c2e12f41a3e3935d3f4aea1b2d3e58b696b0ffcd954f88e58ec5107c0e7cee29be4912d10db4edf75efb336a0a9393f6a7a
7
- data.tar.gz: 817930c112d109e25c1abf2a58bb45bf8c45bba50fe5b722f0bacef44d9d3095719873931a6efc8e636848d3cc8ae20b9d512d9059f55e68600a79fe09d86714
6
+ metadata.gz: ec84b599dd603518eccfed4e2b4bb684478d7bd0892f6ad18be6bab59d940114574ebf19391496676e98eb42450ce518a2ddd04ebba67f466009e2470a1ddc25
7
+ data.tar.gz: cab5440ad2d3754ecc3ebaad6846a411a1133ecb74633244537729596b86b8bcc156652779ee573f7b5019064478414682a33f8a732e018bf937f6d8df04bb87
@@ -1,5 +1,5 @@
1
1
  module ExceptionNotification
2
2
  class Idobata
3
- VERSION = '1.0.2'
3
+ VERSION = '1.1.0'
4
4
  end
5
5
  end
@@ -7,7 +7,7 @@ module ExceptionNotifier
7
7
  attr_reader :url
8
8
 
9
9
  def initialize(options)
10
- @options = extract_global_options(options, :url, :skip_library_backtrace)
10
+ @options = extract_global_options(options, :url, :skip_library_backtrace, :proxy)
11
11
 
12
12
  raise(ArgumentError, 'Endpoint must be specified') unless @url
13
13
  end
@@ -23,11 +23,28 @@ module ExceptionNotifier
23
23
 
24
24
  source = build_message(exception, enviroments)
25
25
 
26
- Net::HTTP.post_form URI.parse(url), source: source, format: :html
26
+ http_client.post_form URI.parse(url), source: source, format: :html
27
27
  end
28
28
 
29
29
  private
30
30
 
31
+ def http_client
32
+ @proxy ? Net::HTTP.Proxy(*extract_proxy_settings(@proxy)) : Net::HTTP
33
+ end
34
+
35
+ def extract_proxy_settings(proxy)
36
+ case proxy
37
+ when String
38
+ extract_proxy_settings(URI(proxy))
39
+ when URI
40
+ [proxy.host, proxy.port]
41
+ when Hash
42
+ proxy.values_at(:host, :port)
43
+ else
44
+ proxy
45
+ end
46
+ end
47
+
31
48
  def extract_global_options(options, *global_option_names)
32
49
  options.dup.tap do |opts|
33
50
  global_option_names.each {|name| instance_variable_set "@#{name}", opts.delete(name) }
@@ -74,4 +74,46 @@ describe ExceptionNotifier::IdobataNotifier do
74
74
  </table>
75
75
  HTML
76
76
  end
77
+
78
+ describe '#http_client' do
79
+ let(:proxy) { raise NotImplementedError }
80
+ let(:notifier) do
81
+ ExceptionNotifier::IdobataNotifier.new(
82
+ :url => 'https://idobata.io/hook/endpoint',
83
+ :proxy => proxy,
84
+ )
85
+ end
86
+
87
+ subject(:http_client) { notifier.send(:http_client) }
88
+
89
+ context ':proxy is a url string' do
90
+ let(:proxy) { 'http://proxy-address:8080/' }
91
+
92
+ it { expect(http_client).to be_proxy_class }
93
+ it { expect(http_client.proxy_address).to eq 'proxy-address' }
94
+ it { expect(http_client.proxy_port).to eq 8080 }
95
+ end
96
+
97
+ context ':proxy is a URI object' do
98
+ let(:proxy) { URI('http://proxy-address:8080/') }
99
+
100
+ it { expect(http_client).to be_proxy_class }
101
+ it { expect(http_client.proxy_address).to eq 'proxy-address' }
102
+ it { expect(http_client.proxy_port).to eq 8080 }
103
+ end
104
+
105
+ context ':proxy is a Hash object' do
106
+ let(:proxy) { {host: 'proxy-address', port: 8080} }
107
+
108
+ it { expect(http_client).to be_proxy_class }
109
+ it { expect(http_client.proxy_address).to eq 'proxy-address' }
110
+ it { expect(http_client.proxy_port).to eq 8080 }
111
+ end
112
+
113
+ context ':proxy is nil' do
114
+ let(:proxy) { nil }
115
+
116
+ it { expect(http_client).to_not be_proxy_class }
117
+ end
118
+ end
77
119
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exception_notification-idobata
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiroshi Yoshida
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-23 00:00:00.000000000 Z
11
+ date: 2016-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: exception_notification