cycle method added to auto cycle through tweets and exception handling is modified to capture all errors that raise from twitter

This commit is contained in:
AnithaPal 2016-07-27 17:02:40 -04:00
parent f29a15b8e4
commit 881518f1f3
10 changed files with 73 additions and 56 deletions

View file

@ -3,23 +3,19 @@ class TwitterWrapper
def initialize
@client = Twitter::REST::Client.new do |config|
config.consumer_key = ENV["OSEM_TWITTER_CONSUMER_KEY"]
config.consumer_secret = ENV["OSEM_TWITTER_CONSUMER_SECRET"]
config.access_token = ENV["OSEM_TWITTER_ACCESS_TOKEN"]
config.access_token_secret = ENV["OSEM_TWITTER_ACCESS_TOKEN_SECRET"]
config.consumer_key = ENV['OSEM_TWITTER_CONSUMER_KEY']
config.consumer_secret = ENV['OSEM_TWITTER_CONSUMER_SECRET']
config.access_token = ENV['OSEM_TWITTER_ACCESS_TOKEN']
config.access_token_secret = ENV['OSEM_TWITTER_ACCESS_TOKEN_SECRET']
end
end
##
#Fetches tweets from twitter api based on search_term and no_of_tweets
# Fetches tweets from twitter api based on search_term and no_of_tweets
#
def search_tweets(no_of_tweets, search_term)
begin
@client.search(search_term, result_type: "recent").take(no_of_tweets).collect
rescue Twitter::Error::TooManyRequests => error
sleep error.rate_limit.reset_in + 1
retry
end
@client.search(search_term, result_type: 'recent').take(no_of_tweets).collect
rescue
nil
end
end