undantag 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/fixtures/cassettes/undantag-server-authorized.yml +11 -15
- data/fixtures/cassettes/undantag-server-not-authorized.yml +11 -15
- data/lib/undantag/notifier.rb +16 -7
- data/lib/undantag/version.rb +1 -1
- data/spec/undantag/notifier_spec.rb +10 -6
- data/spec/undantag_spec.rb +1 -1
- metadata +1 -2
- data/fixtures/cassettes/undantag-server.yml +0 -39
@@ -2,10 +2,11 @@
|
|
2
2
|
http_interactions:
|
3
3
|
- request:
|
4
4
|
method: post
|
5
|
-
uri:
|
5
|
+
uri: https://undantag.herokuapp.com/exception
|
6
6
|
body:
|
7
7
|
encoding: US-ASCII
|
8
|
-
string: api_key=<Undantag API key>&github_user
|
8
|
+
string: api_key=<Undantag API key>&github_user=<GitHub user>&github_repo=<GitHub
|
9
|
+
repo>&env=ENV&request=&exception=Exception
|
9
10
|
headers:
|
10
11
|
Accept:
|
11
12
|
- ! '*/*'
|
@@ -15,25 +16,20 @@ http_interactions:
|
|
15
16
|
- application/x-www-form-urlencoded
|
16
17
|
response:
|
17
18
|
status:
|
18
|
-
code:
|
19
|
-
message:
|
19
|
+
code: 500
|
20
|
+
message: Internal Server Error
|
20
21
|
headers:
|
21
|
-
Server:
|
22
|
-
- nginx
|
23
|
-
Date:
|
24
|
-
- Sat, 20 Oct 2012 14:22:00 GMT
|
25
22
|
Content-Type:
|
26
|
-
- text/
|
23
|
+
- text/plain
|
24
|
+
Server:
|
25
|
+
- thin 1.5.0 codename Knife
|
27
26
|
Content-Length:
|
28
|
-
- '
|
27
|
+
- '21'
|
29
28
|
Connection:
|
30
29
|
- keep-alive
|
31
|
-
Keep-Alive:
|
32
|
-
- timeout=20
|
33
30
|
body:
|
34
31
|
encoding: US-ASCII
|
35
|
-
string:
|
36
|
-
Bad Gateway</h1></center>\r\n<hr><center>nginx</center>\r\n</body>\r\n</html>\r\n"
|
32
|
+
string: Internal server error
|
37
33
|
http_version:
|
38
|
-
recorded_at: Sat, 20 Oct 2012
|
34
|
+
recorded_at: Sat, 20 Oct 2012 15:55:05 GMT
|
39
35
|
recorded_with: VCR 2.2.5
|
@@ -2,10 +2,11 @@
|
|
2
2
|
http_interactions:
|
3
3
|
- request:
|
4
4
|
method: post
|
5
|
-
uri:
|
5
|
+
uri: https://undantag.herokuapp.com/exception
|
6
6
|
body:
|
7
7
|
encoding: US-ASCII
|
8
|
-
string: api_key
|
8
|
+
string: api_key=<Undantag API key>&github_user=<GitHub user>&github_repo=<GitHub
|
9
|
+
repo>&env=ENV&request=&exception=Exception
|
9
10
|
headers:
|
10
11
|
Accept:
|
11
12
|
- ! '*/*'
|
@@ -15,25 +16,20 @@ http_interactions:
|
|
15
16
|
- application/x-www-form-urlencoded
|
16
17
|
response:
|
17
18
|
status:
|
18
|
-
code:
|
19
|
-
message:
|
19
|
+
code: 500
|
20
|
+
message: Internal Server Error
|
20
21
|
headers:
|
21
|
-
Server:
|
22
|
-
- nginx
|
23
|
-
Date:
|
24
|
-
- Sat, 20 Oct 2012 14:11:51 GMT
|
25
22
|
Content-Type:
|
26
|
-
- text/
|
23
|
+
- text/plain
|
24
|
+
Server:
|
25
|
+
- thin 1.5.0 codename Knife
|
27
26
|
Content-Length:
|
28
|
-
- '
|
27
|
+
- '21'
|
29
28
|
Connection:
|
30
29
|
- keep-alive
|
31
|
-
Keep-Alive:
|
32
|
-
- timeout=20
|
33
30
|
body:
|
34
31
|
encoding: US-ASCII
|
35
|
-
string:
|
36
|
-
Bad Gateway</h1></center>\r\n<hr><center>nginx</center>\r\n</body>\r\n</html>\r\n"
|
32
|
+
string: Internal server error
|
37
33
|
http_version:
|
38
|
-
recorded_at: Sat, 20 Oct 2012
|
34
|
+
recorded_at: Sat, 20 Oct 2012 15:55:06 GMT
|
39
35
|
recorded_with: VCR 2.2.5
|
data/lib/undantag/notifier.rb
CHANGED
@@ -1,18 +1,27 @@
|
|
1
|
+
require 'net/https'
|
2
|
+
|
1
3
|
module Undantag
|
2
4
|
class Notifier
|
3
5
|
URL = "https://undantag.herokuapp.com/exception"
|
4
6
|
def self.notify request, exception
|
5
|
-
|
7
|
+
config_vars = Undantag::Configuration.to_hash
|
8
|
+
unless config_vars[:api_key]
|
6
9
|
raise Undantag::ConfigurationError::NoApiKey
|
7
10
|
end
|
11
|
+
post_params = config_vars.merge(env: ENV.inspect,
|
12
|
+
request: request.inspect,
|
13
|
+
exception: exception.inspect)
|
14
|
+
|
8
15
|
uri = URI(Notifier::URL)
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
16
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
17
|
+
http.use_ssl = true
|
18
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
19
|
+
|
20
|
+
request = Net::HTTP::Post.new(uri.request_uri)
|
21
|
+
request.set_form_data(post_params)
|
13
22
|
|
14
|
-
|
15
|
-
case
|
23
|
+
response = http.request(request)
|
24
|
+
case response.code
|
16
25
|
when "401"
|
17
26
|
raise Undantag::NotAuthorized
|
18
27
|
end
|
data/lib/undantag/version.rb
CHANGED
@@ -7,27 +7,31 @@ require './lib/undantag/notifier'
|
|
7
7
|
class Undantag::Configuration; end
|
8
8
|
|
9
9
|
describe Undantag::Notifier do
|
10
|
+
config_vars = { api_key: ENV['UNDANTAG_API_KEY'],
|
11
|
+
github_user: ENV['GITHUB_USER'],
|
12
|
+
github_repo: ENV['GITHUB_REPO']
|
13
|
+
}
|
10
14
|
before do
|
15
|
+
Undantag::Configuration.stub(:to_hash).and_return(config_vars)
|
16
|
+
Undantag::Configuration.stub(:api_key).and_return(config_vars[:api_key])
|
11
17
|
Undantag.stub(:configure)
|
12
|
-
Undantag::Configuration.stub(:api_key)
|
13
18
|
end
|
14
19
|
it 'makes a post to the server when notify is called' do
|
15
20
|
VCR.use_cassette("undantag-server-authorized") do
|
16
|
-
Undantag.configure(
|
17
|
-
github_user: ENV['GITHUB_USER'],
|
18
|
-
github_repo: ENV['GITHUB_REPO'])
|
21
|
+
Undantag.configure(config_vars)
|
19
22
|
Undantag::Notifier.notify(nil, Exception.to_s)
|
20
23
|
end
|
21
24
|
end
|
22
25
|
it 'throws Undantag::NotAuthorized when a 401 is returned' do
|
23
26
|
VCR.use_cassette("undantag-server-not-authorized") do
|
24
|
-
|
27
|
+
wrong = config_vars.merge(api_key: "this isn't right")
|
28
|
+
Undantag::Configuration.stub(:to_hash).and_return(wrong)
|
25
29
|
expect { Undantag::Notifier.notify(nil, Exception.to_s) }.to raise_error(Undantag::NotAuthorized)
|
26
30
|
end
|
27
31
|
end
|
28
32
|
it 'throws "Undantag::ConfigurationError::NoApiKey" if send is called' do
|
29
33
|
#temp hack
|
30
|
-
Undantag.
|
34
|
+
Undantag::Configuration.stub(:to_hash).and_return({})
|
31
35
|
expect { Undantag::Notifier.notify(nil, Exception.to_s) }.to raise_error(Undantag::ConfigurationError::NoApiKey)
|
32
36
|
end
|
33
37
|
end
|
data/spec/undantag_spec.rb
CHANGED
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.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -25,7 +25,6 @@ files:
|
|
25
25
|
- Rakefile
|
26
26
|
- fixtures/cassettes/undantag-server-authorized.yml
|
27
27
|
- fixtures/cassettes/undantag-server-not-authorized.yml
|
28
|
-
- fixtures/cassettes/undantag-server.yml
|
29
28
|
- lib/undantag.rb
|
30
29
|
- lib/undantag/configuration.rb
|
31
30
|
- lib/undantag/exceptions.rb
|
@@ -1,39 +0,0 @@
|
|
1
|
-
---
|
2
|
-
http_interactions:
|
3
|
-
- request:
|
4
|
-
method: post
|
5
|
-
uri: http://undantag.duh.se/exception
|
6
|
-
body:
|
7
|
-
encoding: US-ASCII
|
8
|
-
string: api_key=super+seceret+api+key&github_user&github_repo&title=test&body=Exception
|
9
|
-
headers:
|
10
|
-
Accept:
|
11
|
-
- ! '*/*'
|
12
|
-
User-Agent:
|
13
|
-
- Ruby
|
14
|
-
Content-Type:
|
15
|
-
- application/x-www-form-urlencoded
|
16
|
-
response:
|
17
|
-
status:
|
18
|
-
code: 502
|
19
|
-
message: Bad Gateway
|
20
|
-
headers:
|
21
|
-
Server:
|
22
|
-
- nginx
|
23
|
-
Date:
|
24
|
-
- Sat, 20 Oct 2012 14:05:17 GMT
|
25
|
-
Content-Type:
|
26
|
-
- text/html
|
27
|
-
Content-Length:
|
28
|
-
- '166'
|
29
|
-
Connection:
|
30
|
-
- keep-alive
|
31
|
-
Keep-Alive:
|
32
|
-
- timeout=20
|
33
|
-
body:
|
34
|
-
encoding: US-ASCII
|
35
|
-
string: ! "<html>\r\n<head><title>502 Bad Gateway</title></head>\r\n<body bgcolor=\"white\">\r\n<center><h1>502
|
36
|
-
Bad Gateway</h1></center>\r\n<hr><center>nginx</center>\r\n</body>\r\n</html>\r\n"
|
37
|
-
http_version:
|
38
|
-
recorded_at: Sat, 20 Oct 2012 14:05:19 GMT
|
39
|
-
recorded_with: VCR 2.2.5
|