exception_notification-idobata 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 15c121178f5cd30a18a3a478fc9d3ee54096a1a5
4
+ data.tar.gz: f60ca4b1ea1e2a3e5661458081553a4b237cb0c7
5
+ SHA512:
6
+ metadata.gz: 4259a25670828c2258e94f30a17955ed8956c0b4517f887aab31e3080647d772854d0b142fcec48e8259a19a3b6cacaa03d2e6e93ed613b872b276626606e8e4
7
+ data.tar.gz: 905307fa72225ab90a799880b1bf149ad3bc61d0cf1eccc999487726b76680051c1c995dafea91a45ddf492fc052d10b736771669ba04f4409218cd12169092c
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --warnings
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ notifications:
6
+ webhooks:
7
+ - https://idobata.io/hook/929ab950-8df9-405f-8a39-7189ab24cce2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in exception_notifier_idobata.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Hiroshi Yoshida
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,33 @@
1
+ # ExceptionNotification for Idobata [![Build Status](https://travis-ci.org/hrysd/exception_notification-idobata.png?branch=master)](https://travis-ci.org/hrysd/exception_notification-idobata)
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ gem 'exception_notification-idobata', github: 'hrysd/exception_notification-idobata'
8
+
9
+ And then execute:
10
+
11
+ $ bundle
12
+
13
+ ## Usage
14
+
15
+ ```ruby
16
+ Sample::Application.configure do
17
+ config.middleware.use
18
+ ExceptionNotification::Rack,
19
+ idobata: {
20
+ url: HOOK_ENDPOINT
21
+ }
22
+ end
23
+ ```
24
+
25
+ ![](https://f.cloud.github.com/assets/1663465/2419367/38329928-ab5c-11e3-8137-c9969848e52f.png)
26
+
27
+ ## Contributing
28
+
29
+ 1. Fork it ( http://github.com/hrysd/exception_notification-idobata/fork )
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
32
+ 4. Push to the branch (`git push origin my-new-feature`)
33
+ 5. Create new Pull Request
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,26 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'exception_notification/idobata/version'
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = 'exception_notification-idobata'
7
+ gem.version = ExceptionNotification::Idobata::VERSION
8
+ gem.authors = ['Hiroshi Yoshida']
9
+ gem.email = ['hrysd22@gmail.com']
10
+ gem.summary = %q{exception_notification for Idobata}
11
+ gem.description = %q{exception_notification for Idobata}
12
+ gem.homepage = 'https://github.com/hrysd/exception_notification-idobata'
13
+ gem.license = 'MIT'
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ['lib']
19
+
20
+ gem.add_dependency 'exception_notification', '~> 4.0.0'
21
+ gem.add_dependency 'rest-client'
22
+
23
+ gem.add_development_dependency 'bundler', '~> 1.5'
24
+ gem.add_development_dependency 'rake'
25
+ gem.add_development_dependency 'rspec', '~> 3.0.0.beta2'
26
+ end
@@ -0,0 +1 @@
1
+ require 'exception_notifier/idobata_notifier'
@@ -0,0 +1,5 @@
1
+ module ExceptionNotification
2
+ class Idobata
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
@@ -0,0 +1,77 @@
1
+ require 'exception_notification/idobata/version'
2
+ require 'rest-client'
3
+
4
+ module ExceptionNotifier
5
+ class IdobataNotifier
6
+ attr_reader :url
7
+
8
+ def initialize(options)
9
+ @url = options[:url]
10
+ end
11
+
12
+ def build_message(exception, enviroments)
13
+ return <<-HTML
14
+ <span class='label label-important'>#{exception.class.to_s}</span>
15
+ <b>#{CGI.escapeHTML(exception.message.inspect)}</b>
16
+
17
+ <h4>Backtrace:</h4>
18
+ <pre>#{format_backtrace(exception.backtrace).join("\n")}</pre>
19
+
20
+ <h4>Environments:</h4>
21
+ <table>
22
+ <tbody>
23
+ #{table_rows_from(enviroments)}
24
+ </tbody>
25
+ </table>
26
+ HTML
27
+ end
28
+
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
+ def table_rows_from(hash)
48
+ hash.each_with_object('') { |(key, value), rows|
49
+ rows << "<tr><th>#{key}</th><td>#{value}</td></tr>"
50
+ }
51
+ end
52
+
53
+ def format_backtrace(trace)
54
+ trace.map { |line|
55
+ if from_bundler?(line)
56
+ line.sub(bundle_root, '[bundle]...')
57
+ else
58
+ line.sub(app_root, '[app]...')
59
+ end
60
+ }
61
+ end
62
+
63
+ def from_bundler?(line)
64
+ if bundle_root
65
+ line.match(bundle_root)
66
+ end
67
+ end
68
+
69
+ def bundle_root
70
+ Bundler.bundle_path.to_s if defined?(Bundler)
71
+ end
72
+
73
+ def app_root
74
+ Dir.pwd
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe ExceptionNotifier::IdobataNotifier do
4
+ let(:notifier) { described_class.new(url: 'https://idobata.io/hook/endpoint') }
5
+
6
+ describe '#initialize' do
7
+ it 'should set url' do
8
+ expect(notifier.url).to eql('https://idobata.io/hook/endpoint')
9
+ end
10
+ end
11
+
12
+ describe '#build_message' do
13
+ let(:exception) { StandardError.new('hello, world') }
14
+ let(:backtrace) { ['spec/exception_notifier/idobata_notifier_spec.rb'] }
15
+ let(:enviroments) {
16
+ {
17
+ 'URL' => 'http://hrysd.org',
18
+ 'HTTP Method' => 'GET',
19
+ 'IP Address' => '127.0.0.1',
20
+ 'Paramters' => {'controller' => 'welcome', 'action' => 'index'},
21
+ 'Timestamp' => "2014-03-16 16:30:35 +900"
22
+ }
23
+ }
24
+
25
+ subject { notifier.build_message(exception, enviroments) }
26
+
27
+ before do
28
+ allow(exception).to receive(:backtrace).and_return(backtrace)
29
+ end
30
+
31
+ it { expect(subject).to eql(<<-HTML) }
32
+ <span class='label label-important'>StandardError</span>
33
+ <b>&quot;hello, world&quot;</b>
34
+
35
+ <h4>Backtrace:</h4>
36
+ <pre>spec/exception_notifier/idobata_notifier_spec.rb</pre>
37
+
38
+ <h4>Environments:</h4>
39
+ <table>
40
+ <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>
42
+ </tbody>
43
+ </table>
44
+ HTML
45
+ end
46
+ end
@@ -0,0 +1,83 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
4
+ # file to always be loaded, without a need to explicitly require it in any files.
5
+ #
6
+ # Given that it is always loaded, you are encouraged to keep this file as
7
+ # light-weight as possible. Requiring heavyweight dependencies from this file
8
+ # (such as loading up an entire rails app) will add to the boot time of your
9
+ # test suite on EVERY test run, even for an individual file that may not need
10
+ # all of that loaded.
11
+ #
12
+ # The `.rspec` file also contains a few flags that are not defaults but that
13
+ # users commonly want.
14
+ #
15
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
16
+
17
+ require 'exception_notification-idobata'
18
+
19
+ RSpec.configure do |config|
20
+ # The settings below are suggested to provide a good initial experience
21
+ # with RSpec, but feel free to customize to your heart's content.
22
+ # These two settings work together to allow you to limit a spec run
23
+ # to individual examples or groups you care about by tagging them with
24
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
25
+ # get run.
26
+ config.filter_run :focus
27
+ config.run_all_when_everything_filtered = true
28
+
29
+ # Many RSpec users commonly either run the entire suite or an individual
30
+ # file, and it's useful to allow more verbose output when running an
31
+ # individual spec file.
32
+ if config.files_to_run.one?
33
+ # RSpec filters the backtrace by default so as not to be so noisy.
34
+ # This causes the full backtrace to be printed when running a single
35
+ # spec file (e.g. to troubleshoot a particular spec failure).
36
+ config.full_backtrace = true
37
+
38
+ # Use the documentation formatter for detailed output,
39
+ # unless a formatter has already been configured
40
+ # (e.g. via a command-line flag).
41
+ config.formatter = 'doc' if config.formatters.none?
42
+ end
43
+
44
+ # Print the 10 slowest examples and example groups at the
45
+ # end of the spec run, to help surface which specs are running
46
+ # particularly slow.
47
+ config.profile_examples = 10
48
+
49
+ # Run specs in random order to surface order dependencies. If you find an
50
+ # order dependency and want to debug it, you can fix the order by providing
51
+ # the seed, which is printed after each run.
52
+ # --seed 1234
53
+ config.order = :random
54
+
55
+ # Seed global randomization in this process using the `--seed` CLI option.
56
+ # Setting this allows you to use `--seed` to deterministically reproduce
57
+ # test failures related to randomization by passing the same `--seed` value
58
+ # as the one that triggered the failure.
59
+ Kernel.srand config.seed
60
+
61
+ # rspec-expectations config goes here. You can use an alternate
62
+ # assertion/expectation library such as wrong or the stdlib/minitest
63
+ # assertions if you prefer.
64
+ config.expect_with :rspec do |expectations|
65
+ # Enable only the newer, non-monkey-patching expect syntax.
66
+ # For more details, see:
67
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
68
+ expectations.syntax = :expect
69
+ end
70
+
71
+ # rspec-mocks config goes here. You can use an alternate test double
72
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
73
+ config.mock_with :rspec do |mocks|
74
+ # Enable only the newer, non-monkey-patching expect syntax.
75
+ # For more details, see:
76
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
77
+ mocks.syntax = :expect
78
+
79
+ # Prevents you from mocking or stubbing a method that does not exist on
80
+ # a real object. This is generally recommended.
81
+ mocks.verify_partial_doubles = true
82
+ end
83
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: exception_notification-idobata
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Hiroshi Yoshida
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: exception_notification
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 4.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 4.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rest-client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 3.0.0.beta2
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 3.0.0.beta2
83
+ description: exception_notification for Idobata
84
+ email:
85
+ - hrysd22@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - .rspec
92
+ - .travis.yml
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - exception_notification-idobata.gemspec
98
+ - lib/exception_notification-idobata.rb
99
+ - lib/exception_notification/idobata/version.rb
100
+ - lib/exception_notifier/idobata_notifier.rb
101
+ - spec/exception_notifier/idobata_notifier_spec.rb
102
+ - spec/spec_helper.rb
103
+ homepage: https://github.com/hrysd/exception_notification-idobata
104
+ licenses:
105
+ - MIT
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.0.3
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: exception_notification for Idobata
127
+ test_files:
128
+ - spec/exception_notifier/idobata_notifier_spec.rb
129
+ - spec/spec_helper.rb