Skip to content

Commit ad163ff

Browse files
committed
Merge branch 'master' of github.com:defunkt/resque
2 parents 1821fcd + 86d4a97 commit ad163ff

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

lib/resque/failure/hoptoad.rb

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
require 'net/http'
2+
require 'net/https'
23
require 'builder'
4+
require 'uri'
35

46
module Resque
57
module Failure
@@ -10,18 +12,17 @@ module Failure
1012
# Resque::Failure::Hoptoad.configure do |config|
1113
# config.api_key = 'blah'
1214
# 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
1419
# end
1520
class Hoptoad < Base
1621
#from the hoptoad plugin
1722
INPUT_FORMAT = %r{^([^:]+):(\d+)(?::in `([^']+)')?$}.freeze
1823

1924
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
2526
end
2627

2728
def self.count
@@ -35,13 +36,15 @@ def self.configure
3536
Resque::Failure.backend = self
3637
end
3738

38-
39+
def request
40+
use_proxy? ? Net::HTTP::Proxy(self.class.proxy_host, self.class.proxy_port) : Net::HTTP
41+
end
3942

4043
def save
4144
http = use_ssl? ? :https : :http
4245
url = URI.parse("#{http}://hoptoadapp.com/notifier_api/v2/notices")
4346

44-
http = Net::HTTP.new(url.host, url.port)
47+
http = request.new(url.host, url.port)
4548
headers = {
4649
'Content-type' => 'text/xml',
4750
'Accept' => 'text/xml, application/xml'
@@ -51,7 +54,7 @@ def save
5154
http.open_timeout = 2 # seconds
5255

5356
http.use_ssl = use_ssl?
54-
57+
5558
begin
5659
response = http.post(url.path, xml, headers)
5760
rescue TimeoutError => e
@@ -110,6 +113,10 @@ def fill_in_backtrace_lines(x)
110113
end
111114
end
112115

116+
def use_proxy?
117+
self.class.proxy_host
118+
end
119+
113120
def use_ssl?
114121
self.class.secure
115122
end

0 commit comments

Comments
 (0)