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: 15c121178f5cd30a18a3a478fc9d3ee54096a1a5
4
- data.tar.gz: f60ca4b1ea1e2a3e5661458081553a4b237cb0c7
3
+ metadata.gz: ade18db9b418ae3b8003b3b97ad2a38292251fdf
4
+ data.tar.gz: 5efb9417aef0b6126fac3dee7dbead6fa2e4948f
5
5
  SHA512:
6
- metadata.gz: 4259a25670828c2258e94f30a17955ed8956c0b4517f887aab31e3080647d772854d0b142fcec48e8259a19a3b6cacaa03d2e6e93ed613b872b276626606e8e4
7
- data.tar.gz: 905307fa72225ab90a799880b1bf149ad3bc61d0cf1eccc999487726b76680051c1c995dafea91a45ddf492fc052d10b736771669ba04f4409218cd12169092c
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
- gem 'exception_notification-idobata', github: 'hrysd/exception_notification-idobata'
8
-
7
+ ```ruby
8
+ gem 'exception_notification'
9
+ gem 'exception_notification-idobata'
10
+ ```
9
11
  And then execute:
10
12
 
11
- $ bundle
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: HOOK_ENDPOINT
25
+ url: HOOK_ENDPOINT,
26
+ stage: 'Optional params as you like'
21
27
  }
22
28
  end
23
29
  ```
@@ -1,5 +1,5 @@
1
1
  module ExceptionNotification
2
2
  class Idobata
3
- VERSION = '0.0.1'
3
+ VERSION = '0.0.2'
4
4
  end
5
5
  end
@@ -6,7 +6,37 @@ module ExceptionNotifier
6
6
  attr_reader :url
7
7
 
8
8
  def initialize(options)
9
- @url = options[:url]
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) { described_class.new(url: 'https://idobata.io/hook/endpoint') }
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(exception, enviroments) }
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.1
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-16 00:00:00.000000000 Z
11
+ date: 2014-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: exception_notification