t 3.1.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/t/collectable.rb CHANGED
@@ -1,6 +1,6 @@
1
- require 'twitter'
2
- require 'retryable'
3
- require 'set'
1
+ require "twitter"
2
+ require "retryable"
3
+ require "set"
4
4
 
5
5
  module T
6
6
  module Collectable
@@ -12,6 +12,7 @@ module T
12
12
  yield(max_id)
13
13
  end
14
14
  return collection if tweets.nil?
15
+
15
16
  collection += tweets
16
17
  tweets.empty? ? collection.flatten : collect_with_max_id(collection, tweets.last.id - 1, &block)
17
18
  end
@@ -22,7 +23,7 @@ module T
22
23
  collect_with_max_id do |max_id|
23
24
  opts[:max_id] = max_id unless max_id.nil?
24
25
  opts[:count] = count unless count >= MAX_NUM_RESULTS
25
- if count > 0
26
+ if count.positive?
26
27
  tweets = yield opts
27
28
  count -= tweets.length
28
29
  tweets
@@ -35,6 +36,7 @@ module T
35
36
  yield page
36
37
  end
37
38
  return collection if tweets.nil? || tweets == previous || page >= MAX_PAGE
39
+
38
40
  collection += tweets
39
41
  tweets.empty? ? collection.flatten : collect_with_page(collection, page + 1, tweets, &block)
40
42
  end
@@ -1,13 +1,13 @@
1
1
  module Kernel
2
- def Bignum(arg, base = 0) # rubocop:disable MethodName
2
+ def Bignum(arg, base = 0) # rubocop:disable Naming/MethodName
3
3
  Integer(arg, base)
4
4
  end
5
5
 
6
- def Fixnum(arg, base = 0) # rubocop:disable MethodName
6
+ def Fixnum(arg, base = 0) # rubocop:disable Naming/MethodName
7
7
  Integer(arg, base)
8
8
  end
9
9
 
10
- def NilClass(_) # rubocop:disable MethodName
10
+ def NilClass(_) # rubocop:disable Naming/MethodName
11
11
  nil
12
12
  end
13
13
  end
@@ -4,12 +4,12 @@ class String
4
4
  end
5
5
 
6
6
  def strip_ats
7
- tr('@', '')
7
+ tr("@", "")
8
8
  end
9
9
 
10
10
  alias old_to_i to_i
11
11
 
12
12
  def to_i(base = 10)
13
- tr(',', '').old_to_i(base)
13
+ tr(",", "").old_to_i(base)
14
14
  end
15
15
  end
data/lib/t/delete.rb CHANGED
@@ -1,8 +1,8 @@
1
- require 'thor'
2
- require 'twitter'
3
- require 't/rcfile'
4
- require 't/requestable'
5
- require 't/utils'
1
+ require "thor"
2
+ require "twitter"
3
+ require "t/rcfile"
4
+ require "t/requestable"
5
+ require "t/utils"
6
6
 
7
7
  module T
8
8
  class Delete < Thor
@@ -16,9 +16,9 @@ module T
16
16
  super
17
17
  end
18
18
 
19
- desc 'block USER [USER...]', 'Unblock users.'
20
- method_option 'id', aliases: '-i', type: :boolean, desc: 'Specify input as Twitter user IDs instead of screen names.'
21
- method_option 'force', aliases: '-f', type: :boolean
19
+ desc "block USER [USER...]", "Unblock users."
20
+ method_option "id", aliases: "-i", type: :boolean, desc: "Specify input as Twitter user IDs instead of screen names."
21
+ method_option "force", aliases: "-f", type: :boolean
22
22
  def block(user, *users)
23
23
  unblocked_users, number = fetch_users(users.unshift(user), options) do |users_to_unblock|
24
24
  client.unblock(users_to_unblock)
@@ -28,35 +28,37 @@ module T
28
28
  say "Run `#{File.basename($PROGRAM_NAME)} block #{unblocked_users.collect { |unblocked_user| "@#{unblocked_user.screen_name}" }.join(' ')}` to block."
29
29
  end
30
30
 
31
- desc 'dm [DIRECT_MESSAGE_ID] [DIRECT_MESSAGE_ID...]', 'Delete the last Direct Message sent.'
32
- method_option 'force', aliases: '-f', type: :boolean
31
+ desc "dm [DIRECT_MESSAGE_ID] [DIRECT_MESSAGE_ID...]", "Delete the last Direct Message sent."
32
+ method_option "force", aliases: "-f", type: :boolean
33
33
  def dm(direct_message_id, *direct_message_ids)
34
34
  direct_message_ids.unshift(direct_message_id)
35
- require 't/core_ext/string'
35
+ require "t/core_ext/string"
36
36
  direct_message_ids.collect!(&:to_i)
37
- if options['force']
38
- direct_messages = client.destroy_direct_message(direct_message_ids)
39
- direct_messages.each do |direct_message|
40
- say "@#{@rcfile.active_profile[0]} deleted the direct message sent to @#{direct_message.recipient.screen_name}: \"#{direct_message.text}\""
41
- end
37
+ if options["force"]
38
+ client.destroy_direct_message(*direct_message_ids)
39
+ say "@#{@rcfile.active_profile[0]} deleted #{direct_message_ids.size} direct message#{direct_message_ids.size == 1 ? '' : 's'}."
42
40
  else
43
41
  direct_message_ids.each do |direct_message_id_to_delete|
44
42
  direct_message = client.direct_message(direct_message_id_to_delete)
45
- next unless yes? "Are you sure you want to permanently delete the direct message to @#{direct_message.recipient.screen_name}: \"#{direct_message.text}\"? [y/N]"
43
+ next unless direct_message
44
+
45
+ recipient = client.user(direct_message.recipient_id)
46
+ next unless yes? "Are you sure you want to permanently delete the direct message to @#{recipient.screen_name}: \"#{direct_message.text}\"? [y/N]"
47
+
46
48
  client.destroy_direct_message(direct_message_id_to_delete)
47
- say "@#{@rcfile.active_profile[0]} deleted the direct message sent to @#{direct_message.recipient.screen_name}: \"#{direct_message.text}\""
49
+ say "@#{@rcfile.active_profile[0]} deleted the direct message sent to @#{recipient.screen_name}: \"#{direct_message.text}\""
48
50
  end
49
51
  end
50
52
  end
51
- map %w(d m) => :dm
53
+ map %w[d m] => :dm
52
54
 
53
- desc 'favorite TWEET_ID [TWEET_ID...]', 'Delete favorites.'
54
- method_option 'force', aliases: '-f', type: :boolean
55
+ desc "favorite TWEET_ID [TWEET_ID...]", "Delete favorites."
56
+ method_option "force", aliases: "-f", type: :boolean
55
57
  def favorite(status_id, *status_ids)
56
58
  status_ids.unshift(status_id)
57
- require 't/core_ext/string'
59
+ require "t/core_ext/string"
58
60
  status_ids.collect!(&:to_i)
59
- if options['force']
61
+ if options["force"]
60
62
  tweets = client.unfavorite(status_ids)
61
63
  tweets.each do |status|
62
64
  say "@#{@rcfile.active_profile[0]} unfavorited @#{status.user.screen_name}'s status: \"#{status.full_text}\""
@@ -65,32 +67,32 @@ module T
65
67
  status_ids.each do |status_id_to_unfavorite|
66
68
  status = client.status(status_id_to_unfavorite, include_my_retweet: false)
67
69
  next unless yes? "Are you sure you want to remove @#{status.user.screen_name}'s status: \"#{status.full_text}\" from your favorites? [y/N]"
70
+
68
71
  client.unfavorite(status_id_to_unfavorite)
69
72
  say "@#{@rcfile.active_profile[0]} unfavorited @#{status.user.screen_name}'s status: \"#{status.full_text}\""
70
73
  end
71
74
  end
72
75
  end
73
- map %w(fave favourite) => :favorite
76
+ map %w[fave favourite] => :favorite
74
77
 
75
- desc 'list LIST', 'Delete a list.'
76
- method_option 'force', aliases: '-f', type: :boolean
77
- method_option 'id', aliases: '-i', type: :boolean, desc: 'Specify list via ID instead of slug.'
78
+ desc "list LIST", "Delete a list."
79
+ method_option "force", aliases: "-f", type: :boolean
80
+ method_option "id", aliases: "-i", type: :boolean, desc: "Specify list via ID instead of slug."
78
81
  def list(list)
79
- if options['id']
80
- require 't/core_ext/string'
82
+ if options["id"]
83
+ require "t/core_ext/string"
81
84
  list = list.to_i
82
85
  end
83
86
  list = client.list(list)
84
- unless options['force']
85
- return unless yes? "Are you sure you want to permanently delete the list \"#{list.name}\"? [y/N]"
86
- end
87
+ return if !options["force"] && !(yes? "Are you sure you want to permanently delete the list \"#{list.name}\"? [y/N]")
88
+
87
89
  client.destroy_list(list)
88
90
  say "@#{@rcfile.active_profile[0]} deleted the list \"#{list.name}\"."
89
91
  end
90
92
 
91
- desc 'mute USER [USER...]', 'Unmute users.'
92
- method_option 'id', aliases: '-i', type: :boolean, desc: 'Specify input as Twitter user IDs instead of screen names.'
93
- method_option 'force', aliases: '-f', type: :boolean
93
+ desc "mute USER [USER...]", "Unmute users."
94
+ method_option "id", aliases: "-i", type: :boolean, desc: "Specify input as Twitter user IDs instead of screen names."
95
+ method_option "force", aliases: "-f", type: :boolean
94
96
  def mute(user, *users)
95
97
  unmuted_users, number = fetch_users(users.unshift(user), options) do |users_to_unmute|
96
98
  client.unmute(users_to_unmute)
@@ -100,7 +102,7 @@ module T
100
102
  say "Run `#{File.basename($PROGRAM_NAME)} mute #{unmuted_users.collect { |unmuted_user| "@#{unmuted_user.screen_name}" }.join(' ')}` to mute."
101
103
  end
102
104
 
103
- desc 'account SCREEN_NAME [CONSUMER_KEY]', 'delete account or consumer key from t'
105
+ desc "account SCREEN_NAME [CONSUMER_KEY]", "delete account or consumer key from t"
104
106
  def account(account, key = nil)
105
107
  if key && @rcfile.profiles[account].keys.size > 1
106
108
  @rcfile.delete_key(account, key)
@@ -109,13 +111,13 @@ module T
109
111
  end
110
112
  end
111
113
 
112
- desc 'status TWEET_ID [TWEET_ID...]', 'Delete Tweets.'
113
- method_option 'force', aliases: '-f', type: :boolean
114
+ desc "status TWEET_ID [TWEET_ID...]", "Delete Tweets."
115
+ method_option "force", aliases: "-f", type: :boolean
114
116
  def status(status_id, *status_ids)
115
117
  status_ids.unshift(status_id)
116
- require 't/core_ext/string'
118
+ require "t/core_ext/string"
117
119
  status_ids.collect!(&:to_i)
118
- if options['force']
120
+ if options["force"]
119
121
  tweets = client.destroy_status(status_ids, trim_user: true)
120
122
  tweets.each do |status|
121
123
  say "@#{@rcfile.active_profile[0]} deleted the Tweet: \"#{status.full_text}\""
@@ -124,11 +126,12 @@ module T
124
126
  status_ids.each do |status_id_to_delete|
125
127
  status = client.status(status_id_to_delete, include_my_retweet: false)
126
128
  next unless yes? "Are you sure you want to permanently delete @#{status.user.screen_name}'s status: \"#{status.full_text}\"? [y/N]"
129
+
127
130
  client.destroy_status(status_id_to_delete, trim_user: true)
128
131
  say "@#{@rcfile.active_profile[0]} deleted the Tweet: \"#{status.full_text}\""
129
132
  end
130
133
  end
131
134
  end
132
- map %w(post tweet update) => :status
135
+ map %w[post tweet update] => :status
133
136
  end
134
137
  end
data/lib/t/editor.rb CHANGED
@@ -1,5 +1,5 @@
1
- require 'tempfile'
2
- require 'shellwords'
1
+ require "tempfile"
2
+ require "shellwords"
3
3
 
4
4
  module T
5
5
  class Editor
@@ -14,7 +14,7 @@ module T
14
14
  end
15
15
 
16
16
  def tempfile
17
- Tempfile.new('TWEET_EDITMSG')
17
+ Tempfile.new("TWEET_EDITMSG")
18
18
  end
19
19
 
20
20
  def edit(path)
@@ -22,11 +22,11 @@ module T
22
22
  end
23
23
 
24
24
  def editor
25
- ENV['VISUAL'] || ENV['EDITOR'] || system_editor
25
+ ENV["VISUAL"] || ENV["EDITOR"] || system_editor
26
26
  end
27
27
 
28
28
  def system_editor
29
- RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ ? 'notepad' : 'vi'
29
+ RbConfig::CONFIG["host_os"] =~ /mswin|mingw/ ? "notepad" : "vi"
30
30
  end
31
31
  end
32
32
  end
data/lib/t/identicon.rb CHANGED
@@ -42,7 +42,7 @@ module T
42
42
  private
43
43
 
44
44
  def digest(string)
45
- require 'digest'
45
+ require "digest"
46
46
  Digest::MD5.digest(string).chars.inject(0) { |acc, elem| (acc << 8) | elem.ord }
47
47
  end
48
48
  end
data/lib/t/list.rb CHANGED
@@ -1,10 +1,10 @@
1
- require 'thor'
2
- require 'twitter'
3
- require 't/collectable'
4
- require 't/printable'
5
- require 't/rcfile'
6
- require 't/requestable'
7
- require 't/utils'
1
+ require "thor"
2
+ require "twitter"
3
+ require "t/collectable"
4
+ require "t/printable"
5
+ require "t/rcfile"
6
+ require "t/requestable"
7
+ require "t/utils"
8
8
 
9
9
  module T
10
10
  class List < Thor
@@ -22,8 +22,8 @@ module T
22
22
  super
23
23
  end
24
24
 
25
- desc 'add LIST USER [USER...]', 'Add members to a list.'
26
- method_option 'id', aliases: '-i', type: :boolean, desc: 'Specify input as Twitter user IDs instead of screen names.'
25
+ desc "add LIST USER [USER...]", "Add members to a list."
26
+ method_option "id", aliases: "-i", type: :boolean, desc: "Specify input as Twitter user IDs instead of screen names."
27
27
  def add(list_name, user, *users)
28
28
  added_users, number = fetch_users(users.unshift(user), options) do |users_to_add|
29
29
  client.add_list_members(list_name, users_to_add)
@@ -31,63 +31,63 @@ module T
31
31
  end
32
32
  say "@#{@rcfile.active_profile[0]} added #{pluralize(number, 'member')} to the list \"#{list_name}\"."
33
33
  say
34
- if options['id']
34
+ if options["id"]
35
35
  say "Run `#{File.basename($PROGRAM_NAME)} list remove --id #{list_name} #{added_users.join(' ')}` to undo."
36
36
  else
37
37
  say "Run `#{File.basename($PROGRAM_NAME)} list remove #{list_name} #{added_users.collect { |added_user| "@#{added_user}" }.join(' ')}` to undo."
38
38
  end
39
39
  end
40
40
 
41
- desc 'create LIST [DESCRIPTION]', 'Create a new list.'
42
- method_option 'private', aliases: '-p', type: :boolean
41
+ desc "create LIST [DESCRIPTION]", "Create a new list."
42
+ method_option "private", aliases: "-p", type: :boolean
43
43
  def create(list_name, description = nil)
44
44
  opts = description ? {description: description} : {}
45
- opts[:mode] = 'private' if options['private']
45
+ opts[:mode] = "private" if options["private"]
46
46
  client.create_list(list_name, opts)
47
47
  say "@#{@rcfile.active_profile[0]} created the list \"#{list_name}\"."
48
48
  end
49
49
 
50
- desc 'information [USER/]LIST', 'Retrieves detailed information about a Twitter list.'
51
- method_option 'csv', aliases: '-c', type: :boolean, desc: 'Output in CSV format.'
50
+ desc "information [USER/]LIST", "Retrieves detailed information about a Twitter list."
51
+ method_option "csv", aliases: "-c", type: :boolean, desc: "Output in CSV format."
52
52
  def information(user_list)
53
53
  owner, list_name = extract_owner(user_list, options)
54
54
  list = client.list(owner, list_name)
55
- if options['csv']
56
- require 'csv'
57
- say ['ID', 'Description', 'Slug', 'Screen name', 'Created at', 'Members', 'Subscribers', 'Following', 'Mode', 'URL'].to_csv
55
+ if options["csv"]
56
+ require "csv"
57
+ say ["ID", "Description", "Slug", "Screen name", "Created at", "Members", "Subscribers", "Following", "Mode", "URL"].to_csv
58
58
  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
59
59
  else
60
60
  array = []
61
- array << ['ID', list.id.to_s]
62
- array << ['Description', list.description] unless list.description.nil?
63
- array << ['Slug', list.slug]
64
- array << ['Screen name', "@#{list.user.screen_name}"]
65
- array << ['Created at', "#{ls_formatted_time(list, :created_at, false)} (#{time_ago_in_words(list.created_at)} ago)"]
66
- array << ['Members', number_with_delimiter(list.member_count)]
67
- array << ['Subscribers', number_with_delimiter(list.subscriber_count)]
68
- array << ['Status', list.following? ? 'Following' : 'Not following']
69
- array << ['Mode', list.mode]
70
- array << ['URL', list.uri]
61
+ array << ["ID", list.id.to_s]
62
+ array << ["Description", list.description] unless list.description.nil?
63
+ array << ["Slug", list.slug]
64
+ array << ["Screen name", "@#{list.user.screen_name}"]
65
+ array << ["Created at", "#{ls_formatted_time(list, :created_at, false)} (#{time_ago_in_words(list.created_at)} ago)"]
66
+ array << ["Members", number_with_delimiter(list.member_count)]
67
+ array << ["Subscribers", number_with_delimiter(list.subscriber_count)]
68
+ array << ["Status", list.following? ? "Following" : "Not following"]
69
+ array << ["Mode", list.mode]
70
+ array << ["URL", list.uri]
71
71
  print_table(array)
72
72
  end
73
73
  end
74
- map %w(details) => :information
74
+ map %w[details] => :information
75
75
 
76
- desc 'members [USER/]LIST', 'Returns the members of a Twitter list.'
77
- method_option 'csv', aliases: '-c', type: :boolean, desc: 'Output in CSV format.'
78
- method_option 'id', aliases: '-i', type: :boolean, desc: 'Specify user via ID instead of screen name.'
79
- method_option 'long', aliases: '-l', type: :boolean, desc: 'Output in long format.'
80
- method_option 'reverse', aliases: '-r', type: :boolean, desc: 'Reverse the order of the sort.'
81
- method_option 'sort', aliases: '-s', type: :string, enum: %w(favorites followers friends listed screen_name since tweets tweeted), default: 'screen_name', desc: 'Specify the order of the results.', banner: 'ORDER'
82
- method_option 'unsorted', aliases: '-u', type: :boolean, desc: 'Output is not sorted.'
76
+ desc "members [USER/]LIST", "Returns the members of a Twitter list."
77
+ method_option "csv", aliases: "-c", type: :boolean, desc: "Output in CSV format."
78
+ method_option "id", aliases: "-i", type: :boolean, desc: "Specify user via ID instead of screen name."
79
+ method_option "long", aliases: "-l", type: :boolean, desc: "Output in long format."
80
+ method_option "reverse", aliases: "-r", type: :boolean, desc: "Reverse the order of the sort."
81
+ method_option "sort", aliases: "-s", type: :string, enum: %w[favorites followers friends listed screen_name since tweets tweeted], default: "screen_name", desc: "Specify the order of the results.", banner: "ORDER"
82
+ method_option "unsorted", aliases: "-u", type: :boolean, desc: "Output is not sorted."
83
83
  def members(user_list)
84
84
  owner, list_name = extract_owner(user_list, options)
85
85
  users = client.list_members(owner, list_name).to_a
86
86
  print_users(users)
87
87
  end
88
88
 
89
- desc 'remove LIST USER [USER...]', 'Remove members from a list.'
90
- method_option 'id', aliases: '-i', type: :boolean, desc: 'Specify input as Twitter user IDs instead of screen names.'
89
+ desc "remove LIST USER [USER...]", "Remove members from a list."
90
+ method_option "id", aliases: "-i", type: :boolean, desc: "Specify input as Twitter user IDs instead of screen names."
91
91
  def remove(list_name, user, *users)
92
92
  removed_users, number = fetch_users(users.unshift(user), options) do |users_to_remove|
93
93
  client.remove_list_members(list_name, users_to_remove)
@@ -95,31 +95,31 @@ module T
95
95
  end
96
96
  say "@#{@rcfile.active_profile[0]} removed #{pluralize(number, 'member')} from the list \"#{list_name}\"."
97
97
  say
98
- if options['id']
98
+ if options["id"]
99
99
  say "Run `#{File.basename($PROGRAM_NAME)} list add --id #{list_name} #{removed_users.join(' ')}` to undo."
100
100
  else
101
101
  say "Run `#{File.basename($PROGRAM_NAME)} list add #{list_name} #{removed_users.collect { |removed_user| "@#{removed_user}" }.join(' ')}` to undo."
102
102
  end
103
103
  end
104
104
 
105
- desc 'timeline [USER/]LIST', 'Show tweet timeline for members of the specified list.'
106
- method_option 'csv', aliases: '-c', type: :boolean, desc: 'Output in CSV format.'
107
- method_option 'decode_uris', aliases: '-d', type: :boolean, desc: 'Decodes t.co URLs into their original form.'
108
- method_option 'id', aliases: '-i', type: :boolean, desc: 'Specify user via ID instead of screen name.'
109
- method_option 'long', aliases: '-l', type: :boolean, desc: 'Output in long format.'
110
- method_option 'number', aliases: '-n', type: :numeric, default: DEFAULT_NUM_RESULTS, desc: 'Limit the number of results.'
111
- method_option 'relative_dates', aliases: '-a', type: :boolean, desc: 'Show relative dates.'
112
- method_option 'reverse', aliases: '-r', type: :boolean, desc: 'Reverse the order of the sort.'
105
+ desc "timeline [USER/]LIST", "Show tweet timeline for members of the specified list."
106
+ method_option "csv", aliases: "-c", type: :boolean, desc: "Output in CSV format."
107
+ method_option "decode_uris", aliases: "-d", type: :boolean, desc: "Decodes t.co URLs into their original form."
108
+ method_option "id", aliases: "-i", type: :boolean, desc: "Specify user via ID instead of screen name."
109
+ method_option "long", aliases: "-l", type: :boolean, desc: "Output in long format."
110
+ method_option "number", aliases: "-n", type: :numeric, default: DEFAULT_NUM_RESULTS, desc: "Limit the number of results."
111
+ method_option "relative_dates", aliases: "-a", type: :boolean, desc: "Show relative dates."
112
+ method_option "reverse", aliases: "-r", type: :boolean, desc: "Reverse the order of the sort."
113
113
  def timeline(user_list)
114
114
  owner, list_name = extract_owner(user_list, options)
115
- count = options['number'] || DEFAULT_NUM_RESULTS
115
+ count = options["number"] || DEFAULT_NUM_RESULTS
116
116
  opts = {}
117
- opts[:include_entities] = !!options['decode_uris']
117
+ opts[:include_entities] = !!options["decode_uris"]
118
118
  tweets = collect_with_count(count) do |count_opts|
119
119
  client.list_timeline(owner, list_name, count_opts.merge(opts))
120
120
  end
121
121
  print_tweets(tweets)
122
122
  end
123
- map %w(tl) => :timeline
123
+ map %w[tl] => :timeline
124
124
  end
125
125
  end