Skip to content

Instantly share code, notes, and snippets.

@bjhaid
Created January 27, 2014 16:58
Show Gist options
  • Save bjhaid/8652528 to your computer and use it in GitHub Desktop.
Save bjhaid/8652528 to your computer and use it in GitHub Desktop.
get '/twitter/:name' do
content_type :json
sorted_influencers(params[:name])
end
def sorted_influencers(name)
# get first 2 tweets
tweets = client.user_timeline(name)[0,1]
# for each tweet, get the retweeters
arr = tweets.map do |tweet|
#puts tweet.to_hash
client.retweeters_of(tweet.id).each_with_object({}) do |retweeter,hash|
hash[:name] = retweeter.name
hash[:followers_count] = retweeter.followers_count
end
end
# remove the duplicates and sort on the users with the most followers,
sorted_influencers = arr.sort_by { |hsh| hsh[:followers_count] }
sorted_influencers.reverse!
sorted_influencers[0..9].to_s
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment