Skip to content

Instantly share code, notes, and snippets.

@adamburmister
Forked from casualjim/growler.rb
Created April 15, 2011 13:58
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 adamburmister/921742 to your computer and use it in GitHub Desktop.
Save adamburmister/921742 to your computer and use it in GitHub Desktop.
# TODO: include gems in package
require 'rubygems'
require 'growl'
require 'net/http'
require 'net/https'
require 'yajl/json_gem'
# TODO: Read from ~/.backchatio_notifier file
API_KEY="YOUR_API_KEY_HERE"
STREAM_SLUG="controlbox"
ICON_PATH="$1/Contents/Resources/icon.png"
def start_listening
Thread.new do
begin
http_client = Net::HTTP.new("api.backchat.io", 443)
http_client.use_ssl = true
http_client.verify_mode = OpenSSL::SSL::VERIFY_NONE
http_client.start do |http|
req = Net::HTTP::Get.new(
"/1/stream/#{STREAM_SLUG}",
'content-type' => "application/json", "accept" => "application/json", "authorization" => "Backchat #{API_KEY}")
http.request(req) do |res|
res.read_body do |chunk|
puts chunk
unless chunk.chomp.strip.empty?
msg = JSON.parse(chunk)["messages"].first["content"]
Growl.notify msg, :title => "BackChat.io", :icon => ICON_PATH
end
end
end
end
rescue Exception => ex
puts "[#{Time.now} | #{ex.class}] #{ex.message}\n#{ex.backtrace.join("\n")}"
raise ex
end
end
end
start_listening
sleep
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment