Skip to content

Instantly share code, notes, and snippets.

@methodmissing
Created September 19, 2008 06:12
Show Gist options
  • Save methodmissing/11554 to your computer and use it in GitHub Desktop.
Save methodmissing/11554 to your computer and use it in GitHub Desktop.
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