Class: Weeter::Twitter::TweetConsumer
- Inherits:
-
Object
- Object
- Weeter::Twitter::TweetConsumer
- Extended by:
- Forwardable
- Defined in:
- lib/weeter/twitter/tweet_consumer.rb
Constant Summary collapse
- TRACK_LIMIT =
400
- FOLLOW_LIMIT =
5000
Instance Attribute Summary collapse
-
#limiter ⇒ Object
readonly
Returns the value of attribute limiter.
-
#notifier ⇒ Object
readonly
Returns the value of attribute notifier.
Instance Method Summary collapse
- #connect(filter_params) ⇒ Object
-
#initialize(twitter_config, notifier, limiter) ⇒ TweetConsumer
constructor
A new instance of TweetConsumer.
- #reconnect(filter_params) ⇒ Object
Constructor Details
#initialize(twitter_config, notifier, limiter) ⇒ TweetConsumer
Returns a new instance of TweetConsumer.
17 18 19 20 21 |
# File 'lib/weeter/twitter/tweet_consumer.rb', line 17 def initialize(twitter_config, notifier, limiter) @config = twitter_config @notifier = notifier @limiter = limiter end |
Instance Attribute Details
#limiter ⇒ Object (readonly)
Returns the value of attribute limiter.
11 12 13 |
# File 'lib/weeter/twitter/tweet_consumer.rb', line 11 def limiter @limiter end |
#notifier ⇒ Object (readonly)
Returns the value of attribute notifier.
11 12 13 |
# File 'lib/weeter/twitter/tweet_consumer.rb', line 11 def notifier @notifier end |
Instance Method Details
#connect(filter_params) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/weeter/twitter/tweet_consumer.rb', line 23 def connect(filter_params) filter_params = limit_filter_params(filter_params) filter_params = clean_filter_params(filter_params) = @config.[:oauth] = { :path => '/1.1/statuses/filter.json', :params => filter_params, :oauth => { :consumer_key => [:consumer_key], :consumer_secret => [:consumer_secret], :token => [:access_key], :token_secret => [:access_secret] } } Weeter.logger.info("Connecting to Twitter stream...") @client = EM::Twitter::Client.connect() @client.each do |item| begin tweet_item = TweetItem.new(MultiJson.decode(item)) if tweet_item.limit_notice? notify_missed_tweets(tweet_item) elsif tweet_item.deletion? delete_tweet(tweet_item) elsif tweet_item.publishable? publish_or_rate_limit(tweet_item) else ignore_tweet(tweet_item) end rescue => ex Weeter.logger.error("Twitter stream tweet exception: #{ex.class.name}: #{ex.} #{tweet_item.to_json}") end end @client. do |msg| Weeter.logger.debug("on_unauthorized: #{msg}") end @client.on_forbidden do |msg| Weeter.logger.debug("on_forbidden: #{msg}") end @client.on_not_found do |msg| Weeter.logger.debug("on_not_found: #{msg}") end @client.on_not_acceptable do |msg| Weeter.logger.debug("on_not_acceptable: #{msg}") end @client.on_too_long do |msg| Weeter.logger.debug("on_too_long: #{msg}") end @client.on_range_unacceptable do |msg| Weeter.logger.debug("on_range_unacceptable: #{msg}") end @client.on_enhance_your_calm do |msg| # rate-limited Weeter.logger.debug("on_enhance_your_calm: #{msg}") end @client.on_error do |msg| Weeter.logger.error("Twitter stream error: #{msg}. Connect options were #{.inspect}") end @client.on_reconnect do |msg| Weeter.logger.debug("on_reconnect: #{msg}") end @client.on_max_reconnects do |timeout, retries| Weeter.logger.error("Twitter stream max-reconnects reached: timeout=#{timeout}, retries=#{retries}") end end |
#reconnect(filter_params) ⇒ Object
100 101 102 103 104 |
# File 'lib/weeter/twitter/tweet_consumer.rb', line 100 def reconnect(filter_params) @client.stop @client.unbind connect(filter_params) end |