lib/weeter/twitter/tweet_consumer.rb in weeter-0.9.2 vs lib/weeter/twitter/tweet_consumer.rb in weeter-0.10.0
- old
+ new
@@ -3,13 +3,16 @@
module Weeter
module Twitter
class TweetConsumer
- def initialize(twitter_config, notifier)
+ attr_reader :limiter
+
+ def initialize(twitter_config, notifier, limiter)
@config = twitter_config
@notifier = notifier
+ @limiter = limiter
end
def connect(filter_params)
filter_params = clean_filter_params(filter_params)
connect_options = {:ssl => true, :params => filter_params, :method => 'POST'}.merge(@config.auth_options)
@@ -17,11 +20,13 @@
@stream.each_item do |item|
begin
tweet_item = TweetItem.new(MultiJson.decode(item))
- if tweet_item.deletion?
+ if limiter.limit?(*tweet_item.limiting_facets)
+ rate_limit_tweet(tweet_item)
+ elsif tweet_item.deletion?
@notifier.delete_tweet(tweet_item)
elsif tweet_item.publishable?
@notifier.publish_tweet(tweet_item)
else
ignore_tweet(tweet_item)
@@ -61,8 +66,15 @@
text = tweet_item['text']
user_id = tweet_item['user']['id_str']
Weeter.logger.info("Ignoring tweet #{id} from user #{user_id}: #{text}")
end
+ def rate_limit_tweet(tweet_item)
+ id = tweet_item['id_str']
+ text = tweet_item['text']
+ user_id = tweet_item['user']['id_str']
+
+ Weeter.logger.info("Rate Limiting tweet #{id} from user #{user_id}: #{text}")
+ end
end
end
end