Class: T::List

Inherits:
Thor
  • Object
show all
Includes:
Collectable, Printable, Requestable, Utils
Defined in:
lib/t/list.rb

Constant Summary collapse

DEFAULT_NUM_RESULTS =
20

Constants included from Printable

Printable::LIST_HEADINGS, Printable::MONTH_IN_SECONDS, Printable::TWEET_HEADINGS, Printable::USER_HEADINGS

Constants included from Collectable

Collectable::MAX_NUM_RESULTS, Collectable::MAX_PAGE

Instance Method Summary collapse

Methods included from Collectable

#collect_with_count, #collect_with_max_id, #collect_with_page

Constructor Details

#initializeList

Returns a new instance of List.



20
21
22
23
# File 'lib/t/list.rb', line 20

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

Instance Method Details

#add(list_name, user, *users) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/t/list.rb', line 27

def add(list_name, user, *users)
  added_users, number = fetch_users(users.unshift(user), options) do |users_to_add|
    client.add_list_members(list_name, users_to_add)
    users_to_add
  end
  say "@#{@rcfile.active_profile[0]} added #{pluralize(number, 'member')} to the list \"#{list_name}\"."
  say
  if options["id"]
    say "Run `#{File.basename($PROGRAM_NAME)} list remove --id #{list_name} #{added_users.join(' ')}` to undo."
  else
    say "Run `#{File.basename($PROGRAM_NAME)} list remove #{list_name} #{added_users.collect { |added_user| "@#{added_user}" }.join(' ')}` to undo."
  end
end

#create(list_name, description = nil) ⇒ Object



43
44
45
46
47
48
# File 'lib/t/list.rb', line 43

def create(list_name, description = nil)
  opts = description ? {description:} : {}
  opts[:mode] = "private" if options["private"]
  client.create_list(list_name, opts)
  say "@#{@rcfile.active_profile[0]} created the list \"#{list_name}\"."
end

#information(user_list) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/t/list.rb', line 52

def information(user_list)
  owner, list_name = extract_owner(user_list, options)
  list = client.list(owner, list_name)
  if options["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, :created_at, false)} (#{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(user_list) ⇒ Object



83
84
85
86
87
# File 'lib/t/list.rb', line 83

def members(user_list)
  owner, list_name = extract_owner(user_list, options)
  users = client.list_members(owner, list_name).to_a
  print_users(users)
end

#remove(list_name, user, *users) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/t/list.rb', line 91

def remove(list_name, user, *users)
  removed_users, number = fetch_users(users.unshift(user), options) do |users_to_remove|
    client.remove_list_members(list_name, users_to_remove)
    users_to_remove
  end
  say "@#{@rcfile.active_profile[0]} removed #{pluralize(number, 'member')} from the list \"#{list_name}\"."
  say
  if options["id"]
    say "Run `#{File.basename($PROGRAM_NAME)} list add --id #{list_name} #{removed_users.join(' ')}` to undo."
  else
    say "Run `#{File.basename($PROGRAM_NAME)} list add #{list_name} #{removed_users.collect { |removed_user| "@#{removed_user}" }.join(' ')}` to undo."
  end
end

#timeline(user_list) ⇒ Object



113
114
115
116
117
118
119
120
121
122
# File 'lib/t/list.rb', line 113

def timeline(user_list)
  owner, list_name = extract_owner(user_list, options)
  count = options["number"] || DEFAULT_NUM_RESULTS
  opts = {}
  opts[:include_entities] = !!options["decode_uris"]
  tweets = collect_with_count(count) do |count_opts|
    client.list_timeline(owner, list_name, count_opts.merge(opts))
  end
  print_tweets(tweets)
end