Skip to content

Instantly share code, notes, and snippets.

@dolzenko
Forked from croaky/hoptoad_api.rb
Created January 19, 2012 11:01
Show Gist options
  • Save dolzenko/1639418 to your computer and use it in GitHub Desktop.
Save dolzenko/1639418 to your computer and use it in GitHub Desktop.
Access the Hoptoad (http://hoptoadapp.com) API with Ruby's ActiveResource
class Hoptoad < ActiveResource::Base
self.site = "https://your_account.airbrake.io"
class << self
@@auth_token = 'your_auth_token'
def find(*arguments)
arguments = append_auth_token_to_params(*arguments)
super(*arguments)
end
def append_auth_token_to_params(*arguments)
opts = arguments.last.is_a?(Hash) ? arguments.pop : {}
opts = opts.has_key?(:params) ? opts : opts.merge(:params => {})
opts[:params] = opts[:params].merge(:auth_token => @@auth_token)
arguments << opts
arguments
end
end
end
class Error < Hoptoad
end
class Notice < Airbrake
self.prefix = "/errors/:error_id/"
self.format = :xml # Errors are only available in XML, WTF???
end
# Errors are paginated. You get 30 at a time.
@errors = Error.find :all
@errors = Error.find :all, :params => { :page => 2 }
@notices = Notice.find :all, :params => { :error_id => 123 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment