Class: Pry::SendTweet::SendTweet

Inherits:
BaseCommand
  • Object
show all
Defined in:
lib/pry/send_tweet/commands/send_tweet.rb

Constant Summary collapse

MAX_TWEET_SIZE =
280

Constants included from TimeAgoInWords

TimeAgoInWords::VERSION

Instance Method Summary collapse

Methods inherited from BaseCommand

inherited

Methods included from PagingSupport

#page, #page_error, #page_ok

Methods included from UserRenderer

#render_user

Methods included from TweetRenderer

#render_tweets

Methods included from TimeAgoInWords

time_ago_in_words

Instance Method Details

#options(o) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/pry/send_tweet/commands/send_tweet.rb', line 13

def options(o)
  o.on 'f=', 'file=',
       'One or more paths to file(s) to attach to a tweet.',
        as: Array
  o.on 'r=', 'reply-to=',
       'An absolute url to a tweet you want to reply to.'
  o.on 's=', 'self-destruct=',
       'The number of seconds (represented as a number or a timestamp in the ' \
       'format of HH:MM:SS) to wait before automatically deleting the tweet ' \
       'asynchronously.'
  o.on 'd=', 'delay=',
       'The number of seconds (represented as a number or a timestamp in the ' \
       'format of HH:MM:SS) to wait before creating the tweet asynchronously.'
  o.on 'n', 'no-newline',
       "Remove newlines (\\n) from a tweet before sending it."
  o.on 'v', 'version', 'Print the version information of fry-send_tweet.rb'
end

#process(args) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/pry/send_tweet/commands/send_tweet.rb', line 31

def process(args)
  super
  return __print_version_information if opts.version?
  tweet_creator = create_tweet_creator(compose_tweet_with_editor)
  if opts.present?('delay')
    time_obj, sleep_seconds = parse_duration_str(opts['delay'])
    Thread.new {
      sleep sleep_seconds
      tweet_creator.call
    }
    publish_time = (time_obj ? time_obj : Time.now + sleep_seconds)
                    .getlocal
                    .strftime(time_format)
    page_ok bold("Tweet will be published at approximately #{publish_time}.")
  else
    tweet = tweet_creator.call
    page_ok tweet.url
  end
end