Class: T::Stream
Constant Summary
collapse
[
'%-18s', '%-12s', '%-20s', '%s', ]
Constants included
from Printable
Printable::LIST_HEADINGS, Printable::MONTH_IN_SECONDS, Printable::TWEET_HEADINGS, Printable::USER_HEADINGS
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ Stream
Returns a new instance of Stream.
22
23
24
25
|
# File 'lib/t/stream.rb', line 22
def initialize(*)
@rcfile = T::RCFile.instance
super
end
|
Instance Method Details
#all ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/t/stream.rb', line 33
def all
streaming_client.before_request do
if options['csv']
require 'csv'
say TWEET_HEADINGS.to_csv
elsif options['long'] && STDOUT.tty?
headings = TWEET_HEADINGS.size.times.collect do |index|
TWEET_HEADINGS_FORMATTING[index] % TWEET_HEADINGS[index]
end
print_table([headings])
end
end
streaming_client.sample do ||
next unless .is_a?(Twitter::Tweet)
next if options['no-replies'] && .reply?
next if options['no-retweets'] && .
if options['csv']
()
elsif options['long']
array = ().each_with_index.collect do |element, index|
TWEET_HEADINGS_FORMATTING[index] % element
end
print_table([array], :truncate => STDOUT.tty?)
else
print_message(.user.screen_name, .text)
end
end
end
|
#list(user_list) ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
# File 'lib/t/stream.rb', line 70
def list(user_list)
owner, list_name = (user_list, options)
require 't/list'
streaming_client.before_request do
list = T::List.new
list.options = list.options.merge(options)
list.options = list.options.merge(:reverse => true)
list.options = list.options.merge(:format => TWEET_HEADINGS_FORMATTING)
list.timeline(user_list)
end
user_ids = client.list_members(owner, list_name).collect(&:id)
streaming_client.filter(:follow => user_ids.join(',')) do ||
next unless .is_a?(Twitter::Tweet)
next if options['no-replies'] && .reply?
next if options['no-retweets'] && .
if options['csv']
()
elsif options['long']
array = ().each_with_index.collect do |element, index|
TWEET_HEADINGS_FORMATTING[index] % element
end
print_table([array], :truncate => STDOUT.tty?)
else
print_message(.user.screen_name, .text)
end
end
end
|
#matrix ⇒ Object
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/t/stream.rb', line 100
def matrix
require 't/cli'
streaming_client.before_request do
cli = T::CLI.new
cli.matrix
end
streaming_client.sample(:language => 'ja') do ||
next unless .is_a?(Twitter::Tweet)
say(.text.gsub(/[^\u3000\u3040-\u309f]/, '').reverse, [:bold, :green, :on_black], false)
end
end
|
#search(keyword, *keywords) ⇒ Object
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
# File 'lib/t/stream.rb', line 118
def search(keyword, *keywords)
keywords.unshift(keyword)
require 't/search'
streaming_client.before_request do
search = T::Search.new
search.options = search.options.merge(options)
search.options = search.options.merge(:reverse => true)
search.options = search.options.merge(:format => TWEET_HEADINGS_FORMATTING)
search.all(keywords.join(' OR '))
end
streaming_client.filter(:track => keywords.join(',')) do ||
next unless .is_a?(Twitter::Tweet)
next if options['no-replies'] && .reply?
next if options['no-retweets'] && .
if options['csv']
()
elsif options['long']
array = ().each_with_index.collect do |element, index|
TWEET_HEADINGS_FORMATTING[index] % element
end
print_table([array], :truncate => STDOUT.tty?)
else
print_message(.user.screen_name, .text)
end
end
end
|
#timeline ⇒ Object
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
# File 'lib/t/stream.rb', line 151
def timeline
require 't/cli'
streaming_client.before_request do
cli = T::CLI.new
cli.options = cli.options.merge(options)
cli.options = cli.options.merge(:reverse => true)
cli.options = cli.options.merge(:format => TWEET_HEADINGS_FORMATTING)
cli.timeline
end
streaming_client.user do ||
next unless .is_a?(Twitter::Tweet)
next if options['no-replies'] && .reply?
next if options['no-retweets'] && .
if options['csv']
()
elsif options['long']
array = ().each_with_index.collect do |element, index|
TWEET_HEADINGS_FORMATTING[index] % element
end
print_table([array], :truncate => STDOUT.tty?)
else
print_message(.user.screen_name, .text)
end
end
end
|
#users(user_id, *user_ids) ⇒ Object
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
# File 'lib/t/stream.rb', line 183
def users(user_id, *user_ids)
user_ids.unshift(user_id)
user_ids.collect!(&:to_i)
streaming_client.before_request do
if options['csv']
require 'csv'
say TWEET_HEADINGS.to_csv
elsif options['long'] && STDOUT.tty?
headings = TWEET_HEADINGS.size.times.collect do |index|
TWEET_HEADINGS_FORMATTING[index] % TWEET_HEADINGS[index]
end
print_table([headings])
end
end
streaming_client.filter(:follow => user_ids.join(',')) do ||
next unless .is_a?(Twitter::Tweet)
next if options['no-replies'] && .reply?
next if options['no-retweets'] && .
if options['csv']
()
elsif options['long']
array = ().each_with_index.collect do |element, index|
TWEET_HEADINGS_FORMATTING[index] % element
end
print_table([array], :truncate => STDOUT.tty?)
else
print_message(.user.screen_name, .text)
end
end
end
|