t 1.7.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/README.md +21 -8
- data/lib/t.rb +1 -1
- data/lib/t/cli.rb +62 -73
- data/lib/t/collectable.rb +2 -10
- data/lib/t/core_ext/kernel.rb +4 -4
- data/lib/t/delete.rb +4 -4
- data/lib/t/editor.rb +35 -0
- data/lib/t/list.rb +3 -6
- data/lib/t/printable.rb +7 -13
- data/lib/t/requestable.rb +6 -21
- data/lib/t/search.rb +16 -17
- data/lib/t/set.rb +4 -4
- data/lib/t/stream.rb +15 -27
- data/lib/t/utils.rb +10 -10
- data/lib/t/version.rb +3 -3
- data/spec/cli_spec.rb +223 -109
- data/spec/delete_spec.rb +26 -26
- data/spec/editor_spec.rb +102 -0
- data/spec/fixtures/bearer_token.json +1 -0
- data/spec/fixtures/status.json +1 -1
- data/spec/fixtures/status_no_attributes.json +1 -1
- data/spec/fixtures/status_no_country.json +1 -1
- data/spec/fixtures/status_no_full_name.json +1 -1
- data/spec/fixtures/status_no_locality.json +1 -1
- data/spec/fixtures/status_no_place.json +1 -1
- data/spec/fixtures/status_no_street_address.json +1 -1
- data/spec/helper.rb +6 -2
- data/spec/list_spec.rb +3 -3
- data/spec/rcfile_spec.rb +20 -6
- data/spec/search_spec.rb +19 -19
- data/spec/set_spec.rb +4 -4
- data/spec/stream_spec.rb +77 -101
- data/t.gemspec +4 -5
- metadata +11 -57
- metadata.gz.sig +0 -0
- data/spec/fixtures/activity_summary.json +0 -1
data/lib/t/collectable.rb
CHANGED
@@ -6,16 +6,8 @@ module T
|
|
6
6
|
|
7
7
|
MAX_NUM_RESULTS = 200
|
8
8
|
|
9
|
-
def collect_with_cursor(collection=[], cursor=-1, &block)
|
10
|
-
object = retryable(:tries => 3, :on => Twitter::Error::ServerError, :sleep => 0) do
|
11
|
-
yield(cursor)
|
12
|
-
end
|
13
|
-
collection += object.collection
|
14
|
-
object.last? ? collection.flatten : collect_with_cursor(collection, object.next_cursor, &block)
|
15
|
-
end
|
16
|
-
|
17
9
|
def collect_with_max_id(collection=[], max_id=nil, &block)
|
18
|
-
tweets = retryable(:tries => 3, :on => Twitter::Error
|
10
|
+
tweets = retryable(:tries => 3, :on => Twitter::Error, :sleep => 0) do
|
19
11
|
yield(max_id)
|
20
12
|
end
|
21
13
|
return collection if tweets.nil?
|
@@ -38,7 +30,7 @@ module T
|
|
38
30
|
end
|
39
31
|
|
40
32
|
def collect_with_page(collection=[], page=1, &block)
|
41
|
-
tweets = retryable(:tries => 3, :on => Twitter::Error
|
33
|
+
tweets = retryable(:tries => 3, :on => Twitter::Error, :sleep => 0) do
|
42
34
|
yield page
|
43
35
|
end
|
44
36
|
return collection if tweets.nil?
|
data/lib/t/core_ext/kernel.rb
CHANGED
data/lib/t/delete.rb
CHANGED
@@ -60,14 +60,14 @@ module T
|
|
60
60
|
if options['force']
|
61
61
|
tweets = client.unfavorite(status_ids)
|
62
62
|
tweets.each do |status|
|
63
|
-
say "@#{@rcfile.active_profile[0]} unfavorited @#{status.
|
63
|
+
say "@#{@rcfile.active_profile[0]} unfavorited @#{status.user.screen_name}'s status: \"#{status.full_text}\""
|
64
64
|
end
|
65
65
|
else
|
66
66
|
status_ids.each do |status_id|
|
67
67
|
status = client.status(status_id, :include_my_retweet => false)
|
68
|
-
return unless yes? "Are you sure you want to remove @#{status.
|
68
|
+
return unless yes? "Are you sure you want to remove @#{status.user.screen_name}'s status: \"#{status.full_text}\" from your favorites? [y/N]"
|
69
69
|
client.unfavorite(status_id)
|
70
|
-
say "@#{@rcfile.active_profile[0]} unfavorited @#{status.
|
70
|
+
say "@#{@rcfile.active_profile[0]} unfavorited @#{status.user.screen_name}'s status: \"#{status.full_text}\""
|
71
71
|
end
|
72
72
|
end
|
73
73
|
end
|
@@ -103,7 +103,7 @@ module T
|
|
103
103
|
else
|
104
104
|
status_ids.each do |status_id|
|
105
105
|
status = client.status(status_id, :include_my_retweet => false)
|
106
|
-
return unless yes? "Are you sure you want to permanently delete @#{status.
|
106
|
+
return unless yes? "Are you sure you want to permanently delete @#{status.user.screen_name}'s status: \"#{status.full_text}\"? [y/N]"
|
107
107
|
client.status_destroy(status_id, :trim_user => true)
|
108
108
|
say "@#{@rcfile.active_profile[0]} deleted the Tweet: \"#{status.full_text}\""
|
109
109
|
end
|
data/lib/t/editor.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
require 'shellwords'
|
3
|
+
|
4
|
+
module T
|
5
|
+
class Editor
|
6
|
+
class << self
|
7
|
+
|
8
|
+
def gets
|
9
|
+
file = tempfile
|
10
|
+
edit(file.path)
|
11
|
+
File.read(file).strip
|
12
|
+
ensure
|
13
|
+
file.close
|
14
|
+
file.unlink
|
15
|
+
end
|
16
|
+
|
17
|
+
def tempfile
|
18
|
+
Tempfile.new("TWEET_EDITMSG")
|
19
|
+
end
|
20
|
+
|
21
|
+
def edit(path)
|
22
|
+
system(Shellwords.join([editor, path]))
|
23
|
+
end
|
24
|
+
|
25
|
+
def editor
|
26
|
+
ENV['VISUAL'] || ENV['EDITOR'] || system_editor
|
27
|
+
end
|
28
|
+
|
29
|
+
def system_editor
|
30
|
+
RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ ? 'notepad' : 'vi'
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/t/list.rb
CHANGED
@@ -56,9 +56,8 @@ module T
|
|
56
56
|
list = client.list(owner, list)
|
57
57
|
if options['csv']
|
58
58
|
require 'csv'
|
59
|
-
require 'fastercsv' unless Array.new.respond_to?(:to_csv)
|
60
59
|
say ["ID", "Description", "Slug", "Screen name", "Created at", "Members", "Subscribers", "Following", "Mode", "URL"].to_csv
|
61
|
-
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,
|
60
|
+
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
|
62
61
|
else
|
63
62
|
array = []
|
64
63
|
array << ["ID", list.id.to_s]
|
@@ -70,7 +69,7 @@ module T
|
|
70
69
|
array << ["Subscribers", number_with_delimiter(list.subscriber_count)]
|
71
70
|
array << ["Status", list.following ? "Following" : "Not following"]
|
72
71
|
array << ["Mode", list.mode]
|
73
|
-
array << ["URL",
|
72
|
+
array << ["URL", list.uri]
|
74
73
|
print_table(array)
|
75
74
|
end
|
76
75
|
end
|
@@ -85,9 +84,7 @@ module T
|
|
85
84
|
method_option "unsorted", :aliases => "-u", :type => :boolean, :default => false, :desc => "Output is not sorted."
|
86
85
|
def members(list)
|
87
86
|
owner, list = extract_owner(list, options)
|
88
|
-
users =
|
89
|
-
client.list_members(owner, list, :cursor => cursor)
|
90
|
-
end
|
87
|
+
users = client.list_members(owner, list).to_a
|
91
88
|
print_users(users)
|
92
89
|
end
|
93
90
|
|
data/lib/t/printable.rb
CHANGED
@@ -12,16 +12,16 @@ module T
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def build_long_tweet(tweet)
|
15
|
-
[tweet.id, ls_formatted_time(tweet), "@#{tweet.
|
15
|
+
[tweet.id, ls_formatted_time(tweet), "@#{tweet.user.screen_name}", decode_full_text(tweet, options['decode_uris']).gsub(/\n+/, ' ')]
|
16
16
|
end
|
17
17
|
|
18
18
|
def build_long_user(user)
|
19
|
-
[user.id, ls_formatted_time(user), ls_formatted_time(user.status), user.statuses_count, user.
|
19
|
+
[user.id, ls_formatted_time(user), ls_formatted_time(user.status), user.statuses_count, user.favorites_count, user.listed_count, user.friends_count, user.followers_count, "@#{user.screen_name}", user.name, user.verified? ? "Yes" : "No", user.protected? ? "Yes" : "No", user.description.gsub(/\n+/, ' '), user.status ? decode_full_text(user.status, options['decode_uris']).gsub(/\n+/, ' ') : nil, user.location, user.website.to_s]
|
20
20
|
end
|
21
21
|
|
22
22
|
def csv_formatted_time(object, key=:created_at)
|
23
23
|
return nil if object.nil?
|
24
|
-
time = object.send(key.to_sym)
|
24
|
+
time = object.send(key.to_sym).dup
|
25
25
|
time.utc.strftime("%Y-%m-%d %H:%M:%S %z")
|
26
26
|
end
|
27
27
|
|
@@ -37,21 +37,18 @@ module T
|
|
37
37
|
|
38
38
|
def print_csv_list(list)
|
39
39
|
require 'csv'
|
40
|
-
require 'fastercsv' unless Array.new.respond_to?(:to_csv)
|
41
40
|
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
|
42
41
|
end
|
43
42
|
|
44
43
|
def print_csv_tweet(tweet)
|
45
44
|
require 'csv'
|
46
|
-
require 'fastercsv' unless Array.new.respond_to?(:to_csv)
|
47
45
|
require 'htmlentities'
|
48
|
-
say [tweet.id, csv_formatted_time(tweet), tweet.
|
46
|
+
say [tweet.id, csv_formatted_time(tweet), tweet.user.screen_name, decode_full_text(tweet)].to_csv
|
49
47
|
end
|
50
48
|
|
51
49
|
def print_csv_user(user)
|
52
50
|
require 'csv'
|
53
|
-
|
54
|
-
say [user.id, csv_formatted_time(user), csv_formatted_time(user.status), user.statuses_count, user.favourites_count, user.listed_count, user.friends_count, user.followers_count, user.screen_name, user.name, user.verified?, user.protected?, user.description, user.status ? user.status.full_text : nil, user.location, user.url].to_csv
|
51
|
+
say [user.id, csv_formatted_time(user), csv_formatted_time(user.status), user.statuses_count, user.favorites_count, user.listed_count, user.friends_count, user.followers_count, user.screen_name, user.name, user.verified?, user.protected?, user.description, user.status ? user.status.full_text : nil, user.location, user.website].to_csv
|
55
52
|
end
|
56
53
|
|
57
54
|
def print_lists(lists)
|
@@ -70,7 +67,6 @@ module T
|
|
70
67
|
lists.reverse! if options['reverse']
|
71
68
|
if options['csv']
|
72
69
|
require 'csv'
|
73
|
-
require 'fastercsv' unless Array.new.respond_to?(:to_csv)
|
74
70
|
say LIST_HEADINGS.to_csv unless lists.empty?
|
75
71
|
lists.each do |list|
|
76
72
|
print_csv_list(list)
|
@@ -128,7 +124,6 @@ module T
|
|
128
124
|
tweets.reverse! if options['reverse']
|
129
125
|
if options['csv']
|
130
126
|
require 'csv'
|
131
|
-
require 'fastercsv' unless Array.new.respond_to?(:to_csv)
|
132
127
|
say TWEET_HEADINGS.to_csv unless tweets.empty?
|
133
128
|
tweets.each do |tweet|
|
134
129
|
print_csv_tweet(tweet)
|
@@ -141,7 +136,7 @@ module T
|
|
141
136
|
print_table_with_headings(array, TWEET_HEADINGS, format)
|
142
137
|
else
|
143
138
|
tweets.each do |tweet|
|
144
|
-
print_message(tweet.user.screen_name,
|
139
|
+
print_message(tweet.user.screen_name, decode_uris(tweet.full_text, options['decode_uris'] ? tweet.uris : nil))
|
145
140
|
end
|
146
141
|
end
|
147
142
|
end
|
@@ -149,7 +144,7 @@ module T
|
|
149
144
|
def print_users(users)
|
150
145
|
users = case options['sort']
|
151
146
|
when 'favorites'
|
152
|
-
users.sort_by{|user| user.
|
147
|
+
users.sort_by{|user| user.favorites_count.to_i}
|
153
148
|
when 'followers'
|
154
149
|
users.sort_by{|user| user.followers_count.to_i}
|
155
150
|
when 'friends'
|
@@ -168,7 +163,6 @@ module T
|
|
168
163
|
users.reverse! if options['reverse']
|
169
164
|
if options['csv']
|
170
165
|
require 'csv'
|
171
|
-
require 'fastercsv' unless Array.new.respond_to?(:to_csv)
|
172
166
|
say USER_HEADINGS.to_csv unless users.empty?
|
173
167
|
users.each do |user|
|
174
168
|
print_csv_user(user)
|
data/lib/t/requestable.rb
CHANGED
@@ -2,33 +2,18 @@ require 'twitter'
|
|
2
2
|
|
3
3
|
module T
|
4
4
|
module Requestable
|
5
|
-
DEFAULT_HOST = 'api.twitter.com'
|
6
|
-
DEFAULT_PROTOCOL = 'https'
|
7
5
|
|
8
6
|
private
|
9
7
|
|
10
|
-
def base_url
|
11
|
-
"#{protocol}://#{host}"
|
12
|
-
end
|
13
|
-
|
14
8
|
def client
|
15
9
|
return @client if @client
|
16
10
|
@rcfile.path = options['profile'] if options['profile']
|
17
|
-
@client = Twitter::Client.new
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
)
|
24
|
-
end
|
25
|
-
|
26
|
-
def host
|
27
|
-
options['host'] || DEFAULT_HOST
|
28
|
-
end
|
29
|
-
|
30
|
-
def protocol
|
31
|
-
options['no-ssl'] ? 'http' : DEFAULT_PROTOCOL
|
11
|
+
@client = Twitter::REST::Client.new do |config|
|
12
|
+
config.consumer_key = @rcfile.active_consumer_key
|
13
|
+
config.consumer_secret = @rcfile.active_consumer_secret
|
14
|
+
config.access_token = @rcfile.active_token
|
15
|
+
config.access_token_secret = @rcfile.active_secret
|
16
|
+
end
|
32
17
|
end
|
33
18
|
|
34
19
|
end
|
data/lib/t/search.rb
CHANGED
@@ -26,33 +26,32 @@ module T
|
|
26
26
|
desc "all QUERY", "Returns the #{DEFAULT_NUM_RESULTS} most recent Tweets that match the specified query."
|
27
27
|
method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format."
|
28
28
|
method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format."
|
29
|
-
method_option "
|
29
|
+
method_option "decode_uris", :aliases => "-d", :type => :boolean, :default => false, :desc => "Decodes t.co URLs into their original form."
|
30
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|
|
34
|
-
count_opts[:include_entities] = 1 if options['
|
35
|
-
client.search(query, count_opts).
|
34
|
+
count_opts[:include_entities] = 1 if options['decode_uris']
|
35
|
+
client.search(query, count_opts).to_a
|
36
36
|
end
|
37
37
|
tweets.reverse! if options['reverse']
|
38
38
|
require 'htmlentities'
|
39
39
|
if options['csv']
|
40
40
|
require 'csv'
|
41
|
-
require 'fastercsv' unless Array.new.respond_to?(:to_csv)
|
42
41
|
say TWEET_HEADINGS.to_csv unless tweets.empty?
|
43
42
|
tweets.each do |tweet|
|
44
|
-
say [tweet.id, csv_formatted_time(tweet), tweet.
|
43
|
+
say [tweet.id, csv_formatted_time(tweet), tweet.user.screen_name, decode_full_text(tweet)].to_csv
|
45
44
|
end
|
46
45
|
elsif options['long']
|
47
46
|
array = tweets.map do |tweet|
|
48
|
-
[tweet.id, ls_formatted_time(tweet), "@#{tweet.
|
47
|
+
[tweet.id, ls_formatted_time(tweet), "@#{tweet.user.screen_name}", decode_full_text(tweet, options['decode_uris']).gsub(/\n+/, ' ')]
|
49
48
|
end
|
50
49
|
format = options['format'] || TWEET_HEADINGS.size.times.map{"%s"}
|
51
50
|
print_table_with_headings(array, TWEET_HEADINGS, format)
|
52
51
|
else
|
53
52
|
say unless tweets.empty?
|
54
53
|
tweets.each do |tweet|
|
55
|
-
print_message(tweet.
|
54
|
+
print_message(tweet.user.screen_name, decode_full_text(tweet, options['decode_uris']))
|
56
55
|
end
|
57
56
|
end
|
58
57
|
end
|
@@ -60,13 +59,13 @@ module T
|
|
60
59
|
desc "favorites [USER] QUERY", "Returns Tweets you've favorited that match the specified query."
|
61
60
|
method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format."
|
62
61
|
method_option "id", :aliases => "-i", :type => :boolean, :default => false, :desc => "Specify user via ID instead of screen name."
|
63
|
-
method_option "
|
62
|
+
method_option "decode_uris", :aliases => "-d", :type => :boolean, :default => false, :desc => "Decodes t.co URLs into their original form."
|
64
63
|
method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format."
|
65
64
|
def favorites(*args)
|
66
65
|
opts = {:count => MAX_NUM_RESULTS}
|
67
66
|
query = args.pop
|
68
67
|
user = args.pop
|
69
|
-
opts[:include_entities] = 1 if options['
|
68
|
+
opts[:include_entities] = 1 if options['decode_uris']
|
70
69
|
if user
|
71
70
|
require 't/core_ext/string'
|
72
71
|
user = if options['id']
|
@@ -95,11 +94,11 @@ module T
|
|
95
94
|
method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format."
|
96
95
|
method_option "id", :aliases => "-i", :type => :boolean, :default => false, :desc => "Specify user via ID instead of screen name."
|
97
96
|
method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format."
|
98
|
-
method_option "
|
97
|
+
method_option "decode_uris", :aliases => "-d", :type => :boolean, :default => false, :desc => "Decodes t.co URLs into their original form."
|
99
98
|
def list(list, query)
|
100
99
|
owner, list = extract_owner(list, options)
|
101
100
|
opts = {:count => MAX_NUM_RESULTS}
|
102
|
-
opts[:include_entities] = 1 if options['
|
101
|
+
opts[:include_entities] = 1 if options['decode_uris']
|
103
102
|
tweets = collect_with_max_id do |max_id|
|
104
103
|
opts[:max_id] = max_id unless max_id.nil?
|
105
104
|
client.list_timeline(owner, list, opts)
|
@@ -113,10 +112,10 @@ module T
|
|
113
112
|
desc "mentions QUERY", "Returns Tweets mentioning you that match the specified query."
|
114
113
|
method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format."
|
115
114
|
method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format."
|
116
|
-
method_option "
|
115
|
+
method_option "decode_uris", :aliases => "-d", :type => :boolean, :default => false, :desc => "Decodes t.co URLs into their original form."
|
117
116
|
def mentions(query)
|
118
117
|
opts = {:count => MAX_NUM_RESULTS}
|
119
|
-
opts[:include_entities] = 1 if options['
|
118
|
+
opts[:include_entities] = 1 if options['decode_uris']
|
120
119
|
tweets = collect_with_max_id do |max_id|
|
121
120
|
opts[:max_id] = max_id unless max_id.nil?
|
122
121
|
client.mentions(opts)
|
@@ -132,12 +131,12 @@ module T
|
|
132
131
|
method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format."
|
133
132
|
method_option "id", :aliases => "-i", :type => :boolean, :default => false, :desc => "Specify user via ID instead of screen name."
|
134
133
|
method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format."
|
135
|
-
method_option "
|
134
|
+
method_option "decode_uris", :aliases => "-d", :type => :boolean, :default => false, :desc => "Decodes t.co URLs into their original form."
|
136
135
|
def retweets(*args)
|
137
136
|
opts = {:count => MAX_NUM_RESULTS}
|
138
137
|
query = args.pop
|
139
138
|
user = args.pop
|
140
|
-
opts[:include_entities] = 1 if options['
|
139
|
+
opts[:include_entities] = 1 if options['decode_uris']
|
141
140
|
if user
|
142
141
|
require 't/core_ext/string'
|
143
142
|
user = if options['id']
|
@@ -164,7 +163,7 @@ module T
|
|
164
163
|
|
165
164
|
desc "timeline [USER] QUERY", "Returns Tweets in your timeline that match the specified query."
|
166
165
|
method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format."
|
167
|
-
method_option "
|
166
|
+
method_option "decode_uris", :aliases => "-d", :type => :boolean, :default => false, :desc => "Decodes t.co URLs into their original form."
|
168
167
|
method_option "exclude", :aliases => "-e", :type => :string, :enum => %w(replies retweets), :desc => "Exclude certain types of Tweets from the results.", :banner => "TYPE"
|
169
168
|
method_option "id", :aliases => "-i", :type => :boolean, :default => false, :desc => "Specify user via ID instead of screen name."
|
170
169
|
method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format."
|
@@ -174,7 +173,7 @@ module T
|
|
174
173
|
query = args.pop
|
175
174
|
user = args.pop
|
176
175
|
opts = {:count => MAX_NUM_RESULTS}
|
177
|
-
opts[:include_entities] = 1 if options['
|
176
|
+
opts[:include_entities] = 1 if options['decode_uris']
|
178
177
|
opts[:exclude_replies] = true if options['exclude'] == 'replies'
|
179
178
|
opts[:include_rts] = false if options['exclude'] == 'retweets'
|
180
179
|
opts[:max_id] = options['max_id'] if options['max_id']
|
data/lib/t/set.rb
CHANGED
@@ -63,10 +63,10 @@ module T
|
|
63
63
|
end
|
64
64
|
map %w(avatar image) => :profile_image
|
65
65
|
|
66
|
-
desc "
|
67
|
-
def
|
68
|
-
client.update_profile(:url =>
|
69
|
-
say "@#{@rcfile.active_profile[0]}'s
|
66
|
+
desc "website URI", "Sets the website field on your profile."
|
67
|
+
def website(uri)
|
68
|
+
client.update_profile(:url => uri)
|
69
|
+
say "@#{@rcfile.active_profile[0]}'s website has been updated."
|
70
70
|
end
|
71
71
|
|
72
72
|
end
|
data/lib/t/stream.rb
CHANGED
@@ -25,11 +25,9 @@ module T
|
|
25
25
|
method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format."
|
26
26
|
method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format."
|
27
27
|
def all
|
28
|
-
|
29
|
-
client.on_inited do
|
28
|
+
client.before_request do
|
30
29
|
if options['csv']
|
31
30
|
require 'csv'
|
32
|
-
require 'fastercsv' unless Array.new.respond_to?(:to_csv)
|
33
31
|
say TWEET_HEADINGS.to_csv
|
34
32
|
elsif options['long'] && STDOUT.tty?
|
35
33
|
headings = TWEET_HEADINGS.size.times.map do |index|
|
@@ -38,7 +36,7 @@ module T
|
|
38
36
|
print_table([headings])
|
39
37
|
end
|
40
38
|
end
|
41
|
-
client.
|
39
|
+
client.sample do |tweet|
|
42
40
|
if options['csv']
|
43
41
|
print_csv_tweet(tweet)
|
44
42
|
elsif options['long']
|
@@ -50,16 +48,13 @@ module T
|
|
50
48
|
print_message(tweet.user.screen_name, tweet.text)
|
51
49
|
end
|
52
50
|
end
|
53
|
-
client.sample
|
54
51
|
end
|
55
52
|
|
56
53
|
desc "matrix", "Unfortunately, no one can be told what the Matrix is. You have to see it for yourself."
|
57
54
|
def matrix
|
58
|
-
|
59
|
-
client.on_timeline_status do |tweet|
|
55
|
+
client.sample do |tweet|
|
60
56
|
say(tweet.full_text.gsub("\n", ''), [:bold, :green, :on_black])
|
61
57
|
end
|
62
|
-
client.sample
|
63
58
|
end
|
64
59
|
|
65
60
|
desc "search KEYWORD [KEYWORD...]", "Stream Tweets that contain specified keywords, joined with logical ORs (Control-C to stop)"
|
@@ -67,16 +62,15 @@ module T
|
|
67
62
|
method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format."
|
68
63
|
def search(keyword, *keywords)
|
69
64
|
keywords.unshift(keyword)
|
70
|
-
require 'tweetstream'
|
71
65
|
require 't/search'
|
72
|
-
client.
|
66
|
+
client.before_request do
|
73
67
|
search = T::Search.new
|
74
68
|
search.options = search.options.merge(options)
|
75
69
|
search.options = search.options.merge(:reverse => true)
|
76
70
|
search.options = search.options.merge(:format => TWEET_HEADINGS_FORMATTING)
|
77
71
|
search.all(keywords.join(' OR '))
|
78
72
|
end
|
79
|
-
client.
|
73
|
+
client.filter(:track => keywords) do |tweet|
|
80
74
|
if options['csv']
|
81
75
|
print_csv_tweet(tweet)
|
82
76
|
elsif options['long']
|
@@ -88,23 +82,21 @@ module T
|
|
88
82
|
print_message(tweet.user.screen_name, tweet.text)
|
89
83
|
end
|
90
84
|
end
|
91
|
-
client.track(keywords)
|
92
85
|
end
|
93
86
|
|
94
87
|
desc "timeline", "Stream your timeline (Control-C to stop)"
|
95
88
|
method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format."
|
96
89
|
method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format."
|
97
90
|
def timeline
|
98
|
-
require 'tweetstream'
|
99
91
|
require 't/cli'
|
100
|
-
client.
|
92
|
+
client.before_request do
|
101
93
|
cli = T::CLI.new
|
102
94
|
cli.options = cli.options.merge(options)
|
103
95
|
cli.options = cli.options.merge(:reverse => true)
|
104
96
|
cli.options = cli.options.merge(:format => TWEET_HEADINGS_FORMATTING)
|
105
97
|
cli.timeline
|
106
98
|
end
|
107
|
-
client.
|
99
|
+
client.user do |tweet|
|
108
100
|
if options['csv']
|
109
101
|
print_csv_tweet(tweet)
|
110
102
|
elsif options['long']
|
@@ -116,7 +108,6 @@ module T
|
|
116
108
|
print_message(tweet.user.screen_name, tweet.text)
|
117
109
|
end
|
118
110
|
end
|
119
|
-
client.userstream
|
120
111
|
end
|
121
112
|
|
122
113
|
desc "users USER_ID [USER_ID...]", "Stream Tweets either from or in reply to specified users (Control-C to stop)"
|
@@ -125,11 +116,9 @@ module T
|
|
125
116
|
def users(user_id, *user_ids)
|
126
117
|
user_ids.unshift(user_id)
|
127
118
|
user_ids.map!(&:to_i)
|
128
|
-
|
129
|
-
client.on_inited do
|
119
|
+
client.before_request do
|
130
120
|
if options['csv']
|
131
121
|
require 'csv'
|
132
|
-
require 'fastercsv' unless Array.new.respond_to?(:to_csv)
|
133
122
|
say TWEET_HEADINGS.to_csv
|
134
123
|
elsif options['long'] && STDOUT.tty?
|
135
124
|
headings = TWEET_HEADINGS.size.times.map do |index|
|
@@ -138,7 +127,7 @@ module T
|
|
138
127
|
print_table([headings])
|
139
128
|
end
|
140
129
|
end
|
141
|
-
client.
|
130
|
+
client.follow(user_ids) do |tweet|
|
142
131
|
if options['csv']
|
143
132
|
print_csv_tweet(tweet)
|
144
133
|
elsif options['long']
|
@@ -150,7 +139,6 @@ module T
|
|
150
139
|
print_message(tweet.user.screen_name, tweet.text)
|
151
140
|
end
|
152
141
|
end
|
153
|
-
client.follow(user_ids)
|
154
142
|
end
|
155
143
|
|
156
144
|
private
|
@@ -158,12 +146,12 @@ module T
|
|
158
146
|
def client
|
159
147
|
return @client if @client
|
160
148
|
@rcfile.path = options['profile'] if options['profile']
|
161
|
-
@client =
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
149
|
+
@client = Twitter::Streaming::Client.new do |config|
|
150
|
+
config.consumer_key = @rcfile.active_consumer_key
|
151
|
+
config.consumer_secret = @rcfile.active_consumer_secret
|
152
|
+
config.access_token = @rcfile.active_token
|
153
|
+
config.access_token_secret = @rcfile.active_secret
|
154
|
+
end
|
167
155
|
end
|
168
156
|
|
169
157
|
end
|