Created
December 22, 2009 02:47
-
-
Save EmmanuelOga/261459 to your computer and use it in GitHub Desktop.
Qick & Dirty Campfire notifications on linux
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
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}:[email protected]//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