Created
August 8, 2009 21:24
-
-
Save bhauman/164512 to your computer and use it in GitHub Desktop.
This file contains 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 'rubygems' | |
require 'yajl' | |
require 'yajl/http_stream' | |
require 'uri' | |
require 'observer' | |
module Twroute | |
class Tweeter | |
include Observable | |
def initialize(user, password, twitter_stream, post_arg_hash = {}) | |
@user = user | |
@password = password | |
@twitter_stream = twitter_stream | |
@post_arg_hash = post_arg_hash | |
end | |
def twitter_stream_uri | |
URI.parse("http://#{@user}:#{@password}@stream.twitter.com/#{@twitter_stream}.json?#{self.query_string}") | |
end | |
def query_string | |
@post_arg_hash.keys.collect do |key| | |
"#{key}=#{URI.escape(@post_arg_hash[key])}" | |
end.sort_by { |x| x }.join('&') | |
end | |
def start | |
Yajl::HttpStream.get(twitter_stream_uri, :symbolize_keys => true) do |hash| | |
changed | |
notify_observers( hash ) | |
end | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment