Class: T::CLI

Inherits:
Thor
  • Object
show all
Includes:
ActionView::Helpers::DateHelper, ActionView::Helpers::NumberHelper, ActionView::Helpers::TextHelper, Authorizable, Collectable, Printable, Requestable, Twitter::Extractor
Defined in:
lib/t/cli.rb

Constant Summary collapse

DEFAULT_NUM_RESULTS =
20
MAX_SCREEN_NAME_SIZE =
20
MAX_USERS_PER_REQUEST =
100

Constants included from Requestable

Requestable::DEFAULT_HOST, Requestable::DEFAULT_PROTOCOL

Instance Method Summary collapse

Methods included from Requestable

#base_url, #client, #host, included, #protocol

Methods included from Printable

#build_long_list, #build_long_status, #build_long_user, included, #print_csv_list, #print_csv_status, #print_csv_user, #print_in_columns, #print_lists, #print_status, #print_statuses, #print_users

Methods included from Collectable

#collect_with_cursor, #collect_with_max_id

Methods included from Authorizable

#consumer, #generate_authorize_url, #pin_auth_parameters

Constructor Details

#initializeCLI

Returns a new instance of CLI.



57
58
59
60
# File 'lib/t/cli.rb', line 57

def initialize(*)
  super
  @rcfile = RCFile.instance
end

Instance Method Details

#accountsObject



63
64
65
66
67
68
69
70
71
# File 'lib/t/cli.rb', line 63

def accounts
  @rcfile.path = options['profile'] if options['profile']
  @rcfile.profiles.each do |profile|
    say profile[0]
    profile[1].keys.each do |key|
      say "  #{key}#{@rcfile.active_profile[0] == profile[0] && @rcfile.active_profile[1] == key ? " (active)" : nil}"
    end
  end
end

#authorizeObject



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/t/cli.rb', line 78

def authorize
  request_token = consumer.get_request_token
  url = generate_authorize_url(request_token)
  if options['prompt']
    say "In a moment, you will be directed to the Twitter app authorization page."
    say "Perform the following steps to complete the authorization process:"
    say "  1. Sign in to Twitter"
    say "  2. Press \"Authorize app\""
    say "  3. Copy or memorize the supplied PIN"
    say "  4. Return to the terminal to enter the PIN"
    say
    ask "Press [Enter] to open the Twitter app authorization page."
    say
  end
  Launchy.open(url, :dry_run => options['display-url'])
  pin = ask "Paste in the supplied PIN:"
  access_token = request_token.get_access_token(:oauth_verifier => pin.chomp)
  oauth_response = access_token.get('/1/account/verify_credentials.json')
  screen_name = oauth_response.body.match(/"screen_name"\s*:\s*"(.*?)"/).captures.first
  @rcfile.path = options['profile'] if options['profile']
  @rcfile[screen_name] = {
    options['consumer-key'] => {
      'username' => screen_name,
      'consumer_key' => options['consumer-key'],
      'consumer_secret' => options['consumer-secret'],
      'token' => access_token.token,
      'secret' => access_token.secret,
    }
  }
  @rcfile.active_profile = {'username' => screen_name, 'consumer_key' => options['consumer-key']}
  say "Authorization successful."
end

#block(user, *users) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/t/cli.rb', line 113

def block(user, *users)
  users.unshift(user)
  if options['id']
    users.map!(&:to_i)
  else
    users.map!(&:strip_ats)
  end
  users = users.threaded_map do |user|
    retryable(:tries => 3, :on => Twitter::Error::ServerError, :sleep => 0) do
      client.block(user, :include_entities => false)
    end
  end
  number = users.length
  say "@#{@rcfile.active_profile[0]} blocked #{number} #{number == 1 ? 'user' : 'users'}."
  say
  say "Run `#{File.basename($0)} delete block #{users.map{|user| "@#{user.screen_name}"}.join(' ')}` to unblock."
end

#direct_messagesObject



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/t/cli.rb', line 136

def direct_messages
  count = options['number'] || DEFAULT_NUM_RESULTS
  direct_messages = client.direct_messages(:count => count, :include_entities => false)
  direct_messages.reverse! if options['reverse']
  if options['csv']
    say ["ID", "Posted at", "Screen name", "Text"].to_csv unless direct_messages.empty?
    direct_messages.each do |direct_message|
      say [direct_message.id, direct_message.created_at.utc.strftime("%Y-%m-%d %H:%M:%S %z"), direct_message.sender.screen_name, direct_message.text].to_csv
    end
  elsif options['long']
    array = direct_messages.map do |direct_message|
      created_at = direct_message.created_at > 6.months.ago ? direct_message.created_at.strftime("%b %e %H:%M") : direct_message.created_at.strftime("%b %e  %Y")
      [direct_message.id, created_at, "@#{direct_message.sender.screen_name}", HTMLEntities.new.decode(direct_message.text).gsub(/\n+/, ' ')]
    end
    if STDOUT.tty?
      headings = ["ID", "Posted at", "Screen name", "Text"]
      array.unshift(headings) unless direct_messages.empty?
      print_table(array, :truncate => true)
    else
      print_table(array)
    end
  else
    direct_messages.each do |direct_message|
      say "#{direct_message.sender.screen_name.rjust(MAX_SCREEN_NAME_SIZE)}: #{direct_message.text.gsub(/\n+/, ' ')} (#{time_ago_in_words(direct_message.created_at)} ago)"
    end
  end
end

#direct_messages_sentObject



170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/t/cli.rb', line 170

def direct_messages_sent
  count = options['number'] || DEFAULT_NUM_RESULTS
  direct_messages = client.direct_messages_sent(:count => count, :include_entities => false)
  direct_messages.reverse! if options['reverse']
  if options['csv']
    say ["ID", "Posted at", "Screen name", "Text"].to_csv unless direct_messages.empty?
    direct_messages.each do |direct_message|
      say [direct_message.id, direct_message.created_at.utc.strftime("%Y-%m-%d %H:%M:%S %z"), direct_message.recipient.screen_name, direct_message.text].to_csv
    end
  elsif options['long']
    array = direct_messages.map do |direct_message|
      created_at = direct_message.created_at > 6.months.ago ? direct_message.created_at.strftime("%b %e %H:%M") : direct_message.created_at.strftime("%b %e  %Y")
      [direct_message.id, created_at, "@#{direct_message.recipient.screen_name}", HTMLEntities.new.decode(direct_message.text).gsub(/\n+/, ' ')]
    end
    if STDOUT.tty?
      headings = ["ID", "Posted at", "Screen name", "Text"]
      array.unshift(headings) unless direct_messages.empty?
      print_table(array, :truncate => true)
    else
      print_table(array)
    end
  else
    direct_messages.each do |direct_message|
      say "#{direct_message.recipient.screen_name.rjust(MAX_SCREEN_NAME_SIZE)}: #{direct_message.text.gsub(/\n+/, ' ')} (#{time_ago_in_words(direct_message.created_at)} ago)"
    end
  end
end

#disciples(user = nil) ⇒ Object



211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# File 'lib/t/cli.rb', line 211

def disciples(user=nil)
  if user
    user = if options['id']
      user.to_i
    else
      user.strip_ats
    end
  end
  follower_ids = collect_with_cursor do |cursor|
    client.follower_ids(user, :cursor => cursor)
  end
  following_ids = collect_with_cursor do |cursor|
    client.friend_ids(user, :cursor => cursor)
  end
  disciple_ids = (follower_ids - following_ids)
  users = disciple_ids.in_groups_of(MAX_USERS_PER_REQUEST, false).threaded_map do |disciple_id_group|
    retryable(:tries => 3, :on => Twitter::Error::ServerError, :sleep => 0) do
      client.users(disciple_id_group, :include_entities => false)
    end
  end.flatten
  print_users(users)
end

#dm(user, message) ⇒ Object



236
237
238
239
240
241
242
243
244
# File 'lib/t/cli.rb', line 236

def dm(user, message)
  user = if options['id']
    user.to_i
  else
    user.strip_ats
  end
  direct_message = client.direct_message_create(user, message, :include_entities => false)
  say "Direct Message sent from @#{@rcfile.active_profile[0]} to @#{direct_message.recipient.screen_name} (#{time_ago_in_words(direct_message.created_at)} ago)."
end

#does_contain(list, user = nil) ⇒ Object



249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# File 'lib/t/cli.rb', line 249

def does_contain(list, user=nil)
  owner, list = list.split('/')
  if list.nil?
    list = owner
    owner = @rcfile.active_profile[0]
  else
    owner = if options['id']
      client.user(owner.to_i, :include_entities => false).screen_name
    else
      owner.strip_ats
    end
  end
  if user.nil?
    user = @rcfile.active_profile[0]
  else
    user = if options['id']
      user = client.user(user.to_i, :include_entities => false).screen_name
    else
      user.strip_ats
    end
  end
  if client.list_member?(owner, list, user)
    say "Yes, @#{owner}/#{list} contains @#{user}."
  else
    say "No, @#{owner}/#{list} does not contain @#{user}."
    exit 1
  end
end

#does_follow(user1, user2 = nil) ⇒ Object



281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
# File 'lib/t/cli.rb', line 281

def does_follow(user1, user2=nil)
  user1 = if options['id']
    client.user(user1.to_i, :include_entities => false).screen_name
  else
    user1.strip_ats
  end
  if user2.nil?
    user2 = @rcfile.active_profile[0]
  else
    user2 = if options['id']
      client.user(user2.to_i, :include_entities => false).screen_name
    else
      user2.strip_ats
    end
  end
  if client.friendship?(user1, user2)
    say "Yes, @#{user1} follows @#{user2}."
  else
    say "No, @#{user1} does not follow @#{user2}."
    exit 1
  end
end

#favorite(status_id, *status_ids) ⇒ Object



306
307
308
309
310
311
312
313
314
315
316
317
318
# File 'lib/t/cli.rb', line 306

def favorite(status_id, *status_ids)
  status_ids.unshift(status_id)
  status_ids.map!(&:strip_commas)
  favorites = status_ids.threaded_map do |status_id|
    retryable(:tries => 3, :on => Twitter::Error::ServerError, :sleep => 0) do
      client.favorite(status_id.to_i, :include_entities => false)
    end
  end
  number = favorites.length
  say "@#{@rcfile.active_profile[0]} favorited #{number} #{number == 1 ? 'tweet' : 'tweets'}."
  say
  say "Run `#{File.basename($0)} delete favorite #{status_ids.join(' ')}` to unfavorite."
end

#favorites(user = nil) ⇒ Object



327
328
329
330
331
332
333
334
335
336
337
338
# File 'lib/t/cli.rb', line 327

def favorites(user=nil)
  if user
    user = if options['id']
      user.to_i
    else
      user.strip_ats
    end
  end
  count = options['number'] || DEFAULT_NUM_RESULTS
  statuses = client.favorites(user, :count => count, :include_entities => false)
  print_statuses(statuses)
end

#follow(user, *users) ⇒ Object



343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
# File 'lib/t/cli.rb', line 343

def follow(user, *users)
  users.unshift(user)
  if options['id']
    users.map!(&:to_i)
  else
    users.map!(&:strip_ats)
  end
  users = users.threaded_map do |user|
    retryable(:tries => 3, :on => Twitter::Error::ServerError, :sleep => 0) do
      client.follow(user, :include_entities => false)
    end
  end
  number = users.length
  say "@#{@rcfile.active_profile[0]} is now following #{number} more #{number == 1 ? 'user' : 'users'}."
  say
  say "Run `#{File.basename($0)} unfollow #{users.map{|user| "@#{user.screen_name}"}.join(' ')}` to stop."
end

#followers(user = nil) ⇒ Object



404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
# File 'lib/t/cli.rb', line 404

def followers(user=nil)
  if user
    user = if options['id']
      user.to_i
    else
      user.strip_ats
    end
  end
  follower_ids = collect_with_cursor do |cursor|
    client.follower_ids(user, :cursor => cursor)
  end
  users = follower_ids.in_groups_of(MAX_USERS_PER_REQUEST, false).threaded_map do |follower_id_group|
    retryable(:tries => 3, :on => Twitter::Error::ServerError, :sleep => 0) do
      client.users(follower_id_group, :include_entities => false)
    end
  end.flatten
  print_users(users)
end

#followings(user = nil) ⇒ Object



373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
# File 'lib/t/cli.rb', line 373

def followings(user=nil)
  if user
    user = if options['id']
      user.to_i
    else
      user.strip_ats
    end
  end
  following_ids = collect_with_cursor do |cursor|
    client.friend_ids(user, :cursor => cursor)
  end
  users = following_ids.in_groups_of(MAX_USERS_PER_REQUEST, false).threaded_map do |following_id_group|
    retryable(:tries => 3, :on => Twitter::Error::ServerError, :sleep => 0) do
      client.users(following_id_group, :include_entities => false)
    end
  end.flatten
  print_users(users)
end

#friends(user = nil) ⇒ Object



435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
# File 'lib/t/cli.rb', line 435

def friends(user=nil)
  if user
    user = if options['id']
      user.to_i
    else
      user.strip_ats
    end
  end
  following_ids = collect_with_cursor do |cursor|
    client.friend_ids(user, :cursor => cursor)
  end
  follower_ids = collect_with_cursor do |cursor|
    client.follower_ids(user, :cursor => cursor)
  end
  friend_ids = (following_ids & follower_ids)
  users = friend_ids.in_groups_of(MAX_USERS_PER_REQUEST, false).threaded_map do |friend_id_group|
    retryable(:tries => 3, :on => Twitter::Error::ServerError, :sleep => 0) do
      client.users(friend_id_group, :include_entities => false)
    end
  end.flatten
  print_users(users)
end

#leaders(user = nil) ⇒ Object



470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
# File 'lib/t/cli.rb', line 470

def leaders(user=nil)
  if user
    user = if options['id']
      user.to_i
    else
      user.strip_ats
    end
  end
  following_ids = collect_with_cursor do |cursor|
    client.friend_ids(user, :cursor => cursor)
  end
  follower_ids = collect_with_cursor do |cursor|
    client.follower_ids(user, :cursor => cursor)
  end
  leader_ids = (following_ids - follower_ids)
  users = leader_ids.in_groups_of(MAX_USERS_PER_REQUEST, false).threaded_map do |leader_id_group|
    retryable(:tries => 3, :on => Twitter::Error::ServerError, :sleep => 0) do
      client.users(leader_id_group, :include_entities => false)
    end
  end.flatten
  print_users(users)
end

#lists(user = nil) ⇒ Object



503
504
505
506
507
508
509
510
511
512
513
514
515
# File 'lib/t/cli.rb', line 503

def lists(user=nil)
  if user
    user = if options['id']
      user.to_i
    else
      user.strip_ats
    end
  end
  lists = collect_with_cursor do |cursor|
    client.lists(user, :cursor => cursor)
  end
  print_lists(lists)
end

#mentionsObject



522
523
524
525
526
# File 'lib/t/cli.rb', line 522

def mentions
  count = options['number'] || DEFAULT_NUM_RESULTS
  statuses = client.mentions(:count => count, :include_entities => false)
  print_statuses(statuses)
end

#open(user) ⇒ Object



533
534
535
536
537
538
539
540
541
542
543
# File 'lib/t/cli.rb', line 533

def open(user)
  if options['id']
    user = client.user(user.to_i, :include_entities => false)
    Launchy.open("https://twitter.com/#{user.screen_name}", :dry_run => options['display-url'])
  elsif options['status']
    status = client.status(user.to_i, :include_entities => false, :include_my_retweet => false)
    Launchy.open("https://twitter.com/#{status.user.screen_name}/status/#{status.id}", :dry_run => options['display-url'])
  else
    Launchy.open("https://twitter.com/#{user.strip_ats}", :dry_run => options['display-url'])
  end
end

#reply(status_id, message) ⇒ Object



548
549
550
551
552
553
554
555
556
557
558
559
560
561
# File 'lib/t/cli.rb', line 548

def reply(status_id, message)
  status_id = status_id.strip_commas
  status = client.status(status_id.to_i, :include_entities => false, :include_my_retweet => false)
  users = Array(status.user.screen_name)
  users += extract_mentioned_screen_names(status.text) if options['all']
  users.uniq!
  users.map!(&:prepend_at)
  opts = {:in_reply_to_status_id => status.id, :include_entities => false, :trim_user => true}
  opts.merge!(:lat => location.lat, :long => location.lng) if options['location']
  reply = client.update("#{users.join(' ')} #{message}", opts)
  say "Reply created by @#{@rcfile.active_profile[0]} to #{users.join(' ')} (#{time_ago_in_words(reply.created_at)} ago)."
  say
  say "Run `#{File.basename($0)} delete status #{reply.id}` to delete."
end

#report_spam(user, *users) ⇒ Object



565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
# File 'lib/t/cli.rb', line 565

def report_spam(user, *users)
  users.unshift(user)
  if options['id']
    users.map!(&:to_i)
  else
    users.map!(&:strip_ats)
  end
  users = users.threaded_map do |user|
    retryable(:tries => 3, :on => Twitter::Error::ServerError, :sleep => 0) do
      client.report_spam(user, :include_entities => false)
    end
  end
  number = users.length
  say "@#{@rcfile.active_profile[0]} reported #{number} #{number == 1 ? 'user' : 'users'}."
end

#retweet(status_id, *status_ids) ⇒ Object



583
584
585
586
587
588
589
590
591
592
593
594
595
# File 'lib/t/cli.rb', line 583

def retweet(status_id, *status_ids)
  status_ids.unshift(status_id)
  status_ids.map!(&:strip_commas)
  retweets = status_ids.threaded_map do |status_id|
    retryable(:tries => 3, :on => Twitter::Error::ServerError, :sleep => 0) do
      client.retweet(status_id.to_i, :include_entities => false, :trim_user => true)
    end
  end
  number = retweets.length
  say "@#{@rcfile.active_profile[0]} retweeted #{number} #{number == 1 ? 'tweet' : 'tweets'}."
  say
  say "Run `#{File.basename($0)} delete status #{status_ids.join(' ')}` to undo."
end

#retweets(user = nil) ⇒ Object



604
605
606
607
608
609
610
611
612
613
614
615
# File 'lib/t/cli.rb', line 604

def retweets(user=nil)
  if user
    user = if options['id']
      user.to_i
    else
      user.strip_ats
    end
  end
  count = options['number'] || DEFAULT_NUM_RESULTS
  statuses = client.retweeted_by(user, :count => count, :include_entities => false)
  print_statuses(statuses)
end

#rulerObject



619
620
621
# File 'lib/t/cli.rb', line 619

def ruler
  say "----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|"
end

#status(status_id) ⇒ Object



625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
# File 'lib/t/cli.rb', line 625

def status(status_id)
  status_id = status_id.strip_commas
  status = client.status(status_id.to_i, :include_entities => false, :include_my_retweet => false)
  if status.geo
    geoloc = Geokit::Geocoders::MultiGeocoder.reverse_geocode(status.geo.coordinates)
    location = if geoloc.city && geoloc.state && geoloc.country
      [geoloc.city, geoloc.state, geoloc.country].join(", ")
    elsif geoloc.state && geoloc.country
      [geoloc.state, geoloc.country].join(", ")
    else
      geoloc.country
    end
  else
    location = nil
  end
  if options['csv']
    say ["ID", "Text", "Screen name", "Posted at", "Location", "Retweets", "Source", "URL"].to_csv
    say [status.id, HTMLEntities.new.decode(status.text), status.user.screen_name, status.created_at.utc.strftime("%Y-%m-%d %H:%M:%S %z"), location, status.retweet_count, strip_tags(status.source), "https://twitter.com/#{status.user.screen_name}/status/#{status.id}"].to_csv
  else
    array = []
    array << ["ID", status.id.to_s]
    array << ["Text", HTMLEntities.new.decode(status.text).gsub(/\n+/, ' ')]
    array << ["Screen name", "@#{status.user.screen_name}"]
    posted_at = status.created_at > 6.months.ago ? status.created_at.strftime("%b %e %H:%M") : status.created_at.strftime("%b %e  %Y")
    array << ["Posted at", posted_at]
    array << ["Location", location] unless location.nil?
    array << ["Retweets", number_with_delimiter(status.retweet_count)]
    array << ["Source", strip_tags(status.source)]
    array << ["URL", "https://twitter.com/#{status.user.screen_name}/status/#{status.id}"]
    print_table(array)
  end
end

#suggest(user = nil) ⇒ Object



671
672
673
674
675
676
677
678
679
680
681
682
# File 'lib/t/cli.rb', line 671

def suggest(user=nil)
  if user
    user = if options['id']
      user.to_i
    else
      user.strip_ats
    end
  end
  limit = options['number'] || DEFAULT_NUM_RESULTS
  users = client.recommendations(user, :limit => limit, :include_entities => false)
  print_users(users)
end

#timeline(user = nil) ⇒ Object



690
691
692
693
694
695
696
697
698
699
700
701
702
703
# File 'lib/t/cli.rb', line 690

def timeline(user=nil)
  count = options['number'] || DEFAULT_NUM_RESULTS
  if user
    user = if options['id']
      user.to_i
    else
      user.strip_ats
    end
    statuses = client.user_timeline(user, :count => count, :include_entities => false)
  else
    statuses = client.home_timeline(:count => count, :include_entities => false)
  end
  print_statuses(statuses)
end

#trend_locationsObject



726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
# File 'lib/t/cli.rb', line 726

def trend_locations
  places = client.trend_locations
  places = places.sort_by{|places| places.name.downcase} unless options['unsorted']
  places.reverse! if options['reverse']
  if options['csv']
    say ["WOEID", "Parent ID", "Type", "Name", "Country"].to_csv unless places.empty?
    places.each do |place|
      say [place.woeid, place.parent_id, place.place_type, place.name, place.country].to_csv
    end
  elsif options['long']
    array = places.map do |place|
      [place.woeid, place.parent_id, place.place_type, place.name, place.country]
    end
    if STDOUT.tty?
      headings = ["WOEID", "Parent ID", "Type", "Name", "Country"]
      array.unshift(headings) unless places.empty?
      print_table(array, :truncate => true)
    else
      print_table(array)
    end
  else
    if STDOUT.tty?
      print_in_columns(places.map(&:name))
    else
      places.each do |place|
        say place.name
      end
    end
  end
end


708
709
710
711
712
713
714
715
716
717
718
719
# File 'lib/t/cli.rb', line 708

def trends(woe_id=1)
  opts = {}
  opts.merge!(:exclude => "hashtags") if options['exclude-hashtags']
  trends = client.trends(woe_id, opts)
  if STDOUT.tty?
    print_in_columns(trends.map(&:name))
  else
    trends.each do |trend|
      say trend.name
    end
  end
end

#unfollow(user, *users) ⇒ Object



760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
# File 'lib/t/cli.rb', line 760

def unfollow(user, *users)
  users.unshift(user)
  if options['id']
    users.map!(&:to_i)
  else
    users.map!(&:strip_ats)
  end
  users = users.threaded_map do |user|
    retryable(:tries => 3, :on => Twitter::Error::ServerError, :sleep => 0) do
      client.unfollow(user, :include_entities => false)
    end
  end
  number = users.length
  say "@#{@rcfile.active_profile[0]} is no longer following #{number} #{number == 1 ? 'user' : 'users'}."
  say
  say "Run `#{File.basename($0)} follow #{users.map{|user| "@#{user.screen_name}"}.join(' ')}` to follow again."
end

#update(message) ⇒ Object



780
781
782
783
784
785
786
787
# File 'lib/t/cli.rb', line 780

def update(message)
  opts = {:include_entities => false, :trim_user => true}
  opts.merge!(:lat => location.lat, :long => location.lng) if options['location']
  status = client.update(message, opts)
  say "Tweet created by @#{@rcfile.active_profile[0]} (#{time_ago_in_words(status.created_at)} ago)."
  say
  say "Run `#{File.basename($0)} delete status #{status.id}` to delete."
end

#users(user, *users) ⇒ Object



802
803
804
805
806
807
808
809
810
811
# File 'lib/t/cli.rb', line 802

def users(user, *users)
  users.unshift(user)
  if options['id']
    users.map!(&:to_i)
  else
    users.map!(&:strip_ats)
  end
  users = client.users(users, :include_entities => false)
  print_users(users)
end

#versionObject



815
816
817
# File 'lib/t/cli.rb', line 815

def version
  say T::Version
end

#whois(user) ⇒ Object



823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
# File 'lib/t/cli.rb', line 823

def whois(user)
  user = if options['id']
    user.to_i
  else
    user.strip_ats
  end
  user = client.user(user, :include_entities => false)
  if options['csv']
    say ["ID", "Verified", "Name", "Screen name", "Bio", "Location", "Following", "Last update", "Lasted updated at", "Since", "Tweets", "Favorites", "Listed", "Following", "Followers", "URL"].to_csv
    say [user.id, user.verified?, user.name, user.screen_name, user.description, user.location, user.following?, HTMLEntities.new.decode(user.status.text), user.status.created_at.utc.strftime("%Y-%m-%d %H:%M:%S %z"), user.created_at.utc.strftime("%Y-%m-%d %H:%M:%S %z"), user.statuses_count, user.favourites_count, user.listed_count, user.friends_count, user.followers_count, user.url].to_csv
  else
    array = []
    name_label = user.verified ? "Name (Verified)" : "Name"
    array << ["ID", user.id.to_s]
    array << [name_label, user.name] unless user.name.nil?
    array << ["Bio", user.description.gsub(/\n+/, ' ')] unless user.description.nil?
    array << ["Location", user.location] unless user.location.nil?
    status = user.following ? "Following" : "Not following"
    array << ["Status", status]
    array << ["Last update", "#{HTMLEntities.new.decode(user.status.text).gsub(/\n+/, ' ')} (#{time_ago_in_words(user.status.created_at)} ago)"] unless user.status.nil?
    created_at = user.created_at > 6.months.ago ? user.created_at.strftime("%b %e %H:%M") : user.created_at.strftime("%b %e  %Y")
    array << ["Since", created_at]
    array << ["Tweets", number_with_delimiter(user.statuses_count)]
    array << ["Favorites", number_with_delimiter(user.favourites_count)]
    array << ["Listed", number_with_delimiter(user.listed_count)]
    array << ["Following", number_with_delimiter(user.friends_count)]
    array << ["Followers", number_with_delimiter(user.followers_count)]
    array << ["URL", user.url] unless user.url.nil?
    print_table(array)
  end
end