Class: ExStream
- Inherits:
-
Twitter::Streaming::Client
- Object
- Twitter::Streaming::Client
- ExStream
- Defined in:
- lib/ex_stream.rb
Overview
extended twitter
Constant Summary collapse
- MAX_ATTEMPTS =
1- WAIT =
false- CACHE_EXPIRES_IN =
300
Instance Attribute Summary collapse
-
#cache ⇒ Object
Returns the value of attribute cache.
-
#cache_expires_in ⇒ Object
Returns the value of attribute cache_expires_in.
Instance Method Summary collapse
-
#initialize(config = {}) ⇒ ExStream
constructor
A new instance of ExStream.
- #print_filter_stream(topics) ⇒ Object
- #print_sample_stream ⇒ Object
-
#print_user_stream ⇒ Object
An object may be one of the following: Twitter::DirectMessage Twitter::Streaming::DeletedTweet Twitter::Streaming::Event Twitter::Streaming::FriendList Twitter::Streaming::StallWarning Twitter::Tweet.
Constructor Details
#initialize(config = {}) ⇒ ExStream
Returns a new instance of ExStream.
15 16 17 18 19 20 |
# File 'lib/ex_stream.rb', line 15 def initialize(config={}) self.cache_expires_in = (config[:cache_expires_in] || CACHE_EXPIRES_IN) self.cache = ActiveSupport::Cache::FileStore.new(File.join(Dir::pwd, 'ex_twitter_cache'), {expires_in: self.cache_expires_in, race_condition_ttl: self.cache_expires_in}) super end |
Instance Attribute Details
#cache ⇒ Object
Returns the value of attribute cache.
9 10 11 |
# File 'lib/ex_stream.rb', line 9 def cache @cache end |
#cache_expires_in ⇒ Object
Returns the value of attribute cache_expires_in.
9 10 11 |
# File 'lib/ex_stream.rb', line 9 def cache_expires_in @cache_expires_in end |
Instance Method Details
#print_filter_stream(topics) ⇒ Object
22 23 24 25 26 |
# File 'lib/ex_stream.rb', line 22 def print_filter_stream(topics) filter(track: topics.join(",")) do |object| puts object.text if object.is_a?(Twitter::Tweet) end end |
#print_sample_stream ⇒ Object
28 29 30 31 32 |
# File 'lib/ex_stream.rb', line 28 def print_sample_stream sample do |object| puts object.text if object.is_a?(Twitter::Tweet) end end |
#print_user_stream ⇒ Object
An object may be one of the following:
Twitter::DirectMessage
Twitter::Streaming::DeletedTweet
Twitter::Streaming::Event
Twitter::Streaming::FriendList
Twitter::Streaming::StallWarning
Twitter::Tweet
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ex_stream.rb', line 41 def print_user_stream user do |object| case object when Twitter::Tweet puts "It's a tweet!" when Twitter::DirectMessage puts "It's a direct message!" when Twitter::Streaming::StallWarning warn "Falling behind!" end end end |