t 2.0.1 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/t/rcfile.rb CHANGED
@@ -7,7 +7,7 @@ module T
7
7
  FILE_NAME = '.trc'
8
8
 
9
9
  def initialize
10
- @path = File.join(File.expand_path("~"), FILE_NAME)
10
+ @path = File.join(File.expand_path('~'), FILE_NAME)
11
11
  @data = load_file
12
12
  end
13
13
 
@@ -20,7 +20,7 @@ module T
20
20
  if possibilities.size == 1
21
21
  possibilities.first
22
22
  else
23
- raise ArgumentError, "Username #{username} is #{possibilities.size < 1 ? 'not found.' : 'ambiguous, matching ' + possibilities.join(', ')}"
23
+ fail ArgumentError, "Username #{username} is #{possibilities.size < 1 ? 'not found.' : 'ambiguous, matching ' + possibilities.join(', ')}"
24
24
  end
25
25
  end
26
26
 
@@ -93,7 +93,7 @@ module T
93
93
  end
94
94
 
95
95
  def reset
96
- self.send(:initialize)
96
+ send(:initialize)
97
97
  end
98
98
 
99
99
  private
@@ -108,10 +108,9 @@ module T
108
108
 
109
109
  def write
110
110
  require 'yaml'
111
- File.open(@path, File::RDWR|File::TRUNC|File::CREAT, 0600) do |rcfile|
111
+ File.open(@path, File::RDWR | File::TRUNC | File::CREAT, 0600) do |rcfile|
112
112
  rcfile.write @data.to_yaml
113
113
  end
114
114
  end
115
-
116
115
  end
117
116
  end
data/lib/t/requestable.rb CHANGED
@@ -2,8 +2,7 @@ require 'twitter'
2
2
 
3
3
  module T
4
4
  module Requestable
5
-
6
- private
5
+ private
7
6
 
8
7
  def client
9
8
  return @client if @client
@@ -15,6 +14,5 @@ module T
15
14
  config.access_token_secret = @rcfile.active_secret
16
15
  end
17
16
  end
18
-
19
17
  end
20
18
  end
data/lib/t/search.rb CHANGED
@@ -23,11 +23,11 @@ module T
23
23
  super
24
24
  end
25
25
 
26
- desc "all QUERY", "Returns the #{DEFAULT_NUM_RESULTS} most recent Tweets that match the specified query."
27
- method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format."
28
- method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format."
29
- method_option "decode_uris", :aliases => "-d", :type => :boolean, :default => false, :desc => "Decodes t.co URLs into their original form."
30
- method_option "number", :aliases => "-n", :type => :numeric, :default => DEFAULT_NUM_RESULTS
26
+ desc 'all QUERY', "Returns the #{DEFAULT_NUM_RESULTS} most recent Tweets that match the specified query."
27
+ method_option 'csv', :aliases => '-c', :type => :boolean, :default => false, :desc => 'Output in CSV format.'
28
+ method_option 'long', :aliases => '-l', :type => :boolean, :default => false, :desc => 'Output in long format.'
29
+ method_option 'decode_uris', :aliases => '-d', :type => :boolean, :default => false, :desc => 'Decodes t.co URLs into their original form.'
30
+ method_option 'number', :aliases => '-n', :type => :numeric, :default => DEFAULT_NUM_RESULTS
31
31
  def all(query)
32
32
  count = options['number'] || DEFAULT_NUM_RESULTS
33
33
  tweets = collect_with_count(count) do |count_opts|
@@ -46,7 +46,7 @@ module T
46
46
  array = tweets.map do |tweet|
47
47
  [tweet.id, ls_formatted_time(tweet), "@#{tweet.user.screen_name}", decode_full_text(tweet, options['decode_uris']).gsub(/\n+/, ' ')]
48
48
  end
49
- format = options['format'] || TWEET_HEADINGS.size.times.map{"%s"}
49
+ format = options['format'] || TWEET_HEADINGS.size.times.map { '%s' }
50
50
  print_table_with_headings(array, TWEET_HEADINGS, format)
51
51
  else
52
52
  say unless tweets.empty?
@@ -56,11 +56,11 @@ module T
56
56
  end
57
57
  end
58
58
 
59
- desc "favorites [USER] QUERY", "Returns Tweets you've favorited that match the specified query."
60
- method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format."
61
- method_option "id", :aliases => "-i", :type => :boolean, :default => false, :desc => "Specify user via ID instead of screen name."
62
- method_option "decode_uris", :aliases => "-d", :type => :boolean, :default => false, :desc => "Decodes t.co URLs into their original form."
63
- method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format."
59
+ desc 'favorites [USER] QUERY', "Returns Tweets you've favorited that match the specified query."
60
+ method_option 'csv', :aliases => '-c', :type => :boolean, :default => false, :desc => 'Output in CSV format.'
61
+ method_option 'id', :aliases => '-i', :type => :boolean, :default => false, :desc => 'Specify user via ID instead of screen name.'
62
+ method_option 'decode_uris', :aliases => '-d', :type => :boolean, :default => false, :desc => 'Decodes t.co URLs into their original form.'
63
+ method_option 'long', :aliases => '-l', :type => :boolean, :default => false, :desc => 'Output in long format.'
64
64
  def favorites(*args)
65
65
  opts = {:count => MAX_NUM_RESULTS}
66
66
  query = args.pop
@@ -68,11 +68,7 @@ module T
68
68
  opts[:include_entities] = 1 if options['decode_uris']
69
69
  if user
70
70
  require 't/core_ext/string'
71
- user = if options['id']
72
- user.to_i
73
- else
74
- user.strip_ats
75
- end
71
+ user = options['id'] ? user.to_i : user.strip_ats
76
72
  tweets = collect_with_max_id do |max_id|
77
73
  opts[:max_id] = max_id unless max_id.nil?
78
74
  client.favorites(user, opts)
@@ -90,11 +86,11 @@ module T
90
86
  end
91
87
  map %w(faves) => :favorites
92
88
 
93
- desc "list [USER/]LIST QUERY", "Returns Tweets on a list that match specified query."
94
- method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format."
95
- method_option "id", :aliases => "-i", :type => :boolean, :default => false, :desc => "Specify user via ID instead of screen name."
96
- method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format."
97
- method_option "decode_uris", :aliases => "-d", :type => :boolean, :default => false, :desc => "Decodes t.co URLs into their original form."
89
+ desc 'list [USER/]LIST QUERY', 'Returns Tweets on a list that match the specified query.'
90
+ method_option 'csv', :aliases => '-c', :type => :boolean, :default => false, :desc => 'Output in CSV format.'
91
+ method_option 'id', :aliases => '-i', :type => :boolean, :default => false, :desc => 'Specify user via ID instead of screen name.'
92
+ method_option 'long', :aliases => '-l', :type => :boolean, :default => false, :desc => 'Output in long format.'
93
+ method_option 'decode_uris', :aliases => '-d', :type => :boolean, :default => false, :desc => 'Decodes t.co URLs into their original form.'
98
94
  def list(list, query)
99
95
  owner, list = extract_owner(list, options)
100
96
  opts = {:count => MAX_NUM_RESULTS}
@@ -109,10 +105,10 @@ module T
109
105
  print_tweets(tweets)
110
106
  end
111
107
 
112
- desc "mentions QUERY", "Returns Tweets mentioning you that match the specified query."
113
- method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format."
114
- method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format."
115
- method_option "decode_uris", :aliases => "-d", :type => :boolean, :default => false, :desc => "Decodes t.co URLs into their original form."
108
+ desc 'mentions QUERY', 'Returns Tweets mentioning you that match the specified query.'
109
+ method_option 'csv', :aliases => '-c', :type => :boolean, :default => false, :desc => 'Output in CSV format.'
110
+ method_option 'long', :aliases => '-l', :type => :boolean, :default => false, :desc => 'Output in long format.'
111
+ method_option 'decode_uris', :aliases => '-d', :type => :boolean, :default => false, :desc => 'Decodes t.co URLs into their original form.'
116
112
  def mentions(query)
117
113
  opts = {:count => MAX_NUM_RESULTS}
118
114
  opts[:include_entities] = 1 if options['decode_uris']
@@ -127,11 +123,11 @@ module T
127
123
  end
128
124
  map %w(replies) => :mentions
129
125
 
130
- desc "retweets [USER] QUERY", "Returns Tweets you've retweeted that match the specified query."
131
- method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format."
132
- method_option "id", :aliases => "-i", :type => :boolean, :default => false, :desc => "Specify user via ID instead of screen name."
133
- method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format."
134
- method_option "decode_uris", :aliases => "-d", :type => :boolean, :default => false, :desc => "Decodes t.co URLs into their original form."
126
+ desc 'retweets [USER] QUERY', "Returns Tweets you've retweeted that match the specified query."
127
+ method_option 'csv', :aliases => '-c', :type => :boolean, :default => false, :desc => 'Output in CSV format.'
128
+ method_option 'id', :aliases => '-i', :type => :boolean, :default => false, :desc => 'Specify user via ID instead of screen name.'
129
+ method_option 'long', :aliases => '-l', :type => :boolean, :default => false, :desc => 'Output in long format.'
130
+ method_option 'decode_uris', :aliases => '-d', :type => :boolean, :default => false, :desc => 'Decodes t.co URLs into their original form.'
135
131
  def retweets(*args)
136
132
  opts = {:count => MAX_NUM_RESULTS}
137
133
  query = args.pop
@@ -139,11 +135,7 @@ module T
139
135
  opts[:include_entities] = 1 if options['decode_uris']
140
136
  if user
141
137
  require 't/core_ext/string'
142
- user = if options['id']
143
- user.to_i
144
- else
145
- user.strip_ats
146
- end
138
+ user = options['id'] ? user.to_i : user.strip_ats
147
139
  tweets = collect_with_max_id do |max_id|
148
140
  opts[:max_id] = max_id unless max_id.nil?
149
141
  client.retweeted_by_user(user, opts)
@@ -161,14 +153,14 @@ module T
161
153
  end
162
154
  map %w(rts) => :retweets
163
155
 
164
- desc "timeline [USER] QUERY", "Returns Tweets in your timeline that match the specified query."
165
- method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format."
166
- method_option "decode_uris", :aliases => "-d", :type => :boolean, :default => false, :desc => "Decodes t.co URLs into their original form."
167
- method_option "exclude", :aliases => "-e", :type => :string, :enum => %w(replies retweets), :desc => "Exclude certain types of Tweets from the results.", :banner => "TYPE"
168
- method_option "id", :aliases => "-i", :type => :boolean, :default => false, :desc => "Specify user via ID instead of screen name."
169
- method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format."
170
- method_option "max_id", :aliases => "-m", :type => :numeric, :desc => "Returns only the results with an ID less than the specified ID."
171
- method_option "since_id", :aliases => "-s", :type => :numeric, :desc => "Returns only the results with an ID greater than the specified ID."
156
+ desc 'timeline [USER] QUERY', 'Returns Tweets in your timeline that match the specified query.'
157
+ method_option 'csv', :aliases => '-c', :type => :boolean, :default => false, :desc => 'Output in CSV format.'
158
+ method_option 'decode_uris', :aliases => '-d', :type => :boolean, :default => false, :desc => 'Decodes t.co URLs into their original form.'
159
+ method_option 'exclude', :aliases => '-e', :type => :string, :enum => %w(replies retweets), :desc => 'Exclude certain types of Tweets from the results.', :banner => 'TYPE'
160
+ method_option 'id', :aliases => '-i', :type => :boolean, :default => false, :desc => 'Specify user via ID instead of screen name.'
161
+ method_option 'long', :aliases => '-l', :type => :boolean, :default => false, :desc => 'Output in long format.'
162
+ method_option 'max_id', :aliases => '-m', :type => :numeric, :desc => 'Returns only the results with an ID less than the specified ID.'
163
+ method_option 'since_id', :aliases => '-s', :type => :numeric, :desc => 'Returns only the results with an ID greater than the specified ID.'
172
164
  def timeline(*args)
173
165
  query = args.pop
174
166
  user = args.pop
@@ -180,11 +172,7 @@ module T
180
172
  opts[:since_id] = options['since_id'] if options['since_id']
181
173
  if user
182
174
  require 't/core_ext/string'
183
- user = if options['id']
184
- user.to_i
185
- else
186
- user.strip_ats
187
- end
175
+ user = options['id'] ? user.to_i : user.strip_ats
188
176
  tweets = collect_with_max_id do |max_id|
189
177
  opts[:max_id] = max_id unless max_id.nil?
190
178
  client.user_timeline(user, opts)
@@ -202,18 +190,17 @@ module T
202
190
  end
203
191
  map %w(tl) => :timeline
204
192
 
205
- desc "users QUERY", "Returns users that match the specified query."
206
- method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format."
207
- method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format."
208
- method_option "reverse", :aliases => "-r", :type => :boolean, :default => false, :desc => "Reverse the order of the sort."
209
- 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"
210
- method_option "unsorted", :aliases => "-u", :type => :boolean, :default => false, :desc => "Output is not sorted."
193
+ desc 'users QUERY', 'Returns users that match the specified query.'
194
+ method_option 'csv', :aliases => '-c', :type => :boolean, :default => false, :desc => 'Output in CSV format.'
195
+ method_option 'long', :aliases => '-l', :type => :boolean, :default => false, :desc => 'Output in long format.'
196
+ method_option 'reverse', :aliases => '-r', :type => :boolean, :default => false, :desc => 'Reverse the order of the sort.'
197
+ 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'
198
+ method_option 'unsorted', :aliases => '-u', :type => :boolean, :default => false, :desc => 'Output is not sorted.'
211
199
  def users(query)
212
200
  users = collect_with_page do |page|
213
201
  client.user_search(query, :page => page)
214
202
  end
215
203
  print_users(users)
216
204
  end
217
-
218
205
  end
219
206
  end
data/lib/t/set.rb CHANGED
@@ -13,61 +13,60 @@ module T
13
13
  super
14
14
  end
15
15
 
16
- desc "active SCREEN_NAME [CONSUMER_KEY]", "Set your active account."
17
- def active(screen_name, consumer_key=nil)
16
+ desc 'active SCREEN_NAME [CONSUMER_KEY]', 'Set your active account.'
17
+ def active(screen_name, consumer_key = nil)
18
18
  require 't/core_ext/string'
19
19
  screen_name = screen_name.strip_ats
20
20
  @rcfile.path = options['profile'] if options['profile']
21
21
  consumer_key = @rcfile[screen_name].keys.last if consumer_key.nil?
22
- @rcfile.active_profile = {'username' => @rcfile[screen_name][consumer_key]["username"], 'consumer_key' => consumer_key}
22
+ @rcfile.active_profile = {'username' => @rcfile[screen_name][consumer_key]['username'], 'consumer_key' => consumer_key}
23
23
  say "Active account has been updated to #{@rcfile.active_profile[0]}."
24
24
  end
25
25
  map %w(default) => :active
26
26
 
27
- desc "bio DESCRIPTION", "Edits your Bio information on your Twitter profile."
27
+ desc 'bio DESCRIPTION', 'Edits your Bio information on your Twitter profile.'
28
28
  def bio(description)
29
29
  client.update_profile(:description => description)
30
30
  say "@#{@rcfile.active_profile[0]}'s bio has been updated."
31
31
  end
32
32
 
33
- desc "language LANGUAGE_NAME", "Selects the language you'd like to receive notifications in."
33
+ desc 'language LANGUAGE_NAME', "Selects the language you'd like to receive notifications in."
34
34
  def language(language_name)
35
35
  client.settings(:lang => language_name)
36
36
  say "@#{@rcfile.active_profile[0]}'s language has been updated."
37
37
  end
38
38
 
39
- desc "location PLACE_NAME", "Updates the location field in your profile."
39
+ desc 'location PLACE_NAME', 'Updates the location field in your profile.'
40
40
  def location(place_name)
41
41
  client.update_profile(:location => place_name)
42
42
  say "@#{@rcfile.active_profile[0]}'s location has been updated."
43
43
  end
44
44
 
45
- desc "name NAME", "Sets the name field on your Twitter profile."
45
+ desc 'name NAME', 'Sets the name field on your Twitter profile.'
46
46
  def name(name)
47
47
  client.update_profile(:name => name)
48
48
  say "@#{@rcfile.active_profile[0]}'s name has been updated."
49
49
  end
50
50
 
51
- desc "profile_background_image FILE", "Sets the background image on your Twitter profile."
52
- method_option "tile", :aliases => "-t", :type => :boolean, :default => false, :desc => "Whether or not to tile the background image."
51
+ desc 'profile_background_image FILE', 'Sets the background image on your Twitter profile.'
52
+ method_option 'tile', :aliases => '-t', :type => :boolean, :default => false, :desc => 'Whether or not to tile the background image.'
53
53
  def profile_background_image(file)
54
54
  client.update_profile_background_image(File.new(File.expand_path(file)), :tile => options['tile'], :skip_status => true)
55
55
  say "@#{@rcfile.active_profile[0]}'s background image has been updated."
56
56
  end
57
57
  map %w(background background_image) => :profile_background_image
58
58
 
59
- desc "profile_image FILE", "Sets the image on your Twitter profile."
59
+ desc 'profile_image FILE', 'Sets the image on your Twitter profile.'
60
60
  def profile_image(file)
61
61
  client.update_profile_image(File.new(File.expand_path(file)))
62
62
  say "@#{@rcfile.active_profile[0]}'s image has been updated."
63
63
  end
64
64
  map %w(avatar image) => :profile_image
65
65
 
66
- desc "website URI", "Sets the website field on your profile."
66
+ desc 'website URI', 'Sets the website field on your profile.'
67
67
  def website(uri)
68
68
  client.update_profile(:url => uri)
69
69
  say "@#{@rcfile.active_profile[0]}'s website has been updated."
70
70
  end
71
-
72
71
  end
73
72
  end
data/lib/t/stream.rb CHANGED
@@ -8,10 +8,10 @@ module T
8
8
  include T::Utils
9
9
 
10
10
  TWEET_HEADINGS_FORMATTING = [
11
- "%-18s", # Add padding to maximum length of a Tweet ID
12
- "%-12s", # Add padding to length of a timestamp formatted with ls_formatted_time
13
- "%-20s", # Add padding to maximum length of a Twitter screen name
14
- "%s", # Last element does not need special formatting
11
+ '%-18s', # Add padding to maximum length of a Tweet ID
12
+ '%-12s', # Add padding to length of a timestamp formatted with ls_formatted_time
13
+ '%-20s', # Add padding to maximum length of a Twitter screen name
14
+ '%s', # Last element does not need special formatting
15
15
  ]
16
16
 
17
17
  check_unknown_options!
@@ -21,9 +21,9 @@ module T
21
21
  super
22
22
  end
23
23
 
24
- desc "all", "Stream a random sample of all Tweets (Control-C to stop)"
25
- method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format."
26
- method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format."
24
+ desc 'all', 'Stream a random sample of all Tweets (Control-C to stop)'
25
+ method_option 'csv', :aliases => '-c', :type => :boolean, :default => false, :desc => 'Output in CSV format.'
26
+ method_option 'long', :aliases => '-l', :type => :boolean, :default => false, :desc => 'Output in long format.'
27
27
  def all
28
28
  client.before_request do
29
29
  if options['csv']
@@ -37,6 +37,7 @@ module T
37
37
  end
38
38
  end
39
39
  client.sample do |tweet|
40
+ next unless tweet.is_a?(Twitter::Tweet)
40
41
  if options['csv']
41
42
  print_csv_tweet(tweet)
42
43
  elsif options['long']
@@ -50,16 +51,17 @@ module T
50
51
  end
51
52
  end
52
53
 
53
- desc "matrix", "Unfortunately, no one can be told what the Matrix is. You have to see it for yourself."
54
+ desc 'matrix', 'Unfortunately, no one can be told what the Matrix is. You have to see it for yourself.'
54
55
  def matrix
55
- client.sample do |tweet|
56
- say(tweet.full_text.gsub("\n", ''), [:bold, :green, :on_black])
56
+ client.sample(:language => 'ja') do |tweet|
57
+ next unless tweet.is_a?(Twitter::Tweet)
58
+ say(tweet.full_text.gsub("\n", '').reverse, [:bold, :green, :on_black])
57
59
  end
58
60
  end
59
61
 
60
- desc "search KEYWORD [KEYWORD...]", "Stream Tweets that contain specified keywords, joined with logical ORs (Control-C to stop)"
61
- method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format."
62
- method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format."
62
+ desc 'search KEYWORD [KEYWORD...]', 'Stream Tweets that contain specified keywords, joined with logical ORs (Control-C to stop)'
63
+ method_option 'csv', :aliases => '-c', :type => :boolean, :default => false, :desc => 'Output in CSV format.'
64
+ method_option 'long', :aliases => '-l', :type => :boolean, :default => false, :desc => 'Output in long format.'
63
65
  def search(keyword, *keywords)
64
66
  keywords.unshift(keyword)
65
67
  require 't/search'
@@ -71,6 +73,7 @@ module T
71
73
  search.all(keywords.join(' OR '))
72
74
  end
73
75
  client.filter(:track => keywords) do |tweet|
76
+ next unless tweet.is_a?(Twitter::Tweet)
74
77
  if options['csv']
75
78
  print_csv_tweet(tweet)
76
79
  elsif options['long']
@@ -84,9 +87,9 @@ module T
84
87
  end
85
88
  end
86
89
 
87
- desc "timeline", "Stream your timeline (Control-C to stop)"
88
- method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format."
89
- method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format."
90
+ desc 'timeline', 'Stream your timeline (Control-C to stop)'
91
+ method_option 'csv', :aliases => '-c', :type => :boolean, :default => false, :desc => 'Output in CSV format.'
92
+ method_option 'long', :aliases => '-l', :type => :boolean, :default => false, :desc => 'Output in long format.'
90
93
  def timeline
91
94
  require 't/cli'
92
95
  client.before_request do
@@ -97,6 +100,7 @@ module T
97
100
  cli.timeline
98
101
  end
99
102
  client.user do |tweet|
103
+ next unless tweet.is_a?(Twitter::Tweet)
100
104
  if options['csv']
101
105
  print_csv_tweet(tweet)
102
106
  elsif options['long']
@@ -110,9 +114,9 @@ module T
110
114
  end
111
115
  end
112
116
 
113
- desc "users USER_ID [USER_ID...]", "Stream Tweets either from or in reply to specified users (Control-C to stop)"
114
- method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format."
115
- method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format."
117
+ desc 'users USER_ID [USER_ID...]', 'Stream Tweets either from or in reply to specified users (Control-C to stop)'
118
+ method_option 'csv', :aliases => '-c', :type => :boolean, :default => false, :desc => 'Output in CSV format.'
119
+ method_option 'long', :aliases => '-l', :type => :boolean, :default => false, :desc => 'Output in long format.'
116
120
  def users(user_id, *user_ids)
117
121
  user_ids.unshift(user_id)
118
122
  user_ids.map!(&:to_i)
@@ -128,6 +132,7 @@ module T
128
132
  end
129
133
  end
130
134
  client.follow(user_ids) do |tweet|
135
+ next unless tweet.is_a?(Twitter::Tweet)
131
136
  if options['csv']
132
137
  print_csv_tweet(tweet)
133
138
  elsif options['long']
@@ -153,6 +158,5 @@ module T
153
158
  config.access_token_secret = @rcfile.active_secret
154
159
  end
155
160
  end
156
-
157
161
  end
158
162
  end
data/lib/t/utils.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  module T
2
2
  module Utils
3
- private
3
+ private
4
4
 
5
5
  # https://github.com/rails/rails/blob/bd8a970/actionpack/lib/action_view/helpers/date_helper.rb
6
- def distance_of_time_in_words(from_time, to_time=Time.now)
6
+ def distance_of_time_in_words(from_time, to_time = Time.now) # rubocop:disable CyclomaticComplexity
7
7
  seconds = (to_time - from_time).abs
8
8
  minutes = seconds / 60
9
9
  case minutes
@@ -14,38 +14,38 @@ module T
14
14
  when 1...2
15
15
  'a second'
16
16
  when 2...60
17
- '%d seconds' % seconds
17
+ format('%d seconds', seconds)
18
18
  end
19
19
  when 1...2
20
20
  'a minute'
21
21
  when 2...60
22
- '%d minutes' % minutes
22
+ format('%d minutes', minutes)
23
23
  when 60...120
24
24
  'an hour'
25
25
  # 120 minutes up to 23.5 hours
26
26
  when 120...1410
27
- '%d hours' % (minutes.to_f / 60.0).round
27
+ format('%d hours', (minutes.to_f / 60.0).round)
28
28
  # 23.5 hours up to 48 hours
29
29
  when 1410...2880
30
30
  'a day'
31
31
  # 48 hours up to 29.5 days
32
- when 2880...42480
33
- '%d days' % (minutes.to_f / 1440.0).round
32
+ when 2880...42_480
33
+ format('%d days', (minutes.to_f / 1440.0).round)
34
34
  # 29.5 days up to 60 days
35
- when 42480...86400
35
+ when 42_480...86_400
36
36
  'a month'
37
37
  # 60 days up to 11.5 months
38
- when 86400...503700
39
- '%d months' % (minutes.to_f / 43800.0).round
38
+ when 86_400...503_700
39
+ format('%d months', (minutes.to_f / 43_800.0).round)
40
40
  # 11.5 months up to 2 years
41
- when 503700...1051200
41
+ when 503_700...1_051_200
42
42
  'a year'
43
43
  else
44
- '%d years' % (minutes.to_f / 525600.0).round
44
+ format('%d years', (minutes.to_f / 525_600.0).round)
45
45
  end
46
46
  end
47
- alias :time_ago_in_words :distance_of_time_in_words
48
- alias :time_from_now_in_words :distance_of_time_in_words
47
+ alias_method :time_ago_in_words, :distance_of_time_in_words
48
+ alias_method :time_from_now_in_words, :distance_of_time_in_words
49
49
 
50
50
  def fetch_users(users, options, &block)
51
51
  format_users!(users, options)
@@ -58,11 +58,7 @@ module T
58
58
 
59
59
  def format_users!(users, options)
60
60
  require 't/core_ext/string'
61
- if options['id']
62
- users.map!(&:to_i)
63
- else
64
- users.map!(&:strip_ats)
65
- end
61
+ options['id'] ? users.map!(&:to_i) : users.map!(&:strip_ats)
66
62
  end
67
63
 
68
64
  def extract_owner(list, options)
@@ -72,11 +68,7 @@ module T
72
68
  owner = @rcfile.active_profile[0]
73
69
  else
74
70
  require 't/core_ext/string'
75
- owner = if options['id']
76
- owner.to_i
77
- else
78
- owner.strip_ats
79
- end
71
+ owner = options['id'] ? owner.to_i : owner.strip_ats
80
72
  end
81
73
  [owner, list]
82
74
  end
@@ -85,14 +77,14 @@ module T
85
77
  html.gsub(/<.+?>/, '')
86
78
  end
87
79
 
88
- def number_with_delimiter(number, delimiter=",")
80
+ def number_with_delimiter(number, delimiter = ',')
89
81
  digits = number.to_s.split(//)
90
- groups = digits.reverse.each_slice(3).map{|g| g.join('')}
82
+ groups = digits.reverse.each_slice(3).map { |g| g.join('') }
91
83
  groups.join(delimiter).reverse
92
84
  end
93
85
 
94
- def pluralize(count, singular, plural=nil)
95
- "#{count || 0} " + ((count == 1 || count =~ /^1(\.0+)?$/) ? singular : (plural || "#{singular}s"))
86
+ def pluralize(count, singular, plural = nil)
87
+ "#{count || 0} " + (count == 1 || count =~ /^1(\.0+)?$/ ? singular : (plural || "#{singular}s"))
96
88
  end
97
89
 
98
90
  def decode_full_text(tweet, decode_full_uris = false)