class Pry::SendTweet::ReadTweets

Public Instance Methods

options(o) click to toggle source
# File lib/pry/send_tweet/commands/read_tweets.rb, line 13
def options(o)
  o.on 't=', 'tweeter=',
       'A username whose timeline you want to read.'
  o.on 'c=', 'count=',
       "The number of tweets to read. The maximum is 200, and the default is " \
       "#{default_read_size}."
  o.on 'l=', 'likes=',
       'Read tweets you or another user have liked.',
       argument: :optional
  o.on 'r=', 'replies=', 'A username whose replies you want to read.'
  o.on 'm', 'mentions', 'Read tweets that @mention you.'
  o.on 'x=', 'translate=', 'Translate a tweet.'
  o.on 'tx=', nil, 'Translate a string of text.'
  o.on 'sl=', 'source-lang=', '[optional] The source language of the ' \
                              'text or tweet being translated'
  o.on 'w', 'with-retweets', 'Include retweets.'
end
process() click to toggle source
Calls superclass method Pry::SendTweet::BaseCommand#process
# File lib/pry/send_tweet/commands/read_tweets.rb, line 31
def process
  super
  case
  when opts.present?('translate') then translate_tweet(opts['x'], opts['sl'])
  when opts.present?('tx') then translate_text(opts['tx'], opts['sl'])
  when opts.present?('replies') then show_replies(user: opts['replies'])
  when opts.present?('likes') then show_likes(user: opts['likes'])
  when opts.present?('mentions') then show_mentions
  else show_tweets_from_timeline(user: opts['tweeter'])
  end
end

Private Instance Methods

show_likes(user:) click to toggle source
# File lib/pry/send_tweet/commands/read_tweets.rb, line 57
def show_likes(user:)
  if user
    user = search_str_for_users(user).first
    render_tweets lambda { twitter.favorites(user, count: opts['count'] || default_read_size)},
                  title: "#{'@'+user} likes"
  else
    render_tweets lambda { twitter.favorites(count: opts['count'] || default_read_size) },
                  title: "Your likes"
  end
end
show_mentions() click to toggle source
# File lib/pry/send_tweet/commands/read_tweets.rb, line 79
def show_mentions
  render_tweets lambda { twitter.mentions(timeline_options) },
                title: "@mentions"
end
show_replies(user:) click to toggle source
# File lib/pry/send_tweet/commands/read_tweets.rb, line 45
def show_replies(user:)
  username = search_str_for_users(user).first
  render_tweets lambda {
    twitter.user_timeline(username, timeline_options).select {|tweet|
      tweet.reply? &&
      tweet.in_reply_to_screen_name? &&
      tweet.in_reply_to_screen_name.downcase != username.downcase
    }
  },
  title: "#{'@'+user} replies"
end
show_tweets_from_timeline(user:) click to toggle source
# File lib/pry/send_tweet/commands/read_tweets.rb, line 68
def show_tweets_from_timeline(user:)
  if user
    user = search_str_for_users(user).first
    render_tweets lambda { twitter.user_timeline(user, timeline_options) },
                  title: '@'+user
  else
    render_tweets lambda { twitter.home_timeline(timeline_options) },
                  title: "Twitter"
  end
end
timeline_options() click to toggle source
# File lib/pry/send_tweet/commands/read_tweets.rb, line 84
def timeline_options
  {
    tweet_mode: 'extended',
    include_rts: opts.present?('with-retweets'),
    count: opts.present?('count') ? opts['count'] : default_read_size
  }
end