Class: T::CLI
Constant Summary
collapse
- DEFAULT_NUM_RESULTS =
20
- DIRECT_MESSAGE_HEADINGS =
["ID", "Posted at", "Screen name", "Text"].freeze
- MAX_SEARCH_RESULTS =
100
- TREND_HEADINGS =
["WOEID", "Parent ID", "Type", "Name", "Country"].freeze
- TREND_SORT_MAP =
{
"country" => ->(place) { place["country"].to_s.downcase },
"parent" => ->(place) { place["parent_id"].to_i },
"type" => ->(place) { place["place_type"].to_s.downcase },
"woeid" => ->(place) { place["woeid"].to_i },
}.freeze
Constants included
from Utils
Utils::DISTANCE_THRESHOLDS
RequestableAPI::BASE_URL, RequestableAPI::BASE_URL_UPLOAD, RequestableAPI::BASE_URL_V1, RequestableAPI::FORM_HEADERS, RequestableAPI::JSON_HEADERS, RequestableAPI::MAX_PAGE, RequestableAPI::V2_LIST_FIELDS, RequestableAPI::V2_PLACE_FIELDS, RequestableAPI::V2_TWEET_EXPANSIONS, RequestableAPI::V2_TWEET_FIELDS, RequestableAPI::V2_USER_EXPANSIONS, RequestableAPI::V2_USER_FIELDS
Constants included
from Printable
Printable::LISTS_SORT_MAP, Printable::LIST_HEADINGS, Printable::MONTH_IN_SECONDS, Printable::TWEET_HEADINGS, Printable::USERS_SORT_MAP, Printable::USER_HEADINGS
Constants included
from Collectable
T::Collectable::MAX_NUM_RESULTS, T::Collectable::MAX_PAGE
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(user_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
-
#followings_following(user1, user2 = nil) ⇒ Object
-
#friends(user = nil) ⇒ Object
-
#groupies(user = nil) ⇒ Object
-
#initialize ⇒ CLI
constructor
-
#intersection(first_user, *users) ⇒ Object
-
#leaders(user = nil) ⇒ Object
-
#lists(user = nil) ⇒ Object
-
#matrix ⇒ Object
-
#mentions ⇒ Object
-
#mute(user, *users) ⇒ Object
-
#muted ⇒ Object
-
#open(user) ⇒ Object
-
#reach(tweet_id) ⇒ Object
-
#reply(status_id, message = nil) ⇒ Object
-
#report_spam(user, *users) ⇒ Object
-
#retweet(status_id, *status_ids) ⇒ Object
-
#retweets(user = nil) ⇒ Object
-
#retweets_of_me ⇒ Object
-
#ruler ⇒ Object
-
#status(status_id) ⇒ Object
-
#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
-
#whoami ⇒ Object
-
#whois(user) ⇒ Object
#setup_requestable_api!
#x_before_request, #x_filter, #x_sample, #x_settings, #x_trend_locations, #x_trends, #x_update_profile, #x_update_profile_background_image, #x_update_profile_image
#x_add_list_members, #x_create_list, #x_destroy_list, #x_list, #x_list_member?, #x_list_members, #x_list_timeline, #x_lists, #x_remove_list_members
#x_create_direct_message_event, #x_destroy_direct_message, #x_direct_message, #x_direct_messages_received, #x_direct_messages_sent
#x_block, #x_destroy_status, #x_favorite, #x_follow, #x_mute, #x_muted_ids, #x_report_spam, #x_retweet, #x_unblock, #x_unfavorite, #x_unfollow, #x_unmute
#x_favorites, #x_home_timeline, #x_mentions, #x_retweeted_by_me, #x_retweeted_by_user, #x_retweeters_ids, #x_retweets_of_me, #x_search, #x_status, #x_update, #x_update_with_media, #x_user_timeline
#x_follower_ids, #x_friend_ids, #x_friendship?, #x_user, #x_user_search, #x_users, #x_verify_credentials
#collect_with_count, #collect_with_max_id, #collect_with_page
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
36
37
38
39
|
# File 'lib/t/cli.rb', line 36
def initialize(*)
@rcfile = T::RCFile.instance
super
end
|
Instance Method Details
#accounts ⇒ Object
42
43
44
45
46
47
48
49
50
|
# File 'lib/t/cli.rb', line 42
def accounts
@rcfile.path = options["profile"] if options["profile"]
@rcfile.profiles.each do |profile|
say profile[0]
profile[1].each_key do |key|
say " #{key}#{' (active)' if @rcfile.active_profile[0] == profile[0] && @rcfile.active_profile[1] == key}"
end
end
end
|
#authorize ⇒ Object
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
|
# File 'lib/t/cli.rb', line 54
def authorize
@rcfile.path = options["profile"] if options["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 Application Management site and click"
say ' "Create New App".'
say " 2. Complete the required fields and submit the form."
say " Note: Your application must have a unique name."
say " 3. Go to the Permissions tab of your application, and change the"
say ' Access setting to "Read, Write and Access direct messages".'
say " 4. Go to the Keys and Access Tokens tab to view the consumer key"
say " and secret which you'll need to copy and paste below when"
say " prompted."
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."
end
say
ask "Press [Enter] to open the Twitter Developer site."
say
require "launchy"
open_or_print("https://apps.twitter.com", dry_run: options["display-uri"])
key = ask "Enter your API key:"
secret = ask "Enter your API secret:"
consumer = OAuth::Consumer.new(key, secret, site: T::RequestableAPI::BASE_URL)
request_token = consumer.get_request_token
uri = generate_authorize_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: options["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?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
114
115
116
117
118
119
120
121
|
# File 'lib/t/cli.rb', line 114
def block(user, *users)
blocked_users, number = fetch_users(users.unshift(user), options) do |users_to_block|
x_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.collect { |blocked_user| "@#{blocked_user['screen_name']}" }.join(' ')}` to unblock."
end
|
#direct_messages ⇒ Object
130
131
132
133
134
135
136
137
|
# File 'lib/t/cli.rb', line 130
def direct_messages
count = options["number"] || DEFAULT_NUM_RESULTS
opts = {include_entities: !!options["decode_uris"]}
messages = collect_with_count(count) { |count_opts| x_direct_messages_received(count_opts.merge(opts)) }
users_hash = build_dm_users_hash(messages.map { |m| m["sender_id"] })
messages.reverse! if options["reverse"]
format_direct_messages(messages) { |dm| users_hash[dm["sender_id"]]["screen_name"] }
end
|
#direct_messages_sent ⇒ Object
147
148
149
150
151
152
153
|
# File 'lib/t/cli.rb', line 147
def direct_messages_sent
count = options["number"] || DEFAULT_NUM_RESULTS
opts = {include_entities: !!options["decode_uris"]}
messages = collect_with_count(count) { |count_opts| x_direct_messages_sent(count_opts.merge(opts)) }
messages.reverse! if options["reverse"]
format_direct_messages(messages) { |dm| dm["recipient"]["screen_name"] }
end
|
#dm(user, message) ⇒ Object
158
159
160
161
162
|
# File 'lib/t/cli.rb', line 158
def dm(user, message)
recipient = options["id"] ? x_user(user.to_i) : x_user(user.tr("@", ""))
x_create_direct_message_event(recipient, message)
say "Direct Message sent from @#{@rcfile.active_profile[0]} to @#{recipient['screen_name']}."
end
|
#does_contain(user_list, user = nil) ⇒ Object
167
168
169
170
171
172
173
174
175
176
177
178
179
|
# File 'lib/t/cli.rb', line 167
def does_contain(user_list, user = nil)
owner, list_name = (user_list, options)
user = if user.nil?
@rcfile.active_profile[0]
else
options["id"] ? x_user(user.to_i)["screen_name"] : user.tr("@", "")
end
if x_list_member?(owner, list_name, user)
say "Yes, #{list_name} contains @#{user}."
else
abort "No, #{list_name} does not contain @#{user}."
end
end
|
#does_follow(user1, user2 = nil) ⇒ Object
184
185
186
187
188
189
190
191
192
193
194
195
196
|
# File 'lib/t/cli.rb', line 184
def does_follow(user1, user2 = nil)
abort "No, you are not following yourself." if user2.nil? && @rcfile.active_profile[0].casecmp(user1).zero?
abort "No, @#{user1} is not following themself." if user1 == user2
thread1 = Thread.new { resolve_follow_screen_name(user1) }
thread2 = Thread.new { resolve_follow_screen_name(user2) }
user1 = thread1.value
user2 = thread2.value
if x_friendship?(user1, user2)
say "Yes, @#{user1} follows @#{user2}."
else
abort "No, @#{user1} does not follow @#{user2}."
end
end
|
#favorite(status_id, *status_ids) ⇒ Object
200
201
202
203
204
205
206
207
208
209
210
211
|
# File 'lib/t/cli.rb', line 200
def favorite(status_id, *status_ids)
status_ids.unshift(status_id)
status_ids.collect!(&:to_i)
require "retryable"
favorites = Retryable.retryable(tries: 3, on: X::Error, sleep: 0) do
x_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
224
225
226
227
228
229
230
231
232
|
# File 'lib/t/cli.rb', line 224
def favorites(user = nil)
count = options["number"] || DEFAULT_NUM_RESULTS
opts = build_timeline_opts
user = resolve_user_input(user) if user
= collect_with_count(count) do |count_opts|
x_favorites(user, count_opts.merge(opts))
end
()
end
|
#follow(user, *users) ⇒ Object
237
238
239
240
241
242
243
244
|
# File 'lib/t/cli.rb', line 237
def follow(user, *users)
followed_users, number = fetch_users(users.unshift(user), options) do |users_to_follow|
x_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.collect { |followed_user| "@#{followed_user['screen_name']}" }.join(' ')}` to stop."
end
|
#followers(user = nil) ⇒ Object
300
301
302
303
304
305
306
307
308
309
310
|
# File 'lib/t/cli.rb', line 300
def followers(user = nil)
if user
user = options["id"] ? user.to_i : user.tr("@", "")
end
follower_ids = x_follower_ids(user).to_a
require "retryable"
users = Retryable.retryable(tries: 3, on: X::Error, sleep: 0) do
x_users(follower_ids)
end
print_users(users)
end
|
#followings(user = nil) ⇒ Object
254
255
256
257
258
259
260
261
262
263
264
|
# File 'lib/t/cli.rb', line 254
def followings(user = nil)
if user
user = options["id"] ? user.to_i : user.tr("@", "")
end
following_ids = x_friend_ids(user).to_a
require "retryable"
users = Retryable.retryable(tries: 3, on: X::Error, sleep: 0) do
x_users(following_ids)
end
print_users(users)
end
|
#followings_following(user1, user2 = nil) ⇒ Object
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
|
# File 'lib/t/cli.rb', line 274
def followings_following(user1, user2 = nil)
user1 = options["id"] ? user1.to_i : user1.tr("@", "")
user2 = if user2.nil?
@rcfile.active_profile[0]
else
options["id"] ? user2.to_i : user2.tr("@", "")
end
follower_ids = Thread.new { x_follower_ids(user1).to_a }
following_ids = Thread.new { x_friend_ids(user2).to_a }
followings_following_ids = follower_ids.value & following_ids.value
require "retryable"
users = Retryable.retryable(tries: 3, on: X::Error, sleep: 0) do
x_users(followings_following_ids)
end
print_users(users)
end
|
#friends(user = nil) ⇒ Object
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
|
# File 'lib/t/cli.rb', line 320
def friends(user = nil)
user = if user
options["id"] ? user.to_i : user.tr("@", "")
else
x_verify_credentials["screen_name"]
end
following_ids = Thread.new { x_friend_ids(user).to_a }
follower_ids = Thread.new { x_follower_ids(user).to_a }
friend_ids = following_ids.value & follower_ids.value
require "retryable"
users = Retryable.retryable(tries: 3, on: X::Error, sleep: 0) do
x_users(friend_ids)
end
print_users(users)
end
|
#groupies(user = nil) ⇒ Object
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
|
# File 'lib/t/cli.rb', line 344
def groupies(user = nil)
user = if user
options["id"] ? user.to_i : user.tr("@", "")
else
x_verify_credentials["screen_name"]
end
follower_ids = Thread.new { x_follower_ids(user).to_a }
following_ids = Thread.new { x_friend_ids(user).to_a }
groupie_ids = (follower_ids.value - following_ids.value)
require "retryable"
users = Retryable.retryable(tries: 3, on: X::Error, sleep: 0) do
x_users(groupie_ids)
end
print_users(users)
end
|
#intersection(first_user, *users) ⇒ Object
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
|
# File 'lib/t/cli.rb', line 370
def intersection(first_user, *users)
users.push(first_user)
users.push(@rcfile.active_profile[0]) if users.size == 1
options["id"] ? users.collect!(&:to_i) : users.collect! { |u| u.tr("@", "") }
sets = parallel_map(users) do |user|
case options["type"]
when "followings"
x_friend_ids(user).to_a
when "followers"
x_follower_ids(user).to_a
end
end
intersection = sets.reduce(:&)
require "retryable"
users = Retryable.retryable(tries: 3, on: X::Error, sleep: 0) do
x_users(intersection)
end
print_users(users)
end
|
#leaders(user = nil) ⇒ Object
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
|
# File 'lib/t/cli.rb', line 400
def leaders(user = nil)
user = if user
options["id"] ? user.to_i : user.tr("@", "")
else
x_verify_credentials["screen_name"]
end
following_ids = Thread.new { x_friend_ids(user).to_a }
follower_ids = Thread.new { x_follower_ids(user).to_a }
leader_ids = (following_ids.value - follower_ids.value)
require "retryable"
users = Retryable.retryable(tries: 3, on: X::Error, sleep: 0) do
x_users(leader_ids)
end
print_users(users)
end
|
#lists(user = nil) ⇒ Object
424
425
426
427
428
429
430
431
432
|
# File 'lib/t/cli.rb', line 424
def lists(user = nil)
lists = if user
user = options["id"] ? user.to_i : user.tr("@", "")
x_lists(user)
else
x_lists
end
print_lists(lists)
end
|
#matrix ⇒ Object
435
436
437
438
439
440
441
442
443
444
445
446
447
|
# File 'lib/t/cli.rb', line 435
def matrix
rule_ids = install_matrix_stream_rules
stream_fields = "tweet.fields=text"
bearer_client.stream("tweets/search/stream?#{stream_fields}") do |json|
= (json).first
next unless
text = (["text"] || "").gsub(/[^\u3000\u3040-\u309f]/, "").reverse
say(text, i[bold green on_black], false) unless text.empty?
end
ensure
remove_matrix_stream_rules(rule_ids || [])
end
|
#mentions ⇒ Object
456
457
458
459
460
461
462
463
464
|
# File 'lib/t/cli.rb', line 456
def mentions
count = options["number"] || DEFAULT_NUM_RESULTS
opts = {}
opts[:include_entities] = !!options["decode_uris"]
= collect_with_count(count) do |count_opts|
x_mentions(count_opts.merge(opts))
end
()
end
|
#mute(user, *users) ⇒ Object
469
470
471
472
473
474
475
476
|
# File 'lib/t/cli.rb', line 469
def mute(user, *users)
muted_users, number = fetch_users(users.unshift(user), options) do |users_to_mute|
x_mute(users_to_mute)
end
say "@#{@rcfile.active_profile[0]} muted #{pluralize(number, 'user')}."
say
say "Run `#{File.basename($PROGRAM_NAME)} delete mute #{muted_users.collect { |muted_user| "@#{muted_user['screen_name']}" }.join(' ')}` to unmute."
end
|
#muted ⇒ Object
485
486
487
488
489
490
491
492
|
# File 'lib/t/cli.rb', line 485
def muted
muted_ids = x_muted_ids.to_a
require "retryable"
muted_users = Retryable.retryable(tries: 3, on: X::Error, sleep: 0) do
x_users(muted_ids)
end
print_users(muted_users)
end
|
#open(user) ⇒ Object
499
500
501
502
503
504
505
506
507
508
509
510
|
# File 'lib/t/cli.rb', line 499
def open(user)
require "launchy"
if options["id"]
user = x_user(user.to_i)
open_or_print(user["url"], dry_run: options["display-uri"])
elsif options["status"]
status = x_status(user.to_i, include_my_retweet: false)
open_or_print(status["url"], dry_run: options["display-uri"])
else
open_or_print("https://twitter.com/#{user.tr('@', '')}", dry_run: options["display-uri"])
end
end
|
#reach(tweet_id) ⇒ Object
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
|
# File 'lib/t/cli.rb', line 513
def reach()
status_thread = Thread.new { x_status(.to_i, include_my_retweet: false) }
threads = (.to_i).collect do ||
Thread.new() do |user_id|
x_follower_ids(user_id).to_a
end
end
status = status_thread.value
threads << Thread.new(status["user"]["id"]) do |user_id|
x_follower_ids(user_id).to_a
end
reach = ::Set.new
threads.each { |thread| reach += thread.value }
reach.delete(status["user"]["id"])
say number_with_delimiter(reach.size)
end
|
#reply(status_id, message = nil) ⇒ Object
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
|
# File 'lib/t/cli.rb', line 534
def reply(status_id, message = nil)
message = T::Editor.gets if message.to_s.empty?
status = x_status(status_id.to_i, include_my_retweet: false)
users = Array(status["user"]["screen_name"])
if options["all"]
users += (status["full_text"])
users.uniq!
end
users.delete(@rcfile.active_profile[0])
users.collect! { |u| "@#{u}" }
opts = {in_reply_to_status_id: status["id"]}
add_location!(options, opts)
reply = if options["file"]
x_update_with_media("#{users.join(' ')} #{message}", File.new(File.expand_path(options["file"])), opts)
else
x_update("#{users.join(' ')} #{message}", opts)
end
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
558
559
560
561
562
563
|
# File 'lib/t/cli.rb', line 558
def report_spam(user, *users)
_, number = fetch_users(users.unshift(user), options) do |users_to_report|
x_report_spam(users_to_report)
end
say "@#{@rcfile.active_profile[0]} reported #{pluralize(number, 'user')}."
end
|
567
568
569
570
571
572
573
574
575
576
577
578
|
# File 'lib/t/cli.rb', line 567
def (status_id, *status_ids)
status_ids.unshift(status_id)
status_ids.collect!(&:to_i)
require "retryable"
= Retryable.retryable(tries: 3, on: X::Error, sleep: 0) do
(status_ids)
end
number = .length
say "@#{@rcfile.active_profile[0]} retweeted #{pluralize(number, 'tweet')}."
say
say "Run `#{File.basename($PROGRAM_NAME)} delete status #{retweets.collect { |r| r['id'] }.join(' ')}` to undo."
end
|
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
|
# File 'lib/t/cli.rb', line 589
def (user = nil)
count = options["number"] || DEFAULT_NUM_RESULTS
opts = {}
opts[:include_entities] = !!options["decode_uris"]
= if user
user = options["id"] ? user.to_i : user.tr("@", "")
collect_with_count(count) do |count_opts|
(user, count_opts.merge(opts))
end
else
collect_with_count(count) do |count_opts|
(count_opts.merge(opts))
end
end
()
end
|
614
615
616
617
618
619
620
621
622
|
# File 'lib/t/cli.rb', line 614
def
count = options["number"] || DEFAULT_NUM_RESULTS
opts = {}
opts[:include_entities] = !!options["decode_uris"]
= collect_with_count(count) do |count_opts|
(count_opts.merge(opts))
end
()
end
|
#ruler ⇒ Object
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
|
# File 'lib/t/cli.rb', line 627
def ruler
width = 280
indent = " " * options["indent"].to_i
line = (1..width).map do |position|
if (position % 10).zero?
"|"
elsif (position % 5).zero?
":"
else
"."
end
end.join
(20..width).step(20) do |marker|
label = marker.to_s
start = marker - label.length - 1
line[start, label.length] = label
line[marker - 1] = "|"
end
say "#{indent}#{line}"
end
|
#status(status_id) ⇒ Object
655
656
657
658
659
660
|
# File 'lib/t/cli.rb', line 655
def status(status_id)
opts = {include_my_retweet: false, include_entities: !!options["decode_uris"]}
status = x_status(status_id.to_i, opts)
location = (status)
format_status(status, location)
end
|
#timeline(user = nil) ⇒ Object
673
674
675
676
677
678
679
680
681
682
683
|
# File 'lib/t/cli.rb', line 673
def timeline(user = nil)
count = options["number"] || DEFAULT_NUM_RESULTS
opts = build_timeline_opts
= if user
user = resolve_user_input(user)
collect_with_count(count) { |count_opts| x_user_timeline(user, count_opts.merge(opts)) }
else
collect_with_count(count) { |count_opts| x_home_timeline(count_opts.merge(opts)) }
end
()
end
|
#trend_locations ⇒ Object
702
703
704
705
706
|
# File 'lib/t/cli.rb', line 702
def trend_locations
places = x_trend_locations
places = sort_collection(places, TREND_SORT_MAP, ->(place) { place["name"].downcase })
format_trend_locations(places)
end
|
#trends(woe_id = 1) ⇒ Object
688
689
690
691
692
693
|
# File 'lib/t/cli.rb', line 688
def trends(woe_id = 1)
opts = {}
opts[:exclude] = "hashtags" if options["exclude-hashtags"]
trends = x_trends(woe_id, opts)
print_attribute(trends, "name")
end
|
#unfollow(user, *users) ⇒ Object
711
712
713
714
715
716
717
718
|
# File 'lib/t/cli.rb', line 711
def unfollow(user, *users)
unfollowed_users, number = fetch_users(users.unshift(user), options) do |users_to_unfollow|
x_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.collect { |unfollowed_user| "@#{unfollowed_user['screen_name']}" }.join(' ')}` to follow again."
end
|
#update(message = nil) ⇒ Object
723
724
725
726
727
728
729
730
731
732
733
734
735
|
# File 'lib/t/cli.rb', line 723
def update(message = nil)
message = T::Editor.gets if message.to_s.empty?
opts = {}
add_location!(options, opts)
status = if options["file"]
x_update_with_media(message, File.new(File.expand_path(options["file"])), opts)
else
x_update(message, 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
746
747
748
749
750
751
752
753
754
|
# File 'lib/t/cli.rb', line 746
def users(user, *users)
users.unshift(user)
options["id"] ? users.collect!(&:to_i) : users.collect! { |u| u.tr("@", "") }
require "retryable"
users = Retryable.retryable(tries: 3, on: X::Error, sleep: 0) do
x_users(users)
end
print_users(users)
end
|
#version ⇒ Object
758
759
760
761
|
# File 'lib/t/cli.rb', line 758
def version
require "t/version"
say T::Version
end
|
#whoami ⇒ Object
787
788
789
790
791
792
793
794
795
796
797
798
|
# File 'lib/t/cli.rb', line 787
def whoami
if @rcfile.active_profile && @rcfile.active_profile[0]
user = x_verify_credentials
if options["csv"] || options["long"]
print_users([user])
else
format_whois_default(user)
end
else
warn "You haven't authorized an account, run `t authorize` to get started."
end
end
|
#whois(user) ⇒ Object
770
771
772
773
774
775
776
777
778
779
|
# File 'lib/t/cli.rb', line 770
def whois(user)
user = resolve_user_input(user)
opts = {include_entities: !!options["decode_uris"]}
user = x_user(user, opts)
if options["csv"] || options["long"]
print_users([user])
else
format_whois_default(user)
end
end
|