Created
March 1, 2012 23:30
-
-
Save ninetwentyfour/1954008 to your computer and use it in GitHub Desktop.
Hipchat/Play/Hubot "who's online" awesomeness
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
#hipchat/play/hubot who's online awesomeness | |
require 'sinatra' | |
require 'hipchat-api' | |
# Public: Return a string of users in hipchat | |
# | |
# Examples | |
# | |
# /online | |
# # => 'ninetwentyfour,kkasch,lkkadiri,p5150j' | |
# | |
# Returns the user list string | |
get '/online' do | |
#connect to the chat room you want to monitor for people | |
hipchat_api = HipChat::API.new('HIPCHAT_API_KEY') | |
room = hipchat_api.rooms_show('HIPCHAT_ROOM_ID') | |
#hash of the names in hipchat and their corresponding office_string in play | |
names = Hash.new | |
names["Travis Berry"] = "ninetwentyfour" | |
names["Keith Kacsh"] = "kkasch" | |
names["Leela Krishna"] = "lkkadiri" | |
names["Patrick Ortell"] = "p5150j" | |
names["Jason K"] = "hooptiej" | |
#loop over each current user in the room and add their office_string to a string | |
str="" | |
room["room"]["participants"].each do |username| | |
if names.has_key? username["name"] | |
str<<names[username["name"]]+"," | |
end | |
end | |
str = str[0...-1] #strip the last comma | |
#return the string | |
"#{str}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment