Created
August 15, 2012 18:02
-
-
Save kreeger/3361992 to your computer and use it in GitHub Desktop.
Hits up the Airbrake API for some commonly used tasks of ours.
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
#!/usr/bin/env ruby | |
# Hits up Airbrake to see what's happening. | |
require 'thor' | |
require 'httparty' | |
require 'logger' | |
require 'pp' | |
class AirbrakeAPI | |
include HTTParty | |
base_uri 'https://universaluclick.airbrake.io' | |
# default_params auth_token: 'AUTH_TOKEN_HERE' | |
format :xml | |
def error(error_id, options={}) | |
self.class.get "/errors/#{error_id}.xml", options | |
end | |
def error_notice(error_id, notice_id, options={}) | |
self.class.get "/errors/#{error_id}/notices/#{notice_id}.xml", options | |
end | |
def errors(options={}) | |
self.class.get "/errors.xml", options | |
end | |
def error_notices(error_id, options={}) | |
self.class.get("/errors/#{error_id}/notices.xml", options)['notices'] | |
end | |
end | |
class Airbrake < Thor | |
desc 'engine_feature_codes [OPTIONS]', 'Gets all feature codes from airbrake with missing assets.' | |
method_option :pages, type: :numeric, default: 20, alias: '-p', | |
desc: 'Specify how many pages back to look.' | |
def engine_feature_codes | |
log = Logger.new STDOUT | |
airbrake = AirbrakeAPI.new | |
error_notices = [] | |
options[:pages].times do |p| | |
error_notices << airbrake.error_notices(51565296, page: p).map { |n| n['error_message'] }.flatten | |
end | |
error_notices.flatten! | |
matches = error_notices.map do |n| | |
/contentstore\/(?<category>\w+)\/ | |
(?<code>\w+)\/(?<type>\w+)\/ | |
(?:(?<coloration>\w+)\/)? | |
(?<year>\d{4})/ix.match(n) | |
end | |
result = {} | |
matches.group_by { |m| m[:code] }.each do |code, matches| | |
result[code] ||= [] | |
result[code] << matches.collect { |mat| mat[:year] }.flatten.uniq | |
result[code].flatten!.sort! | |
end | |
pp result | |
end | |
end | |
Airbrake.start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment