Skip to content

Instantly share code, notes, and snippets.

@mattfitzgerald
Created March 3, 2014 04:17
Show Gist options
  • Save mattfitzgerald/9318293 to your computer and use it in GitHub Desktop.
Save mattfitzgerald/9318293 to your computer and use it in GitHub Desktop.
require 'sinatra'
require 'zendesk_api'
require 'logger'
require 'haml'
# launch with > rerun 'rackup'
class ZenDash < Sinatra::Base
def initialize
@states = %w(new open pending hold)
@state_styles = {new: "warning", open: "danger", pending: "info", hold: "default", total: "primary"}
@groups = %w(Graphics Support Services)
initialize_zendesk_client
super
end
def initialize_zendesk_client
@client = ZendeskAPI::Client.new do |config|
config.url = "https://impactdata.zendesk.com/api/v2" # e.g. https://mydesk.zendesk.com/api/v2
config.username = "matt@impactdata.com.au"
config.token = "<secret>"
config.retry = true
# config.logger = Logger.new(STDOUT)
end
end
get '/' do
erb :index, locals: {groups_with_counts: groups_with_counts, state_styles: @state_styles}
end
def groups_with_counts
counts = {}
@groups.each do |group|
counts[group.to_sym] = {}
unsolved_tickets = @client.search(query: "type:ticket group:#{group} status<solved")
@states.each{|state| counts[group.to_sym][state.to_sym] = unsolved_tickets.select{|t| t.attributes["status"] == state}.count }
counts[group.to_sym][:total] = unsolved_tickets.count
end
counts
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment