Sha256: 845fe96ecf204b1e3bfe9511cfe9eb168d8c4b34ed1b923694922f28f6d60aa6
Contents?: true
Size: 1.79 KB
Versions: 2
Compression:
Stored size: 1.79 KB
Contents
# using multipart post require 'net/http/post/multipart' module HockeyBrake # Sends out the notice to HockeyApp class HockeySender < Airbrake::Sender # initialize the sender def initialize super(Airbrake.configuration.to_hash) end # Sends the notice data off to HockeyApp for processing. # # @param [String] data The XML notice to be sent off def send_to_airbrake(data) # generate the log logstr = HockeyLog.generate(data) # store the data into temp file file = Tempfile.new('hockey-exception') file.write(logstr) file.close # buidl the url url = URI.parse(HockeyBrake.configuration.hockey_url) # send the request response = begin File.open(file.path) do |log| req = Net::HTTP::Post::Multipart.new url.path, "log" => UploadIO.new(log, 'application/octet-stream', "log.txt") Net::HTTP.start(url.host, url.port, :use_ssl => url.scheme == 'https') do |http| http.request(req) end end rescue *HTTP_ERRORS => e log :error, "Unable to contact the HockeyApp server. HTTP Error=#{e}" nil end # remove the file file.unlink case response when Net::HTTPSuccess then log :info, "Success: #{response.class}", response else log :error, "Failure: #{response.class}", response end if response && response.respond_to?(:body) error_id = response.body.match(%r{<id[^>]*>(.*?)</id>}) error_id[1] if error_id end rescue => e log :error, "[HockeyBrake::HockeySender#send_to_airbrake] Cannot send notification. Error: #{e.class} - #{e.message}\nBacktrace:\n#{e.backtrace.join("\n\t")}" nil end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
hockeybrake-0.0.3 | lib/hockeybrake/hockey_sender.rb |
hockeybrake-0.0.2 | lib/hockeybrake/hockey_sender.rb |