Skip to content

Instantly share code, notes, and snippets.

@ntalbott
Created January 25, 2013 15:54
Show Gist options
  • Save ntalbott/4635473 to your computer and use it in GitHub Desktop.
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.
#!/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