undantag 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +16 -1
- data/lib/undantag/notifier.rb +6 -4
- data/lib/undantag/version.rb +1 -1
- data/spec/undantag/notifier_spec.rb +5 -3
- metadata +2 -2
data/README.md
CHANGED
@@ -18,7 +18,22 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
In your sinatra application add the following lines
|
22
|
+
|
23
|
+
configure :production do
|
24
|
+
set :show_exceptions, false
|
25
|
+
Undantag.configure(api_key: ENV['UNDANTAG_API_KEY']
|
26
|
+
github_user: ENV['GITHUB_USER']
|
27
|
+
github_repo: ENV['GITHUB_REPO'])
|
28
|
+
end
|
29
|
+
error do
|
30
|
+
if ENV['RACK_ENV'] == 'production'
|
31
|
+
require 'undantag'
|
32
|
+
resp = Undantag::Notifier.notify(env,
|
33
|
+
env['sinatra.error'],
|
34
|
+
Rack::Request.new(env))
|
35
|
+
end
|
36
|
+
end
|
22
37
|
|
23
38
|
## Contributing
|
24
39
|
|
data/lib/undantag/notifier.rb
CHANGED
@@ -1,16 +1,18 @@
|
|
1
1
|
require 'net/https'
|
2
|
+
require 'pp'
|
2
3
|
|
3
4
|
module Undantag
|
4
5
|
class Notifier
|
5
6
|
URL = "https://undantag.herokuapp.com/exception"
|
6
|
-
def self.notify
|
7
|
+
def self.notify env, exception, request
|
7
8
|
config_vars = Undantag::Configuration.to_hash
|
8
9
|
unless config_vars[:api_key]
|
9
10
|
raise Undantag::ConfigurationError::NoApiKey
|
10
11
|
end
|
11
|
-
post_params = config_vars.merge(env:
|
12
|
-
request: request
|
13
|
-
|
12
|
+
post_params = config_vars.merge(env: PP.pp(env, ""),
|
13
|
+
request: PP.pp(request, ""),
|
14
|
+
backtrace: exception.backtrace.join("\n"),
|
15
|
+
exception: PP.pp(exception, ''))
|
14
16
|
|
15
17
|
uri = URI(Notifier::URL)
|
16
18
|
http = Net::HTTP.new(uri.host, uri.port)
|
data/lib/undantag/version.rb
CHANGED
@@ -11,28 +11,30 @@ describe Undantag::Notifier do
|
|
11
11
|
github_user: ENV['GITHUB_USER'],
|
12
12
|
github_repo: ENV['GITHUB_REPO']
|
13
13
|
}
|
14
|
+
excpetion = Exception.new
|
14
15
|
before do
|
15
16
|
Undantag::Configuration.stub(:to_hash).and_return(config_vars)
|
16
17
|
Undantag::Configuration.stub(:api_key).and_return(config_vars[:api_key])
|
17
18
|
Undantag.stub(:configure)
|
19
|
+
excpetion.set_backtrace("super backtrace")
|
18
20
|
end
|
19
21
|
it 'makes a post to the server when notify is called' do
|
20
22
|
VCR.use_cassette("undantag-server-authorized") do
|
21
23
|
Undantag.configure(config_vars)
|
22
|
-
Undantag::Notifier.notify(
|
24
|
+
Undantag::Notifier.notify('env', excpetion, 'req')
|
23
25
|
end
|
24
26
|
end
|
25
27
|
it 'throws Undantag::NotAuthorized when a 401 is returned' do
|
26
28
|
VCR.use_cassette("undantag-server-not-authorized") do
|
27
29
|
wrong = config_vars.merge(api_key: "this isn't right")
|
28
30
|
Undantag::Configuration.stub(:to_hash).and_return(wrong)
|
29
|
-
expect { Undantag::Notifier.notify(
|
31
|
+
expect { Undantag::Notifier.notify('env', excpetion, 'req') }.to raise_error(Undantag::NotAuthorized)
|
30
32
|
end
|
31
33
|
end
|
32
34
|
it 'throws "Undantag::ConfigurationError::NoApiKey" if send is called' do
|
33
35
|
#temp hack
|
34
36
|
Undantag::Configuration.stub(:to_hash).and_return({})
|
35
|
-
expect { Undantag::Notifier.notify(
|
37
|
+
expect { Undantag::Notifier.notify('env', excpetion, 'req') }.to raise_error(Undantag::ConfigurationError::NoApiKey)
|
36
38
|
end
|
37
39
|
end
|
38
40
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: undantag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-21 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Gem for the exception service UNDANTAG
|
15
15
|
email:
|