Permalink
Browse files

forgot to add the bin dir to the repo

  • Loading branch information...
1 parent 4822254 commit 164eb260dcaf4e26c8d285c402b1282aeadb0c4c Emmanuel Oga committed May 31, 2010
Showing with 57 additions and 1 deletion.
  1. +0 −1 .gitignore
  2. +56 −0 bin/campf-notify
  3. +1 −0 firering.gemspec
View
@@ -1,6 +1,5 @@
doc
.yardoc
-bin
*.swp
coverage
rdoc
View
@@ -0,0 +1,56 @@
+#!/usr/bin/env ruby
+
+require 'firering'
+require 'shellwords'
+
+Firering.subdomain = ENV["CAMPFIRE_SUBDOMAIN"]
+Firering.token = ENV["CAMPFIRE_TOKEN"]
+
+room_name = ARGV[0].to_s
+icon_path = ARGV[1].to_s
+
+if Firering.subdomain =~ /^\s*$/ || Firering.token =~ /^\s*$/ || room_name =~ /^\s*$/ || !File.exists?(icon_path)
+ puts "USAGE: campf-notify room-name notify-send-icon-path"
+ puts
+ puts "Icon path #{icon_path} is incorrect\n" unless File.exists?(icon_path)
+ puts "Room name #{room_name} is missing" unless room_name !~ /^\s*$/
+
+ puts "The following environment variables are needed: "
+ puts
+ puts "CAMPFIRE_SUBDOMAIN: #{Firering.subdomain}"
+ puts "CAMPFIRE_TOKEN: #{Firering.token}"
+ puts
+ exit
+else
+ puts "connecting to #{Firering.subdomain}.#{Firering::HTTP.host}"
+end
+
+EM.run do
+ Firering.rooms do |rooms|
+ rooms.each do |room|
+ if room.name == room_name
+
+ puts "Joining #{room.name}"
+
+ Firering.room_join(room.id) do
+ Firering.stream(room.id) do |message|
+
+ if message.from_user?
+ Firering.user(message.user_id) do |user|
+ m = "( #{user.name} ) #{message.body}"
+ system("notify-send -i #{icon_path.shellescape} -t 10000 Campfire #{m.shellescape}")
+ end
+ else
+ m = message.body.to_s
+ system("notify-send -i #{icon_path.shellescape} -t 10000 Campfire #{m.shellescape}") if m !~ /^\s*$/
+ end
+
+ end
+ end
+
+ end
+ end
+ end
+
+ trap("INT") { EM.stop }
+end
View
@@ -32,6 +32,7 @@ Gem::Specification.new do |s|
LICENSE
README.rdoc
Rakefile
+ bin/campf-notify
examples/authenticate.rb
examples/events.rb
examples/recent_messages.rb

0 comments on commit 164eb26

Please sign in to comment.