Class: Tw::Client::Stream
- Inherits:
-
Object
- Object
- Tw::Client::Stream
- Defined in:
- lib/tw/client/stream.rb
Instance Method Summary collapse
- #filter(*track_words, &block) ⇒ Object
-
#initialize(user = nil) ⇒ Stream
constructor
A new instance of Stream.
- #user_stream(&block) ⇒ Object
Constructor Details
#initialize(user = nil) ⇒ Stream
Returns a new instance of Stream.
4 5 6 7 8 9 10 11 12 |
# File 'lib/tw/client/stream.rb', line 4 def initialize(user=nil) user = Tw::Auth.get_or_regist_user user @client = Twitter::Streaming::Client.new do |config| config.consumer_key = Conf['consumer_key'] config.consumer_secret = Conf['consumer_secret'] config.access_token = user['access_token'] config.access_token_secret = user['access_secret'] end end |
Instance Method Details
#filter(*track_words, &block) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/tw/client/stream.rb', line 23 def filter(*track_words, &block) raise ArgumentError, 'block not given' unless block_given? @client.filter :track => track_words.join(',') do |chunk| if tweet = get_if_tweet(chunk) yield tweet end end end |
#user_stream(&block) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/tw/client/stream.rb', line 14 def user_stream(&block) raise ArgumentError, 'block not given' unless block_given? @client.user do |chunk| if tweet = get_if_tweet(chunk) yield tweet end end end |