Class: T::Search
Constant Summary
collapse
- DEFAULT_NUM_RESULTS =
20
- MAX_NUM_RESULTS =
200
- MAX_SEARCH_RESULTS =
100
Constants included
from Printable
Printable::LIST_HEADINGS, Printable::MONTH_IN_SECONDS, Printable::TWEET_HEADINGS, Printable::USER_HEADINGS
Instance Method Summary
collapse
#collect_with_count, #collect_with_max_id, #collect_with_page
Constructor Details
#initialize ⇒ Search
Returns a new instance of Search.
22
23
24
25
|
# File 'lib/t/search.rb', line 22
def initialize(*)
@rcfile = T::RCFile.instance
super
end
|
Instance Method Details
#all(query) ⇒ 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
|
# File 'lib/t/search.rb', line 33
def all(query)
count = options['number'] || DEFAULT_NUM_RESULTS
opts = {:count => MAX_SEARCH_RESULTS}
opts[:include_entities] = !!options['decode_uris']
= client.search(query, opts).take(count)
.reverse! if options['reverse']
if options['csv']
require 'csv'
say TWEET_HEADINGS.to_csv unless .empty?
.each do ||
say [.id, csv_formatted_time(), .user.screen_name, decode_full_text(, options['decode_uris'])].to_csv
end
elsif options['long']
array = .collect do ||
[.id, ls_formatted_time(), "@#{.user.screen_name}", decode_full_text(, options['decode_uris']).gsub(/\n+/, ' ')]
end
format = options['format'] || TWEET_HEADINGS.size.times.collect { '%s' }
print_table_with_headings(array, TWEET_HEADINGS, format)
else
say unless .empty?
.each do ||
print_message(.user.screen_name, decode_full_text(, options['decode_uris']))
end
end
end
|
#favorites(*args) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/t/search.rb', line 65
def favorites(*args)
query = args.pop
user = args.pop
opts = {:count => MAX_NUM_RESULTS}
opts[:include_entities] = !!options['decode_uris']
if user
require 't/core_ext/string'
user = options['id'] ? user.to_i : user.strip_ats
= collect_with_max_id do |max_id|
opts[:max_id] = max_id unless max_id.nil?
client.favorites(user, opts)
end
else
= collect_with_max_id do |max_id|
opts[:max_id] = max_id unless max_id.nil?
client.favorites(opts)
end
end
= .select do ||
/#{query}/i.match(.full_text)
end
()
end
|
#list(user_list, query) ⇒ Object
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/t/search.rb', line 96
def list(user_list, query)
owner, list_name = (user_list, options)
opts = {:count => MAX_NUM_RESULTS}
opts[:include_entities] = !!options['decode_uris']
= collect_with_max_id do |max_id|
opts[:max_id] = max_id unless max_id.nil?
client.list_timeline(owner, list_name, opts)
end
= .select do ||
/#{query}/i.match(.full_text)
end
()
end
|
#mentions(query) ⇒ Object
115
116
117
118
119
120
121
122
123
124
125
126
|
# File 'lib/t/search.rb', line 115
def mentions(query)
opts = {:count => MAX_NUM_RESULTS}
opts[:include_entities] = !!options['decode_uris']
= collect_with_max_id do |max_id|
opts[:max_id] = max_id unless max_id.nil?
client.mentions(opts)
end
= .select do ||
/#{query}/i.match(.full_text)
end
()
end
|
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
# File 'lib/t/search.rb', line 135
def (*args)
query = args.pop
user = args.pop
opts = {:count => MAX_NUM_RESULTS}
opts[:include_entities] = !!options['decode_uris']
if user
require 't/core_ext/string'
user = options['id'] ? user.to_i : user.strip_ats
= collect_with_max_id do |max_id|
opts[:max_id] = max_id unless max_id.nil?
client.(user, opts)
end
else
= collect_with_max_id do |max_id|
opts[:max_id] = max_id unless max_id.nil?
client.(opts)
end
end
= .select do ||
/#{query}/i.match(.full_text)
end
()
end
|
#timeline(*args) ⇒ Object
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
# File 'lib/t/search.rb', line 169
def timeline(*args)
query = args.pop
user = args.pop
opts = {:count => MAX_NUM_RESULTS}
opts[:exclude_replies] = true if options['exclude'] == 'replies'
opts[:include_entities] = !!options['decode_uris']
opts[:include_rts] = false if options['exclude'] == 'retweets'
opts[:max_id] = options['max_id'] if options['max_id']
opts[:since_id] = options['since_id'] if options['since_id']
if user
require 't/core_ext/string'
user = options['id'] ? user.to_i : user.strip_ats
= collect_with_max_id do |max_id|
opts[:max_id] = max_id unless max_id.nil?
client.user_timeline(user, opts)
end
else
= collect_with_max_id do |max_id|
opts[:max_id] = max_id unless max_id.nil?
client.home_timeline(opts)
end
end
= .select do ||
/#{query}/i.match(.full_text)
end
()
end
|
#users(query) ⇒ Object
205
206
207
208
209
210
|
# File 'lib/t/search.rb', line 205
def users(query)
users = collect_with_page do |page|
client.user_search(query, :page => page)
end
print_users(users)
end
|