Skip to content

Instantly share code, notes, and snippets.

@jonasrosland
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonasrosland/55952829d9fdc855b766 to your computer and use it in GitHub Desktop.
Save jonasrosland/55952829d9fdc855b766 to your computer and use it in GitHub Desktop.
StackOverflow Dashing widget

StackOverflow Dashing widget

Enabling you to track questions on StackOverflow with specific tags and the number of answers for each question.

Sample HTML to put in your .erb file:

    <li data-row="1" data-col="2" data-sizex="4" data-sizey="2" onclick="location.href='http://stackoverflow.com/questions/tagged/emc';">
      <div data-id="so_questions" data-view="List" data-unordered="true" data-title="StackOverflow Questions" style="background-color: #e67e22" data-moreinfo="# of answers"></div>
      <i class="icon-stackexchange icon-background"></i>
    </li>
#!/usr/bin/env ruby
require 'net/http'
require 'openssl'
require 'json'
# Created by Jonas Rosland, https://github.com/virtualswede, https://twitter.com/virtualswede
# Template used from https://github.com/foobugs/foobugs-dashboard/blob/master/jobs/github_user_repos.rb
# This job tracks questions with a specific tag on StackOverflow and
# the answer count on them by using the public StackOverflow API
#
# This job should use the `List` widget
# Config
# ------
so_host = ENV['STACKOVERFLOW_HOST'] || 'api.stackexchange.com'
so_tag = ENV['STACKOVERFLOW_TAG'] || 'emc'
# number of questions to display in the list
max_length = 20
# order the list by the numbers
ordered = true
SCHEDULER.every '60m', :first_in => 0 do |job|
uri = URI("https://api.stackexchange.com/2.2/questions?order=desc&sort=activity&tagged=#{so_tag}&site=stackoverflow")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE # disable ssl certificate check
response = http.get(uri.request_uri)
data = JSON.parse(response.body, :symbolize_names => true)
if response.code != "200"
puts "stackoverflow api error (status-code: #{response.code})\n#{response.body}"
else
so_questions = Array.new
data[:items].each do |question|
so_questions.push({
label: question[:title],
value: question[:answer_count]
})
end
if ordered
so_questions = so_questions.sort_by { |obj| -obj[:value] }
end
send_event('so_questions', { items: so_questions.slice(0, max_length) })
end # if
end # SCHEDULER
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment