Skip to content

Instantly share code, notes, and snippets.

@phensalves
Created May 28, 2017 07:57
Show Gist options
  • Save phensalves/9826c1dd4def9e65ad67ec3f94dd8ced to your computer and use it in GitHub Desktop.
Save phensalves/9826c1dd4def9e65ad67ec3f94dd8ced to your computer and use it in GitHub Desktop.
Helper
module TweetsHelper
def build_tweets_hash tweets
@tweets_array = []
tweets.each do |tweet|
tweet_hash = {
user: tweet['user']['screen_name'],
user_profile: ENV['TWITTER_URL'] + tweet['user']['id'].to_s,
followers_count: tweet['user']['followers_count'],
retweets: tweet['retweet_count'],
likes: tweet['favorite_count'],
content: tweet['text'],
tweet_datetime: tweet['created_at']
}
@tweets_array << tweet_hash
end
end
def sort_most_relevants tweets_array
@tweets_sorted = tweets_array.sort_by{|tweet| [tweet[:followers_count], tweet[:retweets], tweet[:likes]]}.reverse
end
def group_tweets_by_user tweets
@tweets_grouped_by_user = tweets.group_by {|tweet| tweet[:user] }
end
def beautify_json_response json
JSON.pretty_generate(json)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment