t 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -44,7 +44,7 @@ Once you've verified that Ruby is installed:
44
44
 
45
45
  ## Configuration
46
46
 
47
- Twitter requires OAuth for most of its functionality, so you'll need a
47
+ Twitter API v1.1 requires OAuth for all of its functionality, so you'll need a
48
48
  registered Twitter application. If you've never registered a Twitter
49
49
  application before, it's easy! Just sign-in using your Twitter account and the
50
50
  fill out the short form at <http://dev.twitter.com/apps/new>. If you've
data/lib/t/cli.rb CHANGED
@@ -319,10 +319,10 @@ module T
319
319
  end
320
320
  end
321
321
  count = options['number'] || DEFAULT_NUM_RESULTS
322
- statuses = collect_with_count(count) do |opts|
322
+ tweets = collect_with_count(count) do |opts|
323
323
  client.favorites(user, opts)
324
324
  end
325
- print_statuses(statuses)
325
+ print_tweets(tweets)
326
326
  end
327
327
  map %w(faves favourites) => :favorites
328
328
 
@@ -491,10 +491,10 @@ module T
491
491
  method_option "reverse", :aliases => "-r", :type => :boolean, :default => false, :desc => "Reverse the order of the sort."
492
492
  def mentions
493
493
  count = options['number'] || DEFAULT_NUM_RESULTS
494
- statuses = collect_with_count(count) do |opts|
494
+ tweets = collect_with_count(count) do |opts|
495
495
  client.mentions(opts)
496
496
  end
497
- print_statuses(statuses)
497
+ print_tweets(tweets)
498
498
  end
499
499
  map %w(replies) => :mentions
500
500
 
@@ -516,25 +516,6 @@ module T
516
516
  end
517
517
  end
518
518
 
519
- desc "rate_limit", "Returns information related to Twitter API rate limiting."
520
- method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format."
521
- def rate_limit
522
- rate_limit_status = client.rate_limit_status
523
- if options['csv']
524
- require 'csv'
525
- require 'fastercsv' unless Array.new.respond_to?(:to_csv)
526
- say ["Hourly limit", "Remaining hits", "Reset time"].to_csv
527
- say [rate_limit_status.hourly_limit, rate_limit_status.remaining_hits, csv_formatted_time(rate_limit_status, :reset_time)].to_csv
528
- else
529
- array = []
530
- array << ["Hourly limit", number_with_delimiter(rate_limit_status.hourly_limit)]
531
- array << ["Remaining hits", number_with_delimiter(rate_limit_status.remaining_hits)]
532
- array << ["Reset time", "#{ls_formatted_time(rate_limit_status, :reset_time)} (#{time_from_now_in_words(rate_limit_status.reset_time)} from now)"]
533
- print_table(array)
534
- end
535
- end
536
- map %w(ratelimit rl) => :rate_limit
537
-
538
519
  desc "reply STATUS_ID MESSAGE", "Post your Tweet as a reply directed at another person."
539
520
  method_option "all", :aliases => "-a", :type => "boolean", :default => false, :desc => "Reply to all users mentioned in the Tweet."
540
521
  method_option "location", :aliases => "-l", :type => :boolean, :default => false
@@ -588,7 +569,7 @@ module T
588
569
  method_option "reverse", :aliases => "-r", :type => :boolean, :default => false, :desc => "Reverse the order of the sort."
589
570
  def retweets(user=nil)
590
571
  count = options['number'] || DEFAULT_NUM_RESULTS
591
- statuses = if user
572
+ tweets = if user
592
573
  require 't/core_ext/string'
593
574
  user = if options['id']
594
575
  user.to_i
@@ -603,7 +584,7 @@ module T
603
584
  client.retweeted_by_me(opts)
604
585
  end
605
586
  end
606
- print_statuses(statuses)
587
+ print_tweets(tweets)
607
588
  end
608
589
  map %w(rts) => :retweets
609
590
 
@@ -654,28 +635,6 @@ module T
654
635
  end
655
636
  end
656
637
 
657
- desc "suggest [USER]", "Returns a listing of Twitter users' accounts you might enjoy following."
658
- method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format."
659
- method_option "id", :aliases => "-i", :type => "boolean", :default => false, :desc => "Specify user via ID instead of screen name."
660
- method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format."
661
- method_option "number", :aliases => "-n", :type => :numeric, :default => DEFAULT_NUM_RESULTS, :desc => "Limit the number of results."
662
- method_option "reverse", :aliases => "-r", :type => :boolean, :default => false, :desc => "Reverse the order of the sort."
663
- 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"
664
- method_option "unsorted", :aliases => "-u", :type => :boolean, :default => false, :desc => "Output is not sorted."
665
- def suggest(user=nil)
666
- if user
667
- require 't/core_ext/string'
668
- user = if options['id']
669
- user.to_i
670
- else
671
- user.strip_ats
672
- end
673
- end
674
- limit = options['number'] || DEFAULT_NUM_RESULTS
675
- users = client.recommendations(user, :limit => limit)
676
- print_users(users)
677
- end
678
-
679
638
  desc "timeline [USER]", "Returns the #{DEFAULT_NUM_RESULTS} most recent Tweets posted by a user."
680
639
  method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format."
681
640
  method_option "id", :aliases => "-i", :type => "boolean", :default => false, :desc => "Specify user via ID instead of screen name."
@@ -691,15 +650,15 @@ module T
691
650
  else
692
651
  user.strip_ats
693
652
  end
694
- statuses = collect_with_count(count) do |opts|
653
+ tweets = collect_with_count(count) do |opts|
695
654
  client.user_timeline(user, opts)
696
655
  end
697
656
  else
698
- statuses = collect_with_count(count) do |opts|
657
+ tweets = collect_with_count(count) do |opts|
699
658
  client.home_timeline(opts)
700
659
  end
701
660
  end
702
- print_statuses(statuses)
661
+ print_tweets(tweets)
703
662
  end
704
663
  map %w(tl) => :timeline
705
664
 
@@ -716,10 +675,22 @@ module T
716
675
  method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format."
717
676
  method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format."
718
677
  method_option "reverse", :aliases => "-r", :type => :boolean, :default => false, :desc => "Reverse the order of the sort."
678
+ method_option "sort", :aliases => "-s", :type => :string, :enum => %w(country name parent type woeid), :default => "name", :desc => "Specify the order of the results.", :banner => "ORDER"
719
679
  method_option "unsorted", :aliases => "-u", :type => :boolean, :default => false, :desc => "Output is not sorted."
720
680
  def trend_locations
721
681
  places = client.trend_locations
722
- places = places.sort_by{|places| places.name.downcase} unless options['unsorted']
682
+ places = case options['sort']
683
+ when 'country'
684
+ places.sort_by{|places| places.country.downcase}
685
+ when 'parent'
686
+ places.sort_by{|places| places.parent_id.to_i}
687
+ when 'type'
688
+ places.sort_by{|places| places.place_type.downcase}
689
+ when 'woeid'
690
+ places.sort_by{|places| places.woeid.to_i}
691
+ else
692
+ places.sort_by{|places| places.name.downcase}
693
+ end unless options['unsorted']
723
694
  places.reverse! if options['reverse']
724
695
  if options['csv']
725
696
  require 'csv'
data/lib/t/collectable.rb CHANGED
@@ -12,19 +12,19 @@ module T
12
12
 
13
13
  def collect_with_cursor(collection=[], cursor=-1, &block)
14
14
  object = retryable(:tries => 3, :on => Twitter::Error::ServerError, :sleep => 0) do
15
- yield cursor
15
+ yield(cursor)
16
16
  end
17
17
  collection += object.collection
18
18
  object.last? ? collection.flatten : collect_with_cursor(collection, object.next_cursor, &block)
19
19
  end
20
20
 
21
21
  def collect_with_max_id(collection=[], max_id=nil, &block)
22
- array = retryable(:tries => 3, :on => Twitter::Error::ServerError, :sleep => 0) do
23
- yield max_id
22
+ tweets = retryable(:tries => 3, :on => Twitter::Error::ServerError, :sleep => 0) do
23
+ yield(max_id)
24
24
  end
25
- return collection if array.nil?
26
- collection += array
27
- array.empty? ? collection.flatten : collect_with_max_id(collection, array.last.id - 1, &block)
25
+ return collection if tweets.nil?
26
+ collection += tweets
27
+ tweets.empty? ? collection.flatten : collect_with_max_id(collection, tweets.last.id - 1, &block)
28
28
  end
29
29
 
30
30
  def collect_with_number(number, key, &block)
@@ -34,9 +34,9 @@ module T
34
34
  opts[:max_id] = max_id unless max_id.nil?
35
35
  opts[key] = number unless number >= MAX_NUM_RESULTS
36
36
  if number > 0
37
- statuses = yield opts
38
- number -= statuses.length
39
- statuses
37
+ tweets = yield opts
38
+ number -= tweets.length
39
+ tweets
40
40
  end
41
41
  end.flatten.compact
42
42
  end
@@ -50,12 +50,12 @@ module T
50
50
  end
51
51
 
52
52
  def collect_with_page(collection=[], page=1, &block)
53
- array = retryable(:tries => 3, :on => Twitter::Error::ServerError, :sleep => 0) do
53
+ tweets = retryable(:tries => 3, :on => Twitter::Error::ServerError, :sleep => 0) do
54
54
  yield page
55
55
  end
56
- return collection if array.nil?
57
- collection += array
58
- array.empty? ? collection.flatten.uniq : collect_with_page(collection, page + 1, &block)
56
+ return collection if tweets.nil?
57
+ collection += tweets
58
+ tweets.empty? ? collection.flatten.uniq : collect_with_page(collection, page + 1, &block)
59
59
  end
60
60
 
61
61
  end
data/lib/t/delete.rb CHANGED
@@ -58,8 +58,8 @@ module T
58
58
  require 't/core_ext/string'
59
59
  status_ids.map!(&:to_i)
60
60
  if options['force']
61
- statuses = client.unfavorite(status_ids)
62
- statuses.each do |status|
61
+ tweets = client.unfavorite(status_ids)
62
+ tweets.each do |status|
63
63
  say "@#{@rcfile.active_profile[0]} unfavorited @#{status.from_user}'s status: \"#{status.full_text}\""
64
64
  end
65
65
  else
@@ -96,16 +96,16 @@ module T
96
96
  require 't/core_ext/string'
97
97
  status_ids.map!(&:to_i)
98
98
  if options['force']
99
- statuses = client.status_destroy(status_ids, :trim_user => true)
100
- statuses.each do |status|
101
- say "@#{@rcfile.active_profile[0]} deleted the status: \"#{status.full_text}\""
99
+ tweets = client.status_destroy(status_ids, :trim_user => true)
100
+ tweets.each do |status|
101
+ say "@#{@rcfile.active_profile[0]} deleted the Tweet: \"#{status.full_text}\""
102
102
  end
103
103
  else
104
104
  status_ids.each do |status_id|
105
105
  status = client.status(status_id, :include_my_retweet => false, :trim_user => true)
106
106
  return unless yes? "Are you sure you want to permanently delete @#{status.from_user}'s status: \"#{status.full_text}\"? [y/N]"
107
107
  client.status_destroy(status_id, :trim_user => true)
108
- say "@#{@rcfile.active_profile[0]} deleted the status: \"#{status.full_text}\""
108
+ say "@#{@rcfile.active_profile[0]} deleted the Tweet: \"#{status.full_text}\""
109
109
  end
110
110
  end
111
111
  end
data/lib/t/list.rb CHANGED
@@ -116,10 +116,10 @@ module T
116
116
  def timeline(list)
117
117
  owner, list = extract_owner(list, options)
118
118
  per_page = options['number'] || DEFAULT_NUM_RESULTS
119
- statuses = collect_with_per_page(per_page) do |opts|
119
+ tweets = collect_with_per_page(per_page) do |opts|
120
120
  client.list_timeline(owner, list, opts)
121
121
  end
122
- print_statuses(statuses)
122
+ print_tweets(tweets)
123
123
  end
124
124
  map %w(tl) => :timeline
125
125
 
data/lib/t/printable.rb CHANGED
@@ -11,9 +11,9 @@ module T
11
11
  [list.id, ls_formatted_time(list), "@#{list.user.screen_name}", list.slug, list.member_count, list.subscriber_count, list.mode, list.description]
12
12
  end
13
13
 
14
- def build_long_status(status)
14
+ def build_long_tweet(tweet)
15
15
  require 'htmlentities'
16
- [status.id, ls_formatted_time(status), "@#{status.from_user}", HTMLEntities.new.decode(status.full_text).gsub(/\n+/, ' ')]
16
+ [tweet.id, ls_formatted_time(tweet), "@#{tweet.from_user}", HTMLEntities.new.decode(tweet.full_text).gsub(/\n+/, ' ')]
17
17
  end
18
18
 
19
19
  def build_long_user(user)
@@ -42,11 +42,11 @@ module T
42
42
  say [list.id, csv_formatted_time(list), list.user.screen_name, list.slug, list.member_count, list.subscriber_count, list.mode, list.description].to_csv
43
43
  end
44
44
 
45
- def print_csv_status(status)
45
+ def print_csv_tweet(tweet)
46
46
  require 'csv'
47
47
  require 'fastercsv' unless Array.new.respond_to?(:to_csv)
48
48
  require 'htmlentities'
49
- say [status.id, csv_formatted_time(status), status.from_user, HTMLEntities.new.decode(status.full_text)].to_csv
49
+ say [tweet.id, csv_formatted_time(tweet), tweet.from_user, HTMLEntities.new.decode(tweet.full_text)].to_csv
50
50
  end
51
51
 
52
52
  def print_csv_user(user)
@@ -124,24 +124,24 @@ module T
124
124
  say
125
125
  end
126
126
 
127
- def print_statuses(statuses)
128
- statuses.reverse! if options['reverse']
127
+ def print_tweets(tweets)
128
+ tweets.reverse! if options['reverse']
129
129
  if options['csv']
130
130
  require 'csv'
131
131
  require 'fastercsv' unless Array.new.respond_to?(:to_csv)
132
- say STATUS_HEADINGS.to_csv unless statuses.empty?
133
- statuses.each do |status|
134
- print_csv_status(status)
132
+ say STATUS_HEADINGS.to_csv unless tweets.empty?
133
+ tweets.each do |tweet|
134
+ print_csv_tweet(tweet)
135
135
  end
136
136
  elsif options['long']
137
- array = statuses.map do |status|
138
- build_long_status(status)
137
+ array = tweets.map do |tweet|
138
+ build_long_tweet(tweet)
139
139
  end
140
140
  format = options['format'] || STATUS_HEADINGS.size.times.map{"%s"}
141
141
  print_table_with_headings(array, STATUS_HEADINGS, format)
142
142
  else
143
- statuses.each do |status|
144
- print_message(status.user.screen_name, status.full_text)
143
+ tweets.each do |tweet|
144
+ print_message(tweet.user.screen_name, tweet.full_text)
145
145
  end
146
146
  end
147
147
  end
@@ -149,17 +149,17 @@ module T
149
149
  def print_users(users)
150
150
  users = case options['sort']
151
151
  when 'favorites'
152
- users.sort_by{|user| user.favourites_count}
152
+ users.sort_by{|user| user.favourites_count.to_i}
153
153
  when 'followers'
154
- users.sort_by{|user| user.followers_count}
154
+ users.sort_by{|user| user.followers_count.to_i}
155
155
  when 'friends'
156
- users.sort_by{|user| user.friends_count}
156
+ users.sort_by{|user| user.friends_count.to_i}
157
157
  when 'listed'
158
- users.sort_by{|user| user.listed_count}
158
+ users.sort_by{|user| user.listed_count.to_i}
159
159
  when 'since'
160
160
  users.sort_by{|user| user.created_at}
161
161
  when 'tweets'
162
- users.sort_by{|user| user.statuses_count}
162
+ users.sort_by{|user| user.statuses_count.to_i}
163
163
  when 'tweeted'
164
164
  users.sort_by{|user| user.status.created_at rescue Time.at(0)}
165
165
  else
data/lib/t/search.rb CHANGED
@@ -29,28 +29,28 @@ module T
29
29
  method_option "number", :aliases => "-n", :type => :numeric, :default => DEFAULT_NUM_RESULTS
30
30
  def all(query)
31
31
  rpp = options['number'] || DEFAULT_NUM_RESULTS
32
- statuses = collect_with_rpp(rpp) do |opts|
32
+ tweets = collect_with_rpp(rpp) do |opts|
33
33
  client.search(query, opts).results
34
34
  end
35
- statuses.reverse! if options['reverse']
35
+ tweets.reverse! if options['reverse']
36
36
  require 'htmlentities'
37
37
  if options['csv']
38
38
  require 'csv'
39
39
  require 'fastercsv' unless Array.new.respond_to?(:to_csv)
40
- say STATUS_HEADINGS.to_csv unless statuses.empty?
41
- statuses.each do |status|
42
- say [status.id, csv_formatted_time(status), status.from_user, HTMLEntities.new.decode(status.full_text)].to_csv
40
+ say STATUS_HEADINGS.to_csv unless tweets.empty?
41
+ tweets.each do |tweet|
42
+ say [tweet.id, csv_formatted_time(tweet), tweet.from_user, HTMLEntities.new.decode(tweet.full_text)].to_csv
43
43
  end
44
44
  elsif options['long']
45
- array = statuses.map do |status|
46
- [status.id, ls_formatted_time(status), "@#{status.from_user}", HTMLEntities.new.decode(status.full_text).gsub(/\n+/, ' ')]
45
+ array = tweets.map do |tweet|
46
+ [tweet.id, ls_formatted_time(tweet), "@#{tweet.from_user}", HTMLEntities.new.decode(tweet.full_text).gsub(/\n+/, ' ')]
47
47
  end
48
48
  format = options['format'] || STATUS_HEADINGS.size.times.map{"%s"}
49
49
  print_table_with_headings(array, STATUS_HEADINGS, format)
50
50
  else
51
- say unless statuses.empty?
52
- statuses.each do |status|
53
- print_message(status.from_user, status.full_text)
51
+ say unless tweets.empty?
52
+ tweets.each do |tweet|
53
+ print_message(tweet.from_user, tweet.full_text)
54
54
  end
55
55
  end
56
56
  end
@@ -70,20 +70,20 @@ module T
70
70
  else
71
71
  user.strip_ats
72
72
  end
73
- statuses = collect_with_max_id do |max_id|
73
+ tweets = collect_with_max_id do |max_id|
74
74
  opts[:max_id] = max_id unless max_id.nil?
75
75
  client.favorites(user, opts)
76
76
  end
77
77
  else
78
- statuses = collect_with_max_id do |max_id|
78
+ tweets = collect_with_max_id do |max_id|
79
79
  opts[:max_id] = max_id unless max_id.nil?
80
80
  client.favorites(opts)
81
81
  end
82
82
  end
83
- statuses = statuses.select do |status|
84
- /#{query}/i.match(status.full_text)
83
+ tweets = tweets.select do |tweet|
84
+ /#{query}/i.match(tweet.full_text)
85
85
  end
86
- print_statuses(statuses)
86
+ print_tweets(tweets)
87
87
  end
88
88
  map %w(faves) => :favorites
89
89
 
@@ -94,14 +94,14 @@ module T
94
94
  def list(list, query)
95
95
  owner, list = extract_owner(list, options)
96
96
  opts = {:count => MAX_NUM_RESULTS}
97
- statuses = collect_with_max_id do |max_id|
97
+ tweets = collect_with_max_id do |max_id|
98
98
  opts[:max_id] = max_id unless max_id.nil?
99
99
  client.list_timeline(owner, list, opts)
100
100
  end
101
- statuses = statuses.select do |status|
102
- /#{query}/i.match(status.full_text)
101
+ tweets = tweets.select do |tweet|
102
+ /#{query}/i.match(tweet.full_text)
103
103
  end
104
- print_statuses(statuses)
104
+ print_tweets(tweets)
105
105
  end
106
106
 
107
107
  desc "mentions QUERY", "Returns Tweets mentioning you that match the specified query."
@@ -109,14 +109,14 @@ module T
109
109
  method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format."
110
110
  def mentions(query)
111
111
  opts = {:count => MAX_NUM_RESULTS}
112
- statuses = collect_with_max_id do |max_id|
112
+ tweets = collect_with_max_id do |max_id|
113
113
  opts[:max_id] = max_id unless max_id.nil?
114
114
  client.mentions(opts)
115
115
  end
116
- statuses = statuses.select do |status|
117
- /#{query}/i.match(status.full_text)
116
+ tweets = tweets.select do |tweet|
117
+ /#{query}/i.match(tweet.full_text)
118
118
  end
119
- print_statuses(statuses)
119
+ print_tweets(tweets)
120
120
  end
121
121
  map %w(replies) => :mentions
122
122
 
@@ -135,20 +135,20 @@ module T
135
135
  else
136
136
  user.strip_ats
137
137
  end
138
- statuses = collect_with_max_id do |max_id|
138
+ tweets = collect_with_max_id do |max_id|
139
139
  opts[:max_id] = max_id unless max_id.nil?
140
140
  client.retweeted_by_user(user, opts)
141
141
  end
142
142
  else
143
- statuses = collect_with_max_id do |max_id|
143
+ tweets = collect_with_max_id do |max_id|
144
144
  opts[:max_id] = max_id unless max_id.nil?
145
145
  client.retweeted_by_me(opts)
146
146
  end
147
147
  end
148
- statuses = statuses.select do |status|
149
- /#{query}/i.match(status.full_text)
148
+ tweets = tweets.select do |tweet|
149
+ /#{query}/i.match(tweet.full_text)
150
150
  end
151
- print_statuses(statuses)
151
+ print_tweets(tweets)
152
152
  end
153
153
  map %w(rts) => :retweets
154
154
 
@@ -167,20 +167,20 @@ module T
167
167
  else
168
168
  user.strip_ats
169
169
  end
170
- statuses = collect_with_max_id do |max_id|
170
+ tweets = collect_with_max_id do |max_id|
171
171
  opts[:max_id] = max_id unless max_id.nil?
172
172
  client.user_timeline(user, opts)
173
173
  end
174
174
  else
175
- statuses = collect_with_max_id do |max_id|
175
+ tweets = collect_with_max_id do |max_id|
176
176
  opts[:max_id] = max_id unless max_id.nil?
177
177
  client.home_timeline(opts)
178
178
  end
179
179
  end
180
- statuses = statuses.select do |status|
181
- /#{query}/i.match(status.full_text)
180
+ tweets = tweets.select do |tweet|
181
+ /#{query}/i.match(tweet.full_text)
182
182
  end
183
- print_statuses(statuses)
183
+ print_tweets(tweets)
184
184
  end
185
185
  map %w(tl) => :timeline
186
186