Class: T::List
- Inherits:
-
Thor
- Object
- Thor
- T::List
- Includes:
- Collectable, Printable, Requestable, Utils
- Defined in:
- lib/t/list.rb
Constant Summary collapse
- DEFAULT_NUM_RESULTS =
20
- MAX_USERS_PER_LIST =
500
- MAX_USERS_PER_REQUEST =
100
Constants included from Printable
Printable::LIST_HEADINGS, Printable::MONTH_IN_SECONDS, Printable::TWEET_HEADINGS, Printable::USER_HEADINGS
Constants included from Collectable
Instance Method Summary collapse
- #add(list, user, *users) ⇒ Object
- #create(list, description = nil) ⇒ Object
- #information(list) ⇒ Object
-
#initialize ⇒ List
constructor
A new instance of List.
- #members(list) ⇒ Object
- #remove(list, user, *users) ⇒ Object
- #timeline(list) ⇒ Object
Methods included from Collectable
#collect_with_count, #collect_with_max_id, #collect_with_page
Constructor Details
Instance Method Details
#add(list, user, *users) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/t/list.rb', line 29 def add(list, user, *users) added_users, number = fetch_users(users.unshift(user), ) do |users_to_add| client.add_list_members(list, users_to_add) users_to_add end say "@#{@rcfile.active_profile[0]} added #{pluralize(number, 'member')} to the list \"#{list}\"." say if ['id'] say "Run `#{File.basename($PROGRAM_NAME)} list remove --id #{list} #{added_users.join(' ')}` to undo." else say "Run `#{File.basename($PROGRAM_NAME)} list remove #{list} #{added_users.map { |added_user| "@#{added_user}" }.join(' ')}` to undo." end end |
#create(list, description = nil) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/t/list.rb', line 45 def create(list, description = nil) opts = description ? {:description => description} : {} opts.merge!(:mode => 'private') if ['private'] client.create_list(list, opts) say "@#{@rcfile.active_profile[0]} created the list \"#{list}\"." end |
#information(list) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/t/list.rb', line 54 def information(list) owner, list = extract_owner(list, ) list = client.list(owner, list) if ['csv'] require 'csv' say ['ID', 'Description', 'Slug', 'Screen name', 'Created at', 'Members', 'Subscribers', 'Following', 'Mode', 'URL'].to_csv say [list.id, list.description, list.slug, list.user.screen_name, csv_formatted_time(list), list.member_count, list.subscriber_count, list.following?, list.mode, list.uri].to_csv else array = [] array << ['ID', list.id.to_s] array << ['Description', list.description] unless list.description.nil? array << ['Slug', list.slug] array << ['Screen name', "@#{list.user.screen_name}"] array << ['Created at', "#{ls_formatted_time(list)} (#{time_ago_in_words(list.created_at)} ago)"] array << ['Members', number_with_delimiter(list.member_count)] array << ['Subscribers', number_with_delimiter(list.subscriber_count)] array << ['Status', list.following ? 'Following' : 'Not following'] array << ['Mode', list.mode] array << ['URL', list.uri] print_table(array) end end |
#members(list) ⇒ Object
85 86 87 88 89 |
# File 'lib/t/list.rb', line 85 def members(list) owner, list = extract_owner(list, ) users = client.list_members(owner, list).to_a print_users(users) end |
#remove(list, user, *users) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/t/list.rb', line 93 def remove(list, user, *users) removed_users, number = fetch_users(users.unshift(user), ) do |users_to_remove| client.remove_list_members(list, users_to_remove) users_to_remove end say "@#{@rcfile.active_profile[0]} removed #{pluralize(number, 'member')} from the list \"#{list}\"." say if ['id'] say "Run `#{File.basename($PROGRAM_NAME)} list add --id #{list} #{removed_users.join(' ')}` to undo." else say "Run `#{File.basename($PROGRAM_NAME)} list add #{list} #{removed_users.map { |removed_user| "@#{removed_user}" }.join(' ')}` to undo." end end |
#timeline(list) ⇒ Object
113 114 115 116 117 118 119 120 |
# File 'lib/t/list.rb', line 113 def timeline(list) owner, list = extract_owner(list, ) count = ['number'] || DEFAULT_NUM_RESULTS tweets = collect_with_count(count) do |count_opts| client.list_timeline(owner, list, count_opts) end print_tweets(tweets) end |