Created
September 19, 2008 06:12
-
-
Save methodmissing/11554 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HoptoadNotifier::Catcher.class_eval do | |
alias :original_send_to_hoptoad :send_to_hoptoad | |
def send_to_hoptoad data | |
async_hoptoad_notification? ? async_send_to_hoptoad( data ) : original_send_to_hoptoad( data ) | |
end | |
def async_hoptoad_notification? | |
if Object.const_defined?(:EventMachine) | |
EventMachine.reactor_running? | |
else | |
false | |
end | |
end | |
def async_send_to_hoptoad( data ) | |
url = HoptoadNotifier.url | |
http = EventMachine::Protocols::HttpClient.request( | |
:host => url.host, | |
:port => 80, | |
:request => url.path, | |
:verb => :post, | |
:contenttype => 'application/x-yaml', | |
:content => stringify_keys(data).to_yaml | |
) | |
http.callback do |response| | |
logger.info "Hoptoad Success: #{response[:status].to_s}" | |
end | |
http.errback do |response| | |
logger.error "Hoptoad Failure: #{response[:status].to_s}\n#{response[:content]}" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment