urkel 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 +4 -4
- data/README.md +19 -3
- data/bin/urkel +0 -0
- data/lib/urkel.rb +25 -1
- data/lib/urkel/configuration.rb +24 -0
- data/lib/urkel/connection.rb +42 -0
- data/lib/urkel/version.rb +1 -1
- data/spec/lib/urkel/connection_spec.rb +54 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/urkel_spec.rb +16 -2
- data/urkel.gemspec +1 -0
- metadata +19 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b08306b3d170888b2b58b76345259f58f9fba77
|
4
|
+
data.tar.gz: 2bc42556fcf321d81bb90da96dadf71d3923d8fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e884504114aacd5e5647eb48e6975fb1d117d149f09cc839831a851de7e19d7565fc170be5137196ce5deff1b4903f1cbac1910c659e03974b95daa08fb34254
|
7
|
+
data.tar.gz: 5164ad3fa4d5a9248fcaad3acef16ecbb7627ea01f92ff2bba7584d1e8c7520fcae038245041bba90d7d678d91c85ed5795d619b7baa86d1252b2ce3bb912ccd
|
data/README.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
# Urkel
|
2
2
|
|
3
|
-
|
3
|
+

|
4
|
+
|
5
|
+
Ooops... did I do that?
|
6
|
+
|
7
|
+
The urkel gem is a client library that allows you to publish errors
|
8
|
+
to an [urkel](https://github.com/mokhan/urkel-api) instance.
|
4
9
|
|
5
10
|
## Installation
|
6
11
|
|
@@ -20,11 +25,22 @@ Or install it yourself as:
|
|
20
25
|
|
21
26
|
## Usage
|
22
27
|
|
23
|
-
|
28
|
+
# place in initializer
|
29
|
+
Urkel.configure do |configuration|
|
30
|
+
configuration.api_host = 'http://localhost:3000'
|
31
|
+
configuration.api_key = '02513a35-b875-40a1-a1fc-f2d2582bdcc5'
|
32
|
+
end
|
33
|
+
|
34
|
+
# usage
|
35
|
+
begin
|
36
|
+
0/1
|
37
|
+
rescue StandardError => error
|
38
|
+
Urkel.oops(error)
|
39
|
+
end
|
24
40
|
|
25
41
|
## Contributing
|
26
42
|
|
27
|
-
1. Fork it ( https://github.com/
|
43
|
+
1. Fork it ( https://github.com/mokhan/urkel/fork )
|
28
44
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
45
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
46
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/bin/urkel
CHANGED
File without changes
|
data/lib/urkel.rb
CHANGED
@@ -1,5 +1,29 @@
|
|
1
1
|
require "urkel/version"
|
2
|
+
require 'net/http'
|
3
|
+
require 'urkel/configuration'
|
4
|
+
require 'urkel/connection'
|
2
5
|
|
3
6
|
module Urkel
|
4
|
-
|
7
|
+
class InvalidConfigurationError < StandardError; end
|
8
|
+
class InvalidAPITokenError < StandardError; end
|
9
|
+
|
10
|
+
def self.configure
|
11
|
+
configuration = Configuration.new
|
12
|
+
yield configuration
|
13
|
+
@connection = Connection.new(configuration)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.oops(error)
|
17
|
+
raise InvalidConfigurationError.new unless @connection
|
18
|
+
@connection.publish(error)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.oops!(error)
|
22
|
+
raise InvalidConfigurationError.new unless @connection
|
23
|
+
@connection.publish!(error)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.reset
|
27
|
+
@connection = nil
|
28
|
+
end
|
5
29
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Urkel
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :api_host, :api_key
|
4
|
+
|
5
|
+
def initialize(api_host = '', api_key = '')
|
6
|
+
@api_host = api_host
|
7
|
+
@api_key = api_key
|
8
|
+
end
|
9
|
+
|
10
|
+
def request(request)
|
11
|
+
request['authorization'] = "Token token=#{api_key}"
|
12
|
+
http_connection.request(request)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def http_connection
|
18
|
+
uri = URI.parse(api_host)
|
19
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
20
|
+
http.use_ssl = (uri.scheme == "https")
|
21
|
+
http
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Urkel
|
2
|
+
class Connection
|
3
|
+
API_ENDPOINT="/api/v1/failures"
|
4
|
+
|
5
|
+
def initialize(configuration)
|
6
|
+
@configuration = configuration
|
7
|
+
end
|
8
|
+
|
9
|
+
def publish(error)
|
10
|
+
response = @configuration.request(request_for(error))
|
11
|
+
response.is_a?(Net::HTTPOK)
|
12
|
+
end
|
13
|
+
|
14
|
+
def publish!(error)
|
15
|
+
response = @configuration.request(request_for(error))
|
16
|
+
if response.is_a? Net::HTTPOK
|
17
|
+
true
|
18
|
+
elsif response.is_a? Net::HTTPUnauthorized
|
19
|
+
raise InvalidAPITokenError.new
|
20
|
+
else
|
21
|
+
false
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def request_for(error)
|
28
|
+
Net::HTTP::Post.new(API_ENDPOINT).tap do |request|
|
29
|
+
request.set_form_data(form_payload_for(error))
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def form_payload_for(error)
|
34
|
+
{
|
35
|
+
"error[message]" => error.message,
|
36
|
+
"error[hostname]" => Socket.gethostname,
|
37
|
+
"error[error_type]" => error.class.name,
|
38
|
+
"error[backtrace][]" => error.backtrace,
|
39
|
+
}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/urkel/version.rb
CHANGED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Urkel
|
4
|
+
describe Connection do
|
5
|
+
subject { Connection.new(configuration) }
|
6
|
+
|
7
|
+
describe "#publish" do
|
8
|
+
let(:hostname) { Socket.gethostname }
|
9
|
+
let(:error_hash) do
|
10
|
+
{
|
11
|
+
"error"=>
|
12
|
+
{
|
13
|
+
"message" => error.message,
|
14
|
+
"hostname" => hostname,
|
15
|
+
"error_type" => error.class.name,
|
16
|
+
"backtrace" => error.backtrace
|
17
|
+
}
|
18
|
+
}
|
19
|
+
end
|
20
|
+
let(:error) do
|
21
|
+
begin
|
22
|
+
1/0
|
23
|
+
rescue => error
|
24
|
+
error
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "given proper credentials" do
|
29
|
+
let(:configuration) { Configuration.new('http://localhost:3000', '02513a35-b875-40a1-a1fc-f2d2582bdcc5') }
|
30
|
+
|
31
|
+
it 'publishes a new error' do
|
32
|
+
stub_request(:post, "http://localhost:3000/api/v1/failures")
|
33
|
+
.with(body: error_hash, headers: { 'Authorization'=>'Token token=02513a35-b875-40a1-a1fc-f2d2582bdcc5' })
|
34
|
+
.to_return(status: 200, body: "", headers: {})
|
35
|
+
expect(subject.publish(error)).to be_truthy
|
36
|
+
expect(subject.publish!(error)).to be_truthy
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "when invalid credentials" do
|
41
|
+
let(:configuration) { Configuration.new('http://localhost:3000', 'blah') }
|
42
|
+
|
43
|
+
it 'raises a meaningful error' do
|
44
|
+
stub_request(:post, "http://localhost:3000/api/v1/failures")
|
45
|
+
.with(body: error_hash, headers: { 'Authorization' => 'Token token=blah' })
|
46
|
+
.to_return(status: 401, body: "HTTP Token: Access denied.", headers: {})
|
47
|
+
|
48
|
+
expect(subject.publish(error)).to be_falsey
|
49
|
+
expect(-> { subject.publish!(error) }).to raise_error(InvalidAPITokenError)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/urkel_spec.rb
CHANGED
@@ -5,7 +5,21 @@ describe Urkel do
|
|
5
5
|
expect(Urkel::VERSION).not_to be nil
|
6
6
|
end
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
describe ".oops" do
|
9
|
+
let(:error) { StandardError.new("Ooops... did i do that?") }
|
10
|
+
|
11
|
+
it 'publishes a new error' do
|
12
|
+
stub_request(:post, "http://localhost:3000/api/v1/failures").to_return(status: 200)
|
13
|
+
Urkel.configure do |configuration|
|
14
|
+
configuration.api_host = 'http://localhost:3000'
|
15
|
+
configuration.api_key = '02513a35-b875-40a1-a1fc-f2d2582bdcc5'
|
16
|
+
end
|
17
|
+
expect(Urkel.oops(error)).to be_truthy
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'raises an error when not configured' do
|
21
|
+
Urkel.reset
|
22
|
+
expect(-> { Urkel.oops(error) }).to raise_error(Urkel::InvalidConfigurationError)
|
23
|
+
end
|
10
24
|
end
|
11
25
|
end
|
data/urkel.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: urkel
|
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
|
- mo khan
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
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'
|
55
69
|
description: A client gem for posting errors to an urkel server.
|
56
70
|
email:
|
57
71
|
- mo@mokhan.ca
|
@@ -69,7 +83,10 @@ files:
|
|
69
83
|
- Rakefile
|
70
84
|
- bin/urkel
|
71
85
|
- lib/urkel.rb
|
86
|
+
- lib/urkel/configuration.rb
|
87
|
+
- lib/urkel/connection.rb
|
72
88
|
- lib/urkel/version.rb
|
89
|
+
- spec/lib/urkel/connection_spec.rb
|
73
90
|
- spec/spec_helper.rb
|
74
91
|
- spec/urkel_spec.rb
|
75
92
|
- urkel.gemspec
|
@@ -98,5 +115,6 @@ signing_key:
|
|
98
115
|
specification_version: 4
|
99
116
|
summary: A client gem for posting errors to an urkel server.
|
100
117
|
test_files:
|
118
|
+
- spec/lib/urkel/connection_spec.rb
|
101
119
|
- spec/spec_helper.rb
|
102
120
|
- spec/urkel_spec.rb
|