toadhopper 0.9 → 0.9.1
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.
- data/Gemfile +1 -0
- data/lib/toadhopper.rb +35 -34
- metadata +12 -2
data/Gemfile
CHANGED
data/lib/toadhopper.rb
CHANGED
@@ -5,8 +5,8 @@ require 'nokogiri'
|
|
5
5
|
|
6
6
|
# Posts errors to the Hoptoad API
|
7
7
|
class ToadHopper
|
8
|
-
VERSION = "0.9"
|
9
|
-
|
8
|
+
VERSION = "0.9.1"
|
9
|
+
|
10
10
|
# Hoptoad API response
|
11
11
|
class Response < Struct.new(:status, :body, :errors); end
|
12
12
|
|
@@ -27,44 +27,46 @@ class ToadHopper
|
|
27
27
|
end
|
28
28
|
|
29
29
|
# Posts an exception to hoptoad.
|
30
|
-
# Toadhopper.new('apikey').post!(error, {:action => 'show', :controller => 'Users'})
|
31
|
-
# The Following Keys are available as parameters to the document_options
|
32
|
-
# url The url for the request, required to post but not useful in a console environment
|
33
|
-
# component Normally this is your Controller name in an MVC framework
|
34
|
-
# action Normally the action for your request in an MVC framework
|
35
|
-
# request An object that response to #params and returns a hash
|
36
|
-
# notifier_name Say you're a different notifier than ToadHopper
|
37
|
-
# notifier_version Specify the version of your custom notifier
|
38
|
-
# notifier_url Specify the project URL of your custom notifier
|
39
|
-
# session A hash of the user session in a web request
|
40
|
-
# framework_env The framework environment your app is running under
|
41
|
-
# backtrace Normally not needed, parsed automatically from the provided exception parameter
|
42
|
-
# environment You MUST scrub your environment if you plan to use this, please do not use it though. :)
|
43
|
-
# project_root The root directory of your app
|
44
30
|
#
|
45
|
-
# @
|
46
|
-
|
47
|
-
|
31
|
+
# @param [Exception] error the error to post
|
32
|
+
#
|
33
|
+
# @param [Hash] options
|
34
|
+
# @option options [String] url The url for the request, required to post but not useful in a console environment
|
35
|
+
# @option options [String] component Normally this is your Controller name in an MVC framework
|
36
|
+
# @option options [String] action Normally the action for your request in an MVC framework
|
37
|
+
# @option options [#params] request An object that response to #params and returns a hash
|
38
|
+
# @option options [String] notifier_name Say you're a different notifier than ToadHopper
|
39
|
+
# @option options [String] notifier_version Specify the version of your custom notifier
|
40
|
+
# @option options [String] notifier_url Specify the project URL of your custom notifier
|
41
|
+
# @option options [Hash] session A hash of the user session in a web request
|
42
|
+
# @option options [String] framework_env The framework environment your app is running under
|
43
|
+
# @option options [Array] backtrace Normally not needed, parsed automatically from the provided exception parameter
|
44
|
+
# @option options [Hash] environment You MUST scrub your environment if you plan to use this, please do not use it though. :)
|
45
|
+
# @option options [String] project_root The root directory of your app
|
46
|
+
#
|
47
|
+
# @param [Hash] http_headers extra HTTP headers to be sent in the post to the API
|
48
|
+
#
|
49
|
+
# @example
|
50
|
+
# Toadhopper.new('apikey').post! error,
|
51
|
+
# {:action => 'show', :controller => 'Users'},
|
52
|
+
# {'X-Hoptoad-Client-Name' => 'My Awesome Notifier'}
|
53
|
+
#
|
54
|
+
# @return [Response]
|
55
|
+
def post!(error, options={}, http_headers={})
|
56
|
+
options[:notifier_name] ||= 'ToadHopper'
|
57
|
+
post_document(document_for(error, options), {'X-Hoptoad-Client-Name' => options[:notifier_name]})
|
48
58
|
end
|
49
59
|
|
50
|
-
# Posts a v2 document error to Hoptoad
|
51
|
-
# header_options can be passed in to indicate you're posting from a separate client
|
52
|
-
# Toadhopper.new('API KEY').post_document(doc, 'X-Hoptoad-Client-Name' => 'MyCustomLib')
|
53
|
-
#
|
54
60
|
# @private
|
55
|
-
def post_document(document,
|
61
|
+
def post_document(document, headers={})
|
56
62
|
uri = URI.parse("http://hoptoadapp.com:80/notifier_api/v2/notices")
|
57
|
-
|
58
63
|
Net::HTTP.start(uri.host, uri.port) do |http|
|
59
|
-
headers = {
|
60
|
-
'Content-type' => 'text/xml',
|
61
|
-
'Accept' => 'text/xml, application/xml',
|
62
|
-
'X-Hoptoad-Client-Name' => 'Toadhopper',
|
63
|
-
}.merge(header_options)
|
64
64
|
http.read_timeout = 5 # seconds
|
65
65
|
http.open_timeout = 2 # seconds
|
66
66
|
begin
|
67
|
-
response = http.post
|
67
|
+
response = http.post uri.path,
|
68
|
+
document,
|
69
|
+
{'Content-type' => 'text/xml', 'Accept' => 'text/xml, application/xml'}.merge(headers)
|
68
70
|
Response.new response.code.to_i,
|
69
71
|
response.body,
|
70
72
|
Nokogiri::XML.parse(response.body).xpath('//errors/error').map {|e| e.content}
|
@@ -76,7 +78,7 @@ class ToadHopper
|
|
76
78
|
|
77
79
|
# @private
|
78
80
|
def document_for(exception, options={})
|
79
|
-
|
81
|
+
defaults = {
|
80
82
|
:error => exception,
|
81
83
|
:api_key => api_key,
|
82
84
|
:environment => clean(ENV.to_hash),
|
@@ -85,7 +87,6 @@ class ToadHopper
|
|
85
87
|
:component => 'http://localhost/',
|
86
88
|
:action => nil,
|
87
89
|
:request => nil,
|
88
|
-
:notifier_name => 'ToadHopper',
|
89
90
|
:notifier_version => VERSION,
|
90
91
|
:notifier_url => 'http://github.com/toolmantim/toadhopper',
|
91
92
|
:session => {},
|
@@ -93,7 +94,7 @@ class ToadHopper
|
|
93
94
|
:project_root => Dir.pwd
|
94
95
|
}.merge(options)
|
95
96
|
|
96
|
-
Haml::Engine.new(notice_template).render(Object.new,
|
97
|
+
Haml::Engine.new(notice_template).render(Object.new, defaults)
|
97
98
|
end
|
98
99
|
|
99
100
|
# @private
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: toadhopper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Lucas
|
@@ -11,7 +11,7 @@ autorequire:
|
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
13
|
|
14
|
-
date: 2009-12-15 00:00:00
|
14
|
+
date: 2009-12-15 00:00:00 -08:00
|
15
15
|
default_executable:
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
@@ -24,6 +24,16 @@ dependencies:
|
|
24
24
|
- !ruby/object:Gem::Version
|
25
25
|
version: "2.0"
|
26
26
|
version:
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: nokogiri
|
29
|
+
type: :runtime
|
30
|
+
version_requirement:
|
31
|
+
version_requirements: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: "0"
|
36
|
+
version:
|
27
37
|
description:
|
28
38
|
email: t.lucas@toolmantim.com
|
29
39
|
executables: []
|