-
-
Save benlangfeld/4337021 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 "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}:[email protected]/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