Skip to content

Instantly share code, notes, and snippets.

@EmmanuelOga
Created December 22, 2009 02:47
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 EmmanuelOga/261459 to your computer and use it in GitHub Desktop.
Save EmmanuelOga/261459 to your computer and use it in GitHub Desktop.
Qick & Dirty Campfire notifications on linux
require "rubygems"
require "uri"
require "yajl/http_stream"
require 'shellwords'
require 'open-uri'
require 'term/ansicolor'
$domain = "broadspire"
$token = '90454e67ebe1e202034a49266cc0abf0de7e538e'
$room_id = 177718
$users = {}
def user(id)
$users[id] ||= Yajl::Parser.new.parse(`curl -s -u #{ $token }:X http://#{ $domain }.campfirenow.com/users/#{ id }.json`)["user"]["name"]
end
include Term::ANSIColor
def notify(user_id, m)
if m =~ /\S/
title = "Campfire: #{ user(user_id) }\n"
system("notify-send -t 10000 #{ title.shellescape } #{ m.shellescape }")
STDOUT.puts("#{user(user_id).red.bold}: #{ m }")
end
end
loop do
begin
url = URI.parse("http://#{$token}:x@streaming.campfirenow.com//room/#{$room_id}/live.json")
Yajl::HttpStream.get(url) do |message|
notify(message["user_id"], message["body"].to_s)
end
rescue => e
STDERR.puts e.message
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment