exception_notification-idobata 0.0.1 → 0.0.2
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ade18db9b418ae3b8003b3b97ad2a38292251fdf
|
4
|
+
data.tar.gz: 5efb9417aef0b6126fac3dee7dbead6fa2e4948f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86f70e6b9446b1b82839920b5a3b6306ba4c552e3830dc549f321680b7a3010d602c6d77a885b437ff02b8a18b01f528fd8e550e4a7c65d17f994d3f448e128f
|
7
|
+
data.tar.gz: 1624ff334d5c43396a2af11db0670425c04132aa55a62929468b19d278e12d8b5bc08c19e1fbe999e3686a3627bac1623710a98903ade2e56f381dedfc437549
|
data/README.md
CHANGED
@@ -4,20 +4,26 @@
|
|
4
4
|
|
5
5
|
Add this line to your application's Gemfile:
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
```ruby
|
8
|
+
gem 'exception_notification'
|
9
|
+
gem 'exception_notification-idobata'
|
10
|
+
```
|
9
11
|
And then execute:
|
10
12
|
|
11
|
-
|
13
|
+
```
|
14
|
+
$ bundle
|
15
|
+
```
|
12
16
|
|
13
17
|
## Usage
|
14
18
|
|
19
|
+
This plugin works by putting the following lines in your `config/environments/production.rb`
|
20
|
+
|
15
21
|
```ruby
|
16
22
|
Sample::Application.configure do
|
17
|
-
config.middleware.use
|
18
|
-
ExceptionNotification::Rack,
|
23
|
+
config.middleware.use ExceptionNotification::Rack,
|
19
24
|
idobata: {
|
20
|
-
url:
|
25
|
+
url: HOOK_ENDPOINT,
|
26
|
+
stage: 'Optional params as you like'
|
21
27
|
}
|
22
28
|
end
|
23
29
|
```
|
@@ -6,7 +6,37 @@ module ExceptionNotifier
|
|
6
6
|
attr_reader :url
|
7
7
|
|
8
8
|
def initialize(options)
|
9
|
-
@url = options
|
9
|
+
unless @url = options.delete(:url)
|
10
|
+
raise ArgumentError, 'Endpoint must be specified'
|
11
|
+
end
|
12
|
+
|
13
|
+
@options = options
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(exception, options={})
|
17
|
+
enviroments =
|
18
|
+
if options[:env]
|
19
|
+
request_option(ActionDispatch::Request.new(options[:env]))
|
20
|
+
else
|
21
|
+
# [TODO] - Add option specification route for non-web notification
|
22
|
+
{'Timestamp' => Time.zone.now}
|
23
|
+
end
|
24
|
+
|
25
|
+
source = build_message(exception, enviroments)
|
26
|
+
|
27
|
+
RestClient.post @url, source: source, format: 'html'
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def request_option(request)
|
33
|
+
{
|
34
|
+
'URL' => request.original_url,
|
35
|
+
'HTTP Method' => request.method,
|
36
|
+
'IP Address' => request.remote_ip,
|
37
|
+
'Paramters' => request.filtered_parameters,
|
38
|
+
'Timestamp' => Time.zone.now
|
39
|
+
}
|
10
40
|
end
|
11
41
|
|
12
42
|
def build_message(exception, enviroments)
|
@@ -20,30 +50,12 @@ module ExceptionNotifier
|
|
20
50
|
<h4>Environments:</h4>
|
21
51
|
<table>
|
22
52
|
<tbody>
|
23
|
-
#{table_rows_from(enviroments)}
|
53
|
+
#{table_rows_from(@options.merge(enviroments))}
|
24
54
|
</tbody>
|
25
55
|
</table>
|
26
56
|
HTML
|
27
57
|
end
|
28
58
|
|
29
|
-
def call(exception, options={})
|
30
|
-
env = options[:env]
|
31
|
-
|
32
|
-
request = ActionDispatch::Request.new(env)
|
33
|
-
|
34
|
-
source = build_message(exception,
|
35
|
-
'URL' => request.original_url,
|
36
|
-
'HTTP Method' => request.method,
|
37
|
-
'IP Address' => request.remote_ip,
|
38
|
-
'Paramters' => request.filtered_parameters,
|
39
|
-
'Timestamp' => Time.zone.now
|
40
|
-
)
|
41
|
-
|
42
|
-
RestClient.post @url, source: source, format: 'html'
|
43
|
-
end
|
44
|
-
|
45
|
-
private
|
46
|
-
|
47
59
|
def table_rows_from(hash)
|
48
60
|
hash.each_with_object('') { |(key, value), rows|
|
49
61
|
rows << "<tr><th>#{key}</th><td>#{value}</td></tr>"
|
@@ -1,7 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ExceptionNotifier::IdobataNotifier do
|
4
|
-
let(:notifier)
|
4
|
+
let(:notifier) do
|
5
|
+
described_class.new(
|
6
|
+
:url => 'https://idobata.io/hook/endpoint',
|
7
|
+
'Rails ENV' => 'staging'
|
8
|
+
)
|
9
|
+
end
|
5
10
|
|
6
11
|
describe '#initialize' do
|
7
12
|
it 'should set url' do
|
@@ -22,7 +27,7 @@ describe ExceptionNotifier::IdobataNotifier do
|
|
22
27
|
}
|
23
28
|
}
|
24
29
|
|
25
|
-
subject { notifier.build_message
|
30
|
+
subject { notifier.send(:build_message, exception, enviroments) }
|
26
31
|
|
27
32
|
before do
|
28
33
|
allow(exception).to receive(:backtrace).and_return(backtrace)
|
@@ -38,7 +43,7 @@ describe ExceptionNotifier::IdobataNotifier do
|
|
38
43
|
<h4>Environments:</h4>
|
39
44
|
<table>
|
40
45
|
<tbody>
|
41
|
-
<tr><th>URL</th><td>http://hrysd.org</td></tr><tr><th>HTTP Method</th><td>GET</td></tr><tr><th>IP Address</th><td>127.0.0.1</td></tr><tr><th>Paramters</th><td>{"controller"=>"welcome", "action"=>"index"}</td></tr><tr><th>Timestamp</th><td>2014-03-16 16:30:35 +900</td></tr>
|
46
|
+
<tr><th>Rails ENV</th><td>staging</td></tr><tr><th>URL</th><td>http://hrysd.org</td></tr><tr><th>HTTP Method</th><td>GET</td></tr><tr><th>IP Address</th><td>127.0.0.1</td></tr><tr><th>Paramters</th><td>{"controller"=>"welcome", "action"=>"index"}</td></tr><tr><th>Timestamp</th><td>2014-03-16 16:30:35 +900</td></tr>
|
42
47
|
</tbody>
|
43
48
|
</table>
|
44
49
|
HTML
|
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: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hiroshi Yoshida
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: exception_notification
|