Created
January 25, 2013 15:54
-
-
Save ntalbott/4635473 to your computer and use it in GitHub Desktop.
A handy little script to create a text-based transcript from a Hipchat room.
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/env ruby | |
require "httparty" | |
def usage! | |
puts "Usage: hipchat-transcript <token> <room id> [date]" | |
exit! | |
end | |
TOKEN = (ARGV[0] || usage!) | |
ROOM_ID = (ARGV[1] || usage!) | |
DATE = (ARGV[2] || "recent") | |
class Message | |
attr_reader :time, :name, :body | |
def initialize(hash) | |
@time = Time.parse(hash["date"]) | |
@name = hash["from"]["name"] | |
@body = hash["message"] | |
if hash["file"] | |
file = "[#{hash["file"]["name"]}]" | |
if @body == "" | |
@body = file | |
else | |
@body += " #{file}" | |
end | |
end | |
end | |
end | |
class Room | |
include HTTParty | |
base_uri "https://api.hipchat.com/v1/rooms" | |
default_params auth_token: TOKEN | |
format :json | |
def initialize(room) | |
@room = room | |
end | |
def history(date) | |
result = self.class.get("/history", query: {room_id: @room, date: date, timezone: "UTC"}) | |
result["messages"].collect do |m| | |
Message.new(m) | |
end | |
end | |
end | |
Room.new(ROOM_ID).history(DATE).each do |message| | |
puts "(#{message.time.strftime("%Y-%m-%d %H:%M:%S")}) #{message.name}: #{message.body}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment