Created
November 9, 2009 13:52
-
-
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!
This file contains 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
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 |
This file contains 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
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