Created
May 1, 2010 01:29
-
-
Save philk/385949 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
| # MIT Licensed | |
| # Author: Boxcar, http://boxcar.io | |
| # | |
| # requires: em-http-request, em-websocket gems. | |
| # | |
| # Be sure to modify the SETTINGS hash and replace it with your Boxcar email and password. | |
| require 'rubygems' | |
| require 'eventmachine' | |
| require 'em-http' | |
| require 'em-websocket' | |
| # http://github.com/snaka/ruby_gntp | |
| require 'ruby_gntp' # gem install ruby_gntp | |
| # http://flori.github.com/json/ | |
| require 'json' # gem install json | |
| gntp_host = "xxx.xxx.xxx.xxx" | |
| gntp_passwd = "12345" | |
| def send_growl(res) | |
| json = JSON.parse(res) | |
| GNTP.notify({ | |
| :host => gntp_host, | |
| :passwd => gntp_passwd, | |
| :sticky => TRUE, | |
| :app_name => "Boxcar", | |
| :title => "#{json["from_screen_name"]}", | |
| :text => "#{json["alert"]}" | |
| }) | |
| end | |
| SETTINGS = { | |
| :email => '[email protected]', | |
| :password => 'hunter13' | |
| } | |
| EventMachine.run { | |
| http = EventMachine::HttpRequest.new("ws://farm.boxcar.io:8080/websocket").get :timeout => 0 | |
| http.errback { | |
| puts "There was a problem maintaining the connection." | |
| } | |
| http.callback { | |
| puts "Connected! Send yourself a notification. Find example code at http://github.com/boxcar" | |
| http.send "{\"action\":\"login\",\"email\":\"#{SETTINGS[:email]}\",\"password\":\"#{SETTINGS[:password]}\"}" | |
| } | |
| http.stream { |msg| | |
| puts "Recieved: #{msg}" | |
| send_growl(msg) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment