Class: Twroute::Tweeter

Inherits:
Object
  • Object
show all
Includes:
Observable
Defined in:
lib/twroute/tweeter.rb

Instance Method Summary collapse

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_stringObject



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

#startObject



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_uriObject



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