Class: T::CLI
- Inherits:
-
Thor
- Object
- Thor
- T::CLI
- Extended by:
- Forwardable
- Includes:
- Collectable, Printable, Requestable, Utils
- Defined in:
- lib/t/cli.rb
Constant Summary collapse
- DEFAULT_NUM_RESULTS =
20- DIRECT_MESSAGE_HEADINGS =
['ID', 'Posted at', 'Screen name', 'Text']
- TREND_HEADINGS =
['WOEID', 'Parent ID', 'Type', 'Name', 'Country']
Constants included from Printable
Printable::LIST_HEADINGS, Printable::MONTH_IN_SECONDS, Printable::TWEET_HEADINGS, Printable::USER_HEADINGS
Constants included from Collectable
T::Collectable::MAX_NUM_RESULTS
Instance Method Summary collapse
- #accounts ⇒ Object
- #authorize ⇒ Object
- #block(user, *users) ⇒ Object
- #direct_messages ⇒ Object
- #direct_messages_sent ⇒ Object
- #dm(user, message) ⇒ Object
- #does_contain(list, user = nil) ⇒ Object
- #does_follow(user1, user2 = nil) ⇒ Object
- #favorite(status_id, *status_ids) ⇒ Object
- #favorites(user = nil) ⇒ Object
- #follow(user, *users) ⇒ Object
- #followers(user = nil) ⇒ Object
- #followings(user = nil) ⇒ Object
- #friends(user = nil) ⇒ Object
- #groupies(user = nil) ⇒ Object
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #leaders(user = nil) ⇒ Object
- #lists(user = nil) ⇒ Object
- #mentions ⇒ Object
- #open(user) ⇒ Object
- #reply(status_id, message) ⇒ Object
- #report_spam(user, *users) ⇒ Object
- #retweet(status_id, *status_ids) ⇒ Object
- #retweets(user = nil) ⇒ Object
- #ruler ⇒ Object
-
#status(status_id) ⇒ Object
rubocop:disable CyclomaticComplexity.
- #timeline(user = nil) ⇒ Object
- #trend_locations ⇒ Object
- #trends(woe_id = 1) ⇒ Object
- #unfollow(user, *users) ⇒ Object
- #update(message = nil) ⇒ Object
- #users(user, *users) ⇒ Object
- #version ⇒ Object
-
#whois(user) ⇒ Object
rubocop:disable CyclomaticComplexity.
Methods included from Collectable
#collect_with_count, #collect_with_max_id, #collect_with_page
Constructor Details
Instance Method Details
#accounts ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/t/cli.rb', line 41 def accounts @rcfile.path = ['profile'] if ['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 |
#authorize ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 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 110 111 112 |
# File 'lib/t/cli.rb', line 53 def @rcfile.path = ['profile'] if ['profile'] if @rcfile.empty? say "Welcome! Before you can use t, you'll first need to register an" say 'application with Twitter. Just follow the steps below:' say ' 1. Sign in to the Twitter Developer site and click' say " \"Create a new application\"." say ' 2. Complete the required fields and submit the form.' say ' Note: Your application must have a unique name.' say " We recommend: \"<your handle>/t\"." say ' 3. Go to the Settings tab of your application, and change the' say " Access setting to \"Read, Write and Access direct messages\"." say ' 4. Go to the Details tab to view the consumer key and secret,' say " which you'll need to copy and paste below when prompted." say ask 'Press [Enter] to open the Twitter Developer site.' say else say "It looks like you've already registered an application with Twitter." say 'To authorize a new account, just follow the steps below:' say ' 1. Sign in to the Twitter Developer site.' say " 2. Select the application for which you'd like to authorize an account." say ' 3. Copy and paste the consumer key and secret below when prompted.' say ask 'Press [Enter] to open the Twitter Developer site.' say end require 'launchy' open_or_print('https://dev.twitter.com/apps', :dry_run => ['display-uri']) key = ask 'Enter your consumer key:' secret = ask 'Enter your consumer secret:' consumer = OAuth::Consumer.new(key, secret, :site => Twitter::REST::Client::ENDPOINT) request_token = consumer.get_request_token uri = (consumer, request_token) say 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 and paste the supplied PIN below when prompted.' say ask 'Press [Enter] to open the Twitter app authorization page.' say open_or_print(uri, :dry_run => ['display-uri']) pin = ask 'Enter the supplied PIN:' access_token = request_token.get_access_token(:oauth_verifier => pin.chomp) oauth_response = access_token.get('/1.1/account/verify_credentials.json?include_entities=false&skip_status=true') screen_name = oauth_response.body.match(/"screen_name"\s*:\s*"(.*?)"/).captures.first @rcfile[screen_name] = { key => { 'username' => screen_name, 'consumer_key' => key, 'consumer_secret' => secret, 'token' => access_token.token, 'secret' => access_token.secret, } } @rcfile.active_profile = {'username' => screen_name, 'consumer_key' => key} say 'Authorization successful.' end |
#block(user, *users) ⇒ Object
116 117 118 119 120 121 122 123 |
# File 'lib/t/cli.rb', line 116 def block(user, *users) blocked_users, number = fetch_users(users.unshift(user), ) do |users_to_block| client.block(users_to_block) end say "@#{@rcfile.active_profile[0]} blocked #{pluralize(number, 'user')}." say say "Run `#{File.basename($PROGRAM_NAME)} delete block #{blocked_users.map { |blocked_user| "@#{blocked_user.screen_name}" }.join(' ')}` to unblock." end |
#direct_messages ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/t/cli.rb', line 131 def count = ['number'] || DEFAULT_NUM_RESULTS = collect_with_count(count) do |count_opts| client.(count_opts) end .reverse! if ['reverse'] require 'htmlentities' if ['csv'] require 'csv' say DIRECT_MESSAGE_HEADINGS.to_csv unless .empty? .each do || say [.id, csv_formatted_time(), .sender.screen_name, HTMLEntities.new.decode(.text)].to_csv end elsif ['long'] array = .map do || [.id, ls_formatted_time(), "@#{.sender.screen_name}", HTMLEntities.new.decode(.text).gsub(/\n+/, ' ')] end format = ['format'] || DIRECT_MESSAGE_HEADINGS.size.times.map { '%s' } print_table_with_headings(array, DIRECT_MESSAGE_HEADINGS, format) else .each do || (.sender.screen_name, .text) end end end |
#direct_messages_sent ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/t/cli.rb', line 164 def count = ['number'] || DEFAULT_NUM_RESULTS = collect_with_count(count) do |count_opts| client.(count_opts) end .reverse! if ['reverse'] require 'htmlentities' if ['csv'] require 'csv' say DIRECT_MESSAGE_HEADINGS.to_csv unless .empty? .each do || say [.id, csv_formatted_time(), .recipient.screen_name, HTMLEntities.new.decode(.text)].to_csv end elsif ['long'] array = .map do || [.id, ls_formatted_time(), "@#{.recipient.screen_name}", HTMLEntities.new.decode(.text).gsub(/\n+/, ' ')] end format = ['format'] || DIRECT_MESSAGE_HEADINGS.size.times.map { '%s' } print_table_with_headings(array, DIRECT_MESSAGE_HEADINGS, format) else .each do || (.recipient.screen_name, .text) end end end |
#dm(user, message) ⇒ Object
223 224 225 226 227 228 |
# File 'lib/t/cli.rb', line 223 def dm(user, ) require 't/core_ext/string' user = ['id'] ? user.to_i : user.strip_ats = client.(user, ) say "Direct Message sent from @#{@rcfile.active_profile[0]} to @#{.recipient.screen_name}." end |
#does_contain(list, user = nil) ⇒ Object
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/t/cli.rb', line 233 def does_contain(list, user = nil) owner, list = extract_owner(list, ) if user.nil? user = @rcfile.active_profile[0] else require 't/core_ext/string' user = ['id'] ? client.user(user.to_i).screen_name : user.strip_ats end if client.list_member?(owner, list, user) say "Yes, #{list} contains @#{user}." else say "No, #{list} does not contain @#{user}." exit 1 end end |
#does_follow(user1, user2 = nil) ⇒ Object
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 |
# File 'lib/t/cli.rb', line 252 def does_follow(user1, user2 = nil) require 't/core_ext/string' user1 = ['id'] ? client.user(user1.to_i).screen_name : user1.strip_ats if user2.nil? user2 = @rcfile.active_profile[0] else user2 = ['id'] ? client.user(user2.to_i).screen_name : user2.strip_ats 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
270 271 272 273 274 275 276 277 278 279 280 281 |
# File 'lib/t/cli.rb', line 270 def favorite(status_id, *status_ids) status_ids.unshift(status_id) status_ids.map!(&:to_i) require 'retryable' favorites = retryable(:tries => 3, :on => Twitter::Error, :sleep => 0) do client.favorite(status_ids) end number = favorites.length say "@#{@rcfile.active_profile[0]} favorited #{pluralize(number, 'tweet')}." say say "Run `#{File.basename($PROGRAM_NAME)} delete favorite #{status_ids.join(' ')}` to unfavorite." end |
#favorites(user = nil) ⇒ Object
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 |
# File 'lib/t/cli.rb', line 293 def favorites(user = nil) count = ['number'] || DEFAULT_NUM_RESULTS opts = {} opts[:exclude_replies] = true if ['exclude'] == 'replies' opts[:include_rts] = false if ['exclude'] == 'retweets' opts[:max_id] = ['max_id'] if ['max_id'] opts[:since_id] = ['since_id'] if ['since_id'] if user require 't/core_ext/string' user = ['id'] ? user.to_i : user.strip_ats end tweets = collect_with_count(count) do |count_opts| client.favorites(user, count_opts.merge(opts)) end print_tweets(tweets) end |
#follow(user, *users) ⇒ Object
313 314 315 316 317 318 319 320 |
# File 'lib/t/cli.rb', line 313 def follow(user, *users) followed_users, number = fetch_users(users.unshift(user), ) do |users_to_follow| client.follow(users_to_follow) end say "@#{@rcfile.active_profile[0]} is now following #{pluralize(number, 'more user')}." say say "Run `#{File.basename($PROGRAM_NAME)} unfollow #{followed_users.map { |followed_user| "@#{followed_user.screen_name}" }.join(' ')}` to stop." end |
#followers(user = nil) ⇒ Object
351 352 353 354 355 356 357 358 359 360 361 362 |
# File 'lib/t/cli.rb', line 351 def followers(user = nil) if user require 't/core_ext/string' user = ['id'] ? user.to_i : user.strip_ats end follower_ids = client.follower_ids(user).to_a require 'retryable' users = retryable(:tries => 3, :on => Twitter::Error, :sleep => 0) do client.users(follower_ids) end print_users(users) end |
#followings(user = nil) ⇒ Object
330 331 332 333 334 335 336 337 338 339 340 341 |
# File 'lib/t/cli.rb', line 330 def followings(user = nil) if user require 't/core_ext/string' user = ['id'] ? user.to_i : user.strip_ats end following_ids = client.friend_ids(user).to_a require 'retryable' users = retryable(:tries => 3, :on => Twitter::Error, :sleep => 0) do client.users(following_ids) end print_users(users) end |
#friends(user = nil) ⇒ Object
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 |
# File 'lib/t/cli.rb', line 372 def friends(user = nil) user = if user require 't/core_ext/string' ['id'] ? user.to_i : user.strip_ats else client.verify_credentials.screen_name end following_ids = Thread.new do client.friend_ids(user).to_a end follower_ids = Thread.new do client.follower_ids(user).to_a end friend_ids = (following_ids.value & follower_ids.value) require 'retryable' users = retryable(:tries => 3, :on => Twitter::Error, :sleep => 0) do client.users(friend_ids) end print_users(users) end |
#groupies(user = nil) ⇒ Object
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/t/cli.rb', line 199 def groupies(user = nil) user = if user require 't/core_ext/string' ['id'] ? user.to_i : user.strip_ats else client.verify_credentials.screen_name end follower_ids = Thread.new do client.follower_ids(user).to_a end following_ids = Thread.new do client.friend_ids(user).to_a end disciple_ids = (follower_ids.value - following_ids.value) require 'retryable' users = retryable(:tries => 3, :on => Twitter::Error, :sleep => 0) do client.users(disciple_ids) end print_users(users) end |
#leaders(user = nil) ⇒ Object
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 |
# File 'lib/t/cli.rb', line 401 def leaders(user = nil) user = if user require 't/core_ext/string' ['id'] ? user.to_i : user.strip_ats else client.verify_credentials.screen_name end following_ids = Thread.new do client.friend_ids(user).to_a end follower_ids = Thread.new do client.follower_ids(user).to_a end leader_ids = (following_ids.value - follower_ids.value) require 'retryable' users = retryable(:tries => 3, :on => Twitter::Error, :sleep => 0) do client.users(leader_ids) end print_users(users) end |
#lists(user = nil) ⇒ Object
430 431 432 433 434 435 436 437 438 439 |
# File 'lib/t/cli.rb', line 430 def lists(user = nil) lists = if user require 't/core_ext/string' user = ['id'] ? user.to_i : user.strip_ats client.lists(user) else client.lists end print_lists(lists) end |
#mentions ⇒ Object
450 451 452 453 454 455 456 |
# File 'lib/t/cli.rb', line 450 def mentions count = ['number'] || DEFAULT_NUM_RESULTS tweets = collect_with_count(count) do |count_opts| client.mentions(count_opts) end print_tweets(tweets) end |
#open(user) ⇒ Object
463 464 465 466 467 468 469 470 471 472 473 474 475 |
# File 'lib/t/cli.rb', line 463 def open(user) require 'launchy' if ['id'] user = client.user(user.to_i) open_or_print(user.website, :dry_run => ['display-uri']) elsif ['status'] status = client.status(user.to_i, :include_my_retweet => false) open_or_print(status.uri, :dry_run => ['display-uri']) else require 't/core_ext/string' open_or_print("https://twitter.com/#{user.strip_ats}", :dry_run => ['display-uri']) end end |
#reply(status_id, message) ⇒ Object
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 |
# File 'lib/t/cli.rb', line 480 def reply(status_id, ) status = client.status(status_id.to_i, :include_my_retweet => false) users = Array(status.user.screen_name) if ['all'] users += extract_mentioned_screen_names(status.full_text) users.uniq! end require 't/core_ext/string' users.map!(&:prepend_at) opts = {:in_reply_to_status_id => status.id, :trim_user => true} add_location!(, opts) reply = client.update("#{users.join(' ')} #{}", opts) say "Reply posted by @#{@rcfile.active_profile[0]} to #{users.join(' ')}." say say "Run `#{File.basename($PROGRAM_NAME)} delete status #{reply.id}` to delete." end |
#report_spam(user, *users) ⇒ Object
499 500 501 502 503 504 |
# File 'lib/t/cli.rb', line 499 def report_spam(user, *users) _, number = fetch_users(users.unshift(user), ) do |users_to_report| client.report_spam(users_to_report) end say "@#{@rcfile.active_profile[0]} reported #{pluralize(number, 'user')}." end |
#retweet(status_id, *status_ids) ⇒ Object
508 509 510 511 512 513 514 515 516 517 518 519 |
# File 'lib/t/cli.rb', line 508 def retweet(status_id, *status_ids) status_ids.unshift(status_id) status_ids.map!(&:to_i) require 'retryable' retweets = retryable(:tries => 3, :on => Twitter::Error, :sleep => 0) do client.retweet(status_ids, :trim_user => true) end number = retweets.length say "@#{@rcfile.active_profile[0]} retweeted #{pluralize(number, 'tweet')}." say say "Run `#{File.basename($PROGRAM_NAME)} delete status #{retweets.map { |tweet| tweet.retweeted_status.id }.join(' ')}` to undo." end |
#retweets(user = nil) ⇒ Object
529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 |
# File 'lib/t/cli.rb', line 529 def retweets(user = nil) count = ['number'] || DEFAULT_NUM_RESULTS tweets = if user require 't/core_ext/string' user = ['id'] ? user.to_i : user.strip_ats collect_with_count(count) do |count_opts| client.retweeted_by_user(user, count_opts) end else collect_with_count(count) do |count_opts| client.retweeted_by_me(count_opts) end end print_tweets(tweets) end |
#ruler ⇒ Object
548 549 550 551 |
# File 'lib/t/cli.rb', line 548 def ruler markings = '----|'.chars.cycle.take(140).join say "#{' ' * ['indent'].to_i}#{markings}" end |
#status(status_id) ⇒ Object
rubocop:disable CyclomaticComplexity
557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 |
# File 'lib/t/cli.rb', line 557 def status(status_id) # rubocop:disable CyclomaticComplexity status = client.status(status_id.to_i, :include_my_retweet => false) location = if status.place? if status.place.name && status.place.attributes && status.place.attributes[:street_address] && status.place.attributes[:locality] && status.place.attributes[:region] && status.place.country [status.place.name, status.place.attributes[:street_address], status.place.attributes[:locality], status.place.attributes[:region], status.place.country].join(', ') elsif status.place.name && status.place.attributes && status.place.attributes[:locality] && status.place.attributes[:region] && status.place.country [status.place.name, status.place.attributes[:locality], status.place.attributes[:region], status.place.country].join(', ') elsif status.place.full_name && status.place.attributes && status.place.attributes[:region] && status.place.country [status.place.full_name, status.place.attributes[:region], status.place.country].join(', ') elsif status.place.full_name && status.place.country [status.place.full_name, status.place.country].join(', ') elsif status.place.full_name status.place.full_name else status.place.name end elsif status.geo? reverse_geocode(status.geo) end status_headings = ['ID', 'Posted at', 'Screen name', 'Text', 'Retweets', 'Favorites', 'Source', 'Location'] if ['csv'] require 'csv' say status_headings.to_csv say [status.id, csv_formatted_time(status), status.user.screen_name, decode_full_text(status), status.retweet_count, status.favorite_count, (status.source), location].to_csv elsif ['long'] array = [status.id, ls_formatted_time(status), "@#{status.user.screen_name}", decode_full_text(status).gsub(/\n+/, ' '), status.retweet_count, status.favorite_count, (status.source), location] format = ['format'] || status_headings.size.times.map { '%s' } print_table_with_headings([array], status_headings, format) else array = [] array << ['ID', status.id.to_s] array << ['Text', decode_full_text(status).gsub(/\n+/, ' ')] array << ['Screen name', "@#{status.user.screen_name}"] array << ['Posted at', "#{ls_formatted_time(status, :created_at, false)} (#{time_ago_in_words(status.created_at)} ago)"] array << ['Retweets', number_with_delimiter(status.retweet_count)] array << ['Favorites', number_with_delimiter(status.favorite_count)] array << ['Source', (status.source)] array << ['Location', location] unless location.nil? print_table(array) end end |
#timeline(user = nil) ⇒ Object
609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 |
# File 'lib/t/cli.rb', line 609 def timeline(user = nil) count = ['number'] || DEFAULT_NUM_RESULTS opts = {} opts[:exclude_replies] = true if ['exclude'] == 'replies' opts[:include_rts] = false if ['exclude'] == 'retweets' opts[:max_id] = ['max_id'] if ['max_id'] opts[:since_id] = ['since_id'] if ['since_id'] if user require 't/core_ext/string' user = ['id'] ? user.to_i : user.strip_ats tweets = collect_with_count(count) do |count_opts| client.user_timeline(user, count_opts.merge(opts)) end else tweets = collect_with_count(count) do |count_opts| client.home_timeline(count_opts.merge(opts)) end end print_tweets(tweets) end |
#trend_locations ⇒ Object
647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 |
# File 'lib/t/cli.rb', line 647 def trend_locations places = client.trend_locations places = case ['sort'] when 'country' places.sort_by { |place| place.country.downcase } when 'parent' places.sort_by { |place| place.parent_id.to_i } when 'type' places.sort_by { |place| place.place_type.downcase } when 'woeid' places.sort_by { |place| place.woeid.to_i } else places.sort_by { |place| place.name.downcase } end unless ['unsorted'] places.reverse! if ['reverse'] if ['csv'] require 'csv' say TREND_HEADINGS.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 ['long'] array = places.map do |place| [place.woeid, place.parent_id, place.place_type, place.name, place.country] end format = ['format'] || TREND_HEADINGS.size.times.map { '%s' } print_table_with_headings(array, TREND_HEADINGS, format) else print_attribute(places, :name) end end |
#trends(woe_id = 1) ⇒ Object
633 634 635 636 637 638 |
# File 'lib/t/cli.rb', line 633 def trends(woe_id = 1) opts = {} opts.merge!(:exclude => 'hashtags') if ['exclude-hashtags'] trends = client.trends(woe_id, opts) print_attribute(trends, :name) end |
#unfollow(user, *users) ⇒ Object
682 683 684 685 686 687 688 689 |
# File 'lib/t/cli.rb', line 682 def unfollow(user, *users) unfollowed_users, number = fetch_users(users.unshift(user), ) do |users_to_unfollow| client.unfollow(users_to_unfollow) end say "@#{@rcfile.active_profile[0]} is no longer following #{pluralize(number, 'user')}." say say "Run `#{File.basename($PROGRAM_NAME)} follow #{unfollowed_users.map { |unfollowed_user| "@#{unfollowed_user.screen_name}" }.join(' ')}` to follow again." end |
#update(message = nil) ⇒ Object
694 695 696 697 698 699 700 701 702 703 704 705 706 707 |
# File 'lib/t/cli.rb', line 694 def update( = nil) = T::Editor.gets if .nil? || .empty? opts = {:trim_user => true} add_location!(, opts) status = if ['file'] client.update_with_media(, File.new(File.(['file'])), opts) else client.update(, opts) end say "Tweet posted by @#{@rcfile.active_profile[0]}." say say "Run `#{File.basename($PROGRAM_NAME)} delete status #{status.id}` to delete." end |
#users(user, *users) ⇒ Object
718 719 720 721 722 723 724 |
# File 'lib/t/cli.rb', line 718 def users(user, *users) users.unshift(user) require 't/core_ext/string' ['id'] ? users.map!(&:to_i) : users.map!(&:strip_ats) users = client.users(users) print_users(users) end |
#version ⇒ Object
728 729 730 731 |
# File 'lib/t/cli.rb', line 728 def version require 't/version' say T::Version end |
#whois(user) ⇒ Object
rubocop:disable CyclomaticComplexity
739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 |
# File 'lib/t/cli.rb', line 739 def whois(user) # rubocop:disable CyclomaticComplexity require 't/core_ext/string' user = ['id'] ? user.to_i : user.strip_ats user = client.user(user) require 'htmlentities' if ['csv'] || ['long'] print_users([user]) else array = [] array << ['ID', user.id.to_s] array << ['Since', "#{ls_formatted_time(user, :created_at, false)} (#{time_ago_in_words(user.created_at)} ago)"] array << ['Last update', "#{decode_full_text(user.status).gsub(/\n+/, ' ')} (#{time_ago_in_words(user.status.created_at)} ago)"] unless user.status.nil? array << ['Screen name', "@#{user.screen_name}"] array << [user.verified ? 'Name (Verified)' : 'Name', user.name] unless user.name.nil? array << ['Tweets', number_with_delimiter(user.statuses_count)] array << ['Favorites', number_with_delimiter(user.favorites_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 << ['Bio', user.description.gsub(/\n+/, ' ')] unless user.description.nil? array << ['Location', user.location] unless user.location.nil? array << ['URL', user.website] unless user.website.nil? print_table(array) end end |