Skip to content

Instantly share code, notes, and snippets.

@x2on
Created July 23, 2015 13:37
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save x2on/eb33c56213db3771cd01 to your computer and use it in GitHub Desktop.
Save x2on/eb33c56213db3771cd01 to your computer and use it in GitHub Desktop.
HockeyApp Dashing Widget

#HockeyApp Dashing Widget

Dashing Widget for displaying HockeyApp App Crashes.

##Usage

To use this widget, copy the hockeyapp.rb file in your /jobs folder. Copy hockeyapp.yml into your /config folder and setup the api_token and the appIds.

Add gem 'rest-client' to your Gemfile and run bundle

To include this widget in a dashboard, add the following snippet to the dashboard layout file:

<li data-row="1" data-col="1" data-sizex="2" data-sizey="1">
    <div data-id="hockeyapp_first_project" data-view="Graph" data-title="App Crashes"></div>
</li>
#!/usr/bin/env ruby
require 'rest-client'
require 'json'
require 'time'
SCHEDULER.every '20m', :first_in => 0 do |job|
begin
crashes = {}
config_file = File.dirname(File.expand_path(__FILE__)) + '/../config/hockeyapp.yml'
config = YAML::load(File.open(config_file))
unless config["appIds"].nil?
config["appIds"].each do |data_id, app_id|
hockeyappBaseUrl = "https://rink.hockeyapp.net/api/2/apps"
response = RestClient.get "#{hockeyappBaseUrl}/#{app_id}/app_versions", {"X-HockeyAppToken" => config["api_token"]}
json = JSON.parse(response.to_str)
json["app_versions"].each do |app|
# Get first version that is available (status == 2)
if app["status"] == 2
points = []
title = app["title"]
version = app["shortversion"]
versionId = app["id"]
startDate = Time.at(app["timestamp"]).strftime("%Y-%m-%d")
endDate = Time.now.strftime("%Y-%m-%d")
# Get histogram for app version
url = "#{hockeyappBaseUrl}/#{app_id}/app_versions/#{versionId}/crashes/histogram?start_date=#{startDate}&end_date=#{endDate}"
response = RestClient.get url, {"X-HockeyAppToken" => config["api_token"]}
json = JSON.parse(response.to_str)
content = {}
result = {
"title" => title,
"version" => version,
"crashes" => content
}
json["histogram"].each do |histogram|
result["crashes"][histogram[0]] = histogram[1]
end
crashes[title] = result
result["crashes"].each do |crash|
points << { x: Time.parse(crash[0]).to_i, y: crash[1] }
end
send_event(data_id, points: points)
break
end
end
end
else
puts "Error: Please setup config/hockeyapp.yml"
end
end
end
api_token: "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
appIds:
hockeyapp_first_project: abcdefghijklmnopqrstuvwxyz
hockeyapp_second_project: abcdefghijklmnopqrstuvwxyz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment