Skip to content

Instantly share code, notes, and snippets.

@benlangfeld
Forked from julienXX/notifier.rb
Created December 19, 2012 14:29
Show Gist options
  • Save benlangfeld/4337021 to your computer and use it in GitHub Desktop.
Save benlangfeld/4337021 to your computer and use it in GitHub Desktop.
require "uri"
require "yajl/http_stream"
require "terminal-notifier"
require "celluloid"
class Stream
include Celluloid
def initialize(room, token)
@room = room
@token = token
start!
end
def start
regexp = Regexp.new('julien', true)
Yajl::HttpStream.get(self.url) do |message|
puts message.inspect
if message['body'] && message['body'].match(regexp)
TerminalNotifier.notify(message['body'], :title => 'Campfire')
end
end
end
def url
@url = URI.parse("http://#{@token}:x@streaming.campfirenow.com/room/#{@room}/live.json")
end
end
token = TOKEN
room_ids = [1,2]
room_ids.map do |room_id|
puts "- Listening room #{room_id}"
Stream.new(room_id, token)
end.each do |stream|
Celluloid.join stream
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment