1
- require 'net/http'
2
1
require 'net/https'
3
2
require 'builder'
4
3
require 'uri'
@@ -12,15 +11,15 @@ module Failure
12
11
# Resque::Failure::Hoptoad.configure do |config|
13
12
# config.api_key = 'blah'
14
13
# config.secure = true
15
- #
14
+ #
16
15
# # optional proxy support
17
16
# config.proxy_host = 'x.y.z.t'
18
17
# config.proxy_port = 8080
19
18
# end
20
19
class Hoptoad < Base
21
- #from the hoptoad plugin
22
- INPUT_FORMAT = %r{ ^([^:]+):(\d +)(?::in `([^']+)')?$} . freeze
23
-
20
+ # From the hoptoad plugin
21
+ INPUT_FORMAT = / ^([^:]+):(\d +)(?::in `([^']+)')?$/
22
+
24
23
class << self
25
24
attr_accessor :secure , :api_key , :proxy_host , :proxy_port
26
25
end
@@ -36,14 +35,11 @@ def self.configure
36
35
Resque ::Failure . backend = self
37
36
end
38
37
39
- def request
40
- use_proxy? ? Net ::HTTP ::Proxy ( self . class . proxy_host , self . class . proxy_port ) : Net ::HTTP
41
- end
42
-
43
38
def save
44
39
http = use_ssl? ? :https : :http
45
40
url = URI . parse ( "#{ http } ://hoptoadapp.com/notifier_api/v2/notices" )
46
41
42
+ request = Net ::HTTP ::Proxy ( self . class . proxy_host , self . class . proxy_port )
47
43
http = request . new ( url . host , url . port )
48
44
headers = {
49
45
'Content-type' => 'text/xml' ,
@@ -52,9 +48,9 @@ def save
52
48
53
49
http . read_timeout = 5 # seconds
54
50
http . open_timeout = 2 # seconds
55
-
51
+
56
52
http . use_ssl = use_ssl?
57
-
53
+
58
54
begin
59
55
response = http . post ( url . path , xml , headers )
60
56
rescue TimeoutError => e
@@ -69,7 +65,7 @@ def save
69
65
log "Hoptoad Failure: #{ response . class } \n #{ body } "
70
66
end
71
67
end
72
-
68
+
73
69
def xml
74
70
x = Builder ::XmlMarkup . new
75
71
x . instruct!
@@ -102,21 +98,17 @@ def xml
102
98
x . tag! ( "server-environment" ) do
103
99
x . tag! ( "environment-name" , RAILS_ENV )
104
100
end
105
-
101
+
106
102
end
107
103
end
108
-
104
+
109
105
def fill_in_backtrace_lines ( x )
110
106
exception . backtrace . each do |unparsed_line |
111
107
_ , file , number , method = unparsed_line . match ( INPUT_FORMAT ) . to_a
112
108
x . line :file => file , :number => number
113
109
end
114
110
end
115
111
116
- def use_proxy?
117
- self . class . proxy_host
118
- end
119
-
120
112
def use_ssl?
121
113
self . class . secure
122
114
end
0 commit comments