Skip to content

Instantly share code, notes, and snippets.

@jamie
Created November 9, 2009 13:52
Show Gist options
  • Save jamie/229952 to your computer and use it in GitHub Desktop.
Save jamie/229952 to your computer and use it in GitHub Desktop.
I'm far to lazy to manually close several hundred hoptoad errors, so I automated it!
require 'rubygems'
require 'activesupport'
require 'restclient'
require 'hpricot'
module Hoptoad
class API
attr_accessor :dirty
def initialize(base, token)
@base, @token = base, token
end
def each
page = 1
loop do
begin
page_xml = RestClient.get(errors_uri(page))
errors = (Hpricot.parse(page_xml)/'group')
break if errors.empty?
errors.each do |error_xml|
yield Toad.new(error_xml, self)
end
rescue => e
puts "Error getting page contents: #{e.message}"
end
page += 1 unless @dirty
@dirty = false
end
end
def errors_uri(page=1)
"#{@base}/errors.xml?auth_token=#{@token}&page=#{page}"
end
def error_uri(id)
"#{@base}/errors/#{id}?auth_token=#{@token}"
end
end
class Toad
def initialize(xml, api)
@xml = xml
@api = api
end
# Object#id isn't deprecated yet :/
def id
method_missing(:id)
end
def method_missing(method, *args)
if (node = @xml/method.to_s.gsub('_','-')) && !node.empty?
node.first.innerHTML
else
super
end
end
def resolve!
@api.dirty = true
RestClient.put(uri, :group => {:resolved => true})
end
def uri
@api.error_uri(self.id)
end
end
end
require 'hoptoad_api'
token = "..."
base_uri = "..."
Hoptoad::API.new(base_uri, token).each do |toad|
# Don't want to worry about ancient errors that haven't resurfaced lately
# and don't want to close a few hundred hoptoads manually.
time = Time.parse(toad.most_recent_notice_at)
if time < 14.days.ago
p [toad.id, toad.error_message]
toad.resolve!
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment