31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/batbugger/sender.rb', line 31
def send_to_batbugger(notice)
data = notice.is_a?(String) ? notice : notice.to_json
http = setup_http_connection
=
.merge!({ 'X-API-Key' => api_key}) unless api_key.nil?
response = begin
http.post(url.path, data, )
rescue *HTTP_ERRORS => e
log(:error, "Unable to contact the Batbugger server. HTTP Error=#{e}")
nil
end
case response
when Net::HTTPSuccess then
log(Batbugger.configuration.debug ? :info : :debug, "Success: #{response.class}", response, data)
JSON.parse(response.body)['id']
else
log(:error, "Failure: #{response.class}", response, data)
nil
end
rescue => e
log(:error, "[Batbugger::Sender#send_to_batbugger] Error: #{e.class} - #{e.message}\nBacktrace:\n#{e.backtrace.join("\n\t")}")
nil
end
|