Skip to content

Instantly share code, notes, and snippets.

@thiagoa
Created October 5, 2016 13:03
Show Gist options
  • Save thiagoa/15abeccd29b457a673858d428fb4a7c2 to your computer and use it in GitHub Desktop.
Save thiagoa/15abeccd29b457a673858d428fb4a7c2 to your computer and use it in GitHub Desktop.
Twitter Timeline Hub first context refactored
class TwitterTimelineHub
Result = Struct.new(:status, :tweets)
def initialize(twitter_client)
@twitter_client = twitter_client
end
def call(user, count: 20)
tweets = fetch_user_timeline(user, count: count)
Result.new(:ok, tweets)
end
private
def fetch_user_timeline(*args)
@twitter_client.user_timeline(*args).map do |tweet|
filter_tweet(tweet)
end
end
def filter_tweet(tweet)
{ created_at: tweet.created_at,
screen_name: tweet.user.screen_name,
text: tweet.text,
mentions: extract_mentions(tweet) }
end
def extract_mentions(tweet)
tweet.user_mentions.map(&:screen_name)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment