Created
April 16, 2013 16:08
-
-
Save iljaiwas/5397240 to your computer and use it in GitHub Desktop.
A ruby script that produces a JSON file for Panic's Status board. It produces a bar graph that shows the number of open crashes per application.
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/ruby | |
require 'rubygems' | |
require 'json' | |
require 'net/http' | |
require 'net/https' | |
def jsonResponseForURL(inURL) | |
uri = URI.parse(inURL) | |
http = Net::HTTP.new(uri.host, uri.port) | |
http.use_ssl = true | |
http.verify_mode = OpenSSL::SSL::VERIFY_NONE | |
request = Net::HTTP::Get.new(uri.request_uri) | |
request['X-HockeyAppToken'] = 'Your Hockey API Token' | |
response = http.request(request) | |
if response.code.to_i() >= 200 && response.code.to_i() < 300 | |
JSON.parse(response.body) | |
end | |
end | |
def writeStatusBoardJSON(crashDict) | |
datapoints = [] | |
crashDict.keys.sort.each do |key| | |
datapoints += [ "title" => key, "value" => crashDict[key] ] | |
end | |
earnings = { "title" => "Hockey", "datapoints" => datapoints} | |
graph = { "title" => "Open Crashes", "datasequences" => [earnings], "type" => "bar"} | |
container = { "graph" => graph } | |
File.open("HockeyOpenCrashes.json","w") do |f| | |
f.write(JSON.pretty_generate(container)) | |
end | |
`scp HockeyOpenCrashes.json www.yourserver.com:/htdocs/hidden-path/` | |
end | |
parsedResponse = jsonResponseForURL('https://rink.hockeyapp.net/api/2/apps') | |
openCrashesDict = {} | |
parsedResponse['apps'].each do |appDict| | |
puts appDict['title'] | |
crashReasonsDict = jsonResponseForURL('https://rink.hockeyapp.net/api/2/apps/' + appDict['public_identifier'] + '/crash_reasons?per_page=100') | |
if crashReasonsDict != nil | |
openCrashes = 0 | |
crashReasonsDict['crash_reasons'].each do |crashReason| | |
if crashReason['status'] < 1 #0=new. 1=resolved, 2=ignored. | |
openCrashes += 1 | |
end | |
end | |
if openCrashes > 0 | |
appName = appDict['title'] | |
platform = appDict['platform'] | |
openCrashesDict[appName + "_" + platform] = openCrashes.to_s() | |
end | |
end | |
end | |
writeStatusBoardJSON(openCrashesDict) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment