Class: Twroute::Tweeter
- Inherits:
-
Object
- Object
- Twroute::Tweeter
- Includes:
- Observable
- Defined in:
- lib/twroute/tweeter.rb
Instance Method Summary collapse
-
#initialize(user, password, twitter_stream, post_arg_hash = {}) ⇒ Tweeter
constructor
A new instance of Tweeter.
- #query_string ⇒ Object
- #start ⇒ Object
- #twitter_stream_uri ⇒ Object
Constructor Details
#initialize(user, password, twitter_stream, post_arg_hash = {}) ⇒ Tweeter
Returns a new instance of Tweeter.
10 11 12 13 14 15 |
# File 'lib/twroute/tweeter.rb', line 10 def initialize(user, password, twitter_stream, post_arg_hash = {}) @user = user @password = password @twitter_stream = twitter_stream @post_arg_hash = post_arg_hash end |
Instance Method Details
#query_string ⇒ Object
21 22 23 24 25 |
# File 'lib/twroute/tweeter.rb', line 21 def query_string @post_arg_hash.keys.collect do |key| "#{key}=#{URI.escape(@post_arg_hash[key])}" end.sort_by { |x| x }.join('&') end |
#start ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/twroute/tweeter.rb', line 27 def start puts twitter_stream_uri.to_s Yajl::HttpStream.get(twitter_stream_uri, :symbolize_keys => true) do |hash| changed notify_observers( hash ) end end |
#twitter_stream_uri ⇒ Object
17 18 19 |
# File 'lib/twroute/tweeter.rb', line 17 def twitter_stream_uri URI.parse("http://#{@user}:#{@password}@stream.twitter.com/#{@twitter_stream}.json?#{self.query_string}") end |