1
1
require 'net/http'
2
+ require 'net/https'
2
3
require 'builder'
4
+ require 'uri'
3
5
4
6
module Resque
5
7
module Failure
@@ -10,18 +12,17 @@ module Failure
10
12
# Resque::Failure::Hoptoad.configure do |config|
11
13
# config.api_key = 'blah'
12
14
# config.secure = true
13
- # config.subdomain = 'your_hoptoad_subdomain'
15
+ #
16
+ # # optional proxy support
17
+ # config.proxy_host = 'x.y.z.t'
18
+ # config.proxy_port = 8080
14
19
# end
15
20
class Hoptoad < Base
16
21
#from the hoptoad plugin
17
22
INPUT_FORMAT = %r{^([^:]+):(\d +)(?::in `([^']+)')?$} . freeze
18
23
19
24
class << self
20
- attr_accessor :secure , :api_key , :subdomain
21
- end
22
-
23
- def self . url
24
- "http://#{ subdomain } .hoptoadapp.com/" if subdomain
25
+ attr_accessor :secure , :api_key , :proxy_host , :proxy_port
25
26
end
26
27
27
28
def self . count
@@ -35,13 +36,15 @@ def self.configure
35
36
Resque ::Failure . backend = self
36
37
end
37
38
38
-
39
+ def request
40
+ use_proxy? ? Net ::HTTP ::Proxy ( self . class . proxy_host , self . class . proxy_port ) : Net ::HTTP
41
+ end
39
42
40
43
def save
41
44
http = use_ssl? ? :https : :http
42
45
url = URI . parse ( "#{ http } ://hoptoadapp.com/notifier_api/v2/notices" )
43
46
44
- http = Net :: HTTP . new ( url . host , url . port )
47
+ http = request . new ( url . host , url . port )
45
48
headers = {
46
49
'Content-type' => 'text/xml' ,
47
50
'Accept' => 'text/xml, application/xml'
@@ -51,7 +54,7 @@ def save
51
54
http . open_timeout = 2 # seconds
52
55
53
56
http . use_ssl = use_ssl?
54
-
57
+
55
58
begin
56
59
response = http . post ( url . path , xml , headers )
57
60
rescue TimeoutError => e
@@ -110,6 +113,10 @@ def fill_in_backtrace_lines(x)
110
113
end
111
114
end
112
115
116
+ def use_proxy?
117
+ self . class . proxy_host
118
+ end
119
+
113
120
def use_ssl?
114
121
self . class . secure
115
122
end
0 commit comments