assistly 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/assistly/api.rb +5 -0
- data/lib/assistly/configuration.rb +1 -11
- data/lib/assistly/version.rb +1 -1
- data/spec/assistly/api_spec.rb +0 -1
- data/spec/assistly_spec.rb +0 -13
- metadata +3 -4
- data/lib/assistly/search.rb +0 -473
data/lib/assistly/api.rb
CHANGED
@@ -11,10 +11,15 @@ module Assistly
|
|
11
11
|
# Creates a new API
|
12
12
|
def initialize(options={})
|
13
13
|
options = Assistly.options.merge(options)
|
14
|
+
|
14
15
|
Configuration::VALID_OPTIONS_KEYS.each do |key|
|
15
16
|
send("#{key}=", options[key])
|
16
17
|
end
|
17
18
|
end
|
19
|
+
|
20
|
+
def endpoint
|
21
|
+
"https://#{self.subdomain}.assistly.com/api/#{self.version}/"
|
22
|
+
end
|
18
23
|
|
19
24
|
include Connection
|
20
25
|
include Request
|
@@ -9,7 +9,6 @@ module Assistly
|
|
9
9
|
:adapter,
|
10
10
|
:consumer_key,
|
11
11
|
:consumer_secret,
|
12
|
-
:endpoint,
|
13
12
|
:format,
|
14
13
|
:oauth_token,
|
15
14
|
:oauth_token_secret,
|
@@ -57,15 +56,7 @@ module Assistly
|
|
57
56
|
|
58
57
|
# The user agent that will be sent to the API endpoint if none is set
|
59
58
|
DEFAULT_VERSION = "v1".freeze
|
60
|
-
|
61
|
-
# The endpoint that will be used to connect if none is set
|
62
|
-
#
|
63
|
-
# @note This is configurable in case you want to use HTTP instead of HTTPS, specify a different API version, or use a Twitter-compatible endpoint.
|
64
|
-
# @see http://status.net/wiki/Twitter-compatible_API
|
65
|
-
# @see http://en.blog.wordpress.com/2009/12/12/twitter-api/
|
66
|
-
# @see http://staff.tumblr.com/post/287703110/api
|
67
|
-
# @see http://developer.typepad.com/typepad-twitter-api/twitter-api.html
|
68
|
-
# DEFAULT_ENDPOINT = "https://#{self.subdomain}.assistly.com/api/#{Assistly.version}/"
|
59
|
+
|
69
60
|
|
70
61
|
# @private
|
71
62
|
attr_accessor *VALID_OPTIONS_KEYS
|
@@ -90,7 +81,6 @@ module Assistly
|
|
90
81
|
self.adapter = DEFAULT_ADAPTER
|
91
82
|
self.consumer_key = DEFAULT_CONSUMER_KEY
|
92
83
|
self.consumer_secret = DEFAULT_CONSUMER_SECRET
|
93
|
-
self.endpoint = "https://#{Assistly.subdomain}.assistly.com/api/#{Assistly.version}/"
|
94
84
|
self.format = DEFAULT_FORMAT
|
95
85
|
self.oauth_token = DEFAULT_OAUTH_TOKEN
|
96
86
|
self.oauth_token_secret = DEFAULT_OAUTH_TOKEN_SECRET
|
data/lib/assistly/version.rb
CHANGED
data/spec/assistly/api_spec.rb
CHANGED
data/spec/assistly_spec.rb
CHANGED
@@ -44,19 +44,6 @@ describe Assistly do
|
|
44
44
|
Assistly.adapter.should == :typhoeus
|
45
45
|
end
|
46
46
|
end
|
47
|
-
|
48
|
-
# describe ".endpoint" do
|
49
|
-
# it "should return the default endpoint" do
|
50
|
-
# Assistly.endpoint.should == Assistly::Configuration::DEFAULT_ENDPOINT
|
51
|
-
# end
|
52
|
-
# end
|
53
|
-
|
54
|
-
describe ".endpoint=" do
|
55
|
-
it "should set the endpoint" do
|
56
|
-
Assistly.endpoint = 'http://tumblr.com/'
|
57
|
-
Assistly.endpoint.should == 'http://tumblr.com/'
|
58
|
-
end
|
59
|
-
end
|
60
47
|
|
61
48
|
describe ".subdomain=" do
|
62
49
|
before do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: assistly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 3
|
10
|
+
version: 0.1.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Chris Warren
|
@@ -298,7 +298,6 @@ files:
|
|
298
298
|
- lib/assistly/connection.rb
|
299
299
|
- lib/assistly/error.rb
|
300
300
|
- lib/assistly/request.rb
|
301
|
-
- lib/assistly/search.rb
|
302
301
|
- lib/assistly/version.rb
|
303
302
|
- lib/faraday/request/multipart_with_file.rb
|
304
303
|
- lib/faraday/response/raise_http_4xx.rb
|
data/lib/assistly/search.rb
DELETED
@@ -1,473 +0,0 @@
|
|
1
|
-
require 'cgi'
|
2
|
-
|
3
|
-
module Twitter
|
4
|
-
# Wrapper for the Twitter Search API
|
5
|
-
#
|
6
|
-
# @note As of April 1st 2010, the Search API provides an option to retrieve
|
7
|
-
# "popular tweets" in addition to real-time search results. In an upcoming release,
|
8
|
-
# this will become the default and clients that don't want to receive popular tweets
|
9
|
-
# in their search results will have to explicitly opt-out. See {Twitter::Search#result_type}
|
10
|
-
# for more information.
|
11
|
-
# @note The user ids in the Search API are different from those in the REST API
|
12
|
-
# ({http://dev.twitter.com/pages/api_overview about the two APIs}). This defect is
|
13
|
-
# being tracked by {http://code.google.com/p/twitter-api/issues/detail?id=214 Issue 214}.
|
14
|
-
# This means that the to_user_id and from_user_id field vary from the actualy user id on
|
15
|
-
# Twitter.com. Applications will have to perform a screen name-based lookup with
|
16
|
-
# {Twitter::Client::User#user} to get the correct user id if necessary.
|
17
|
-
# @see http://dev.twitter.com/doc/get/search Twitter Search API Documentation
|
18
|
-
class Search < API
|
19
|
-
include Enumerable
|
20
|
-
|
21
|
-
# @private
|
22
|
-
attr_reader :query
|
23
|
-
|
24
|
-
# Creates a new search
|
25
|
-
#
|
26
|
-
# @example Initialize a Twitter search
|
27
|
-
# search = Twitter::Search.new
|
28
|
-
def initialize(*)
|
29
|
-
clear
|
30
|
-
super
|
31
|
-
end
|
32
|
-
|
33
|
-
alias :api_endpoint :search_endpoint
|
34
|
-
|
35
|
-
# Clears all query filters and cached results
|
36
|
-
#
|
37
|
-
# @return [Twitter::Search] self
|
38
|
-
# @example Clear a search for "twitter"
|
39
|
-
# search = Twitter::Search.new
|
40
|
-
# search.containing("twitter").fetch
|
41
|
-
# search.clear
|
42
|
-
# search.fetch_next_page #=> 403 Forbidden: You must enter a query.
|
43
|
-
def clear
|
44
|
-
@cache = nil
|
45
|
-
@query = {}
|
46
|
-
@query[:q] = []
|
47
|
-
@query[:tude] = []
|
48
|
-
self
|
49
|
-
end
|
50
|
-
|
51
|
-
# @group Generic filters
|
52
|
-
|
53
|
-
# Search query
|
54
|
-
#
|
55
|
-
# @param query [String] The search query.
|
56
|
-
# @return [Twitter::Search] self
|
57
|
-
# @example Return an array of tweets containing "twitter"
|
58
|
-
# Twitter::Search.new.containing("twitter").fetch
|
59
|
-
# Twitter::Search.new.contains("twitter").fetch # Shortcut for the above
|
60
|
-
# Twitter::Search.new.q("twitter").fetch # Even shorter-cut
|
61
|
-
def containing(query)
|
62
|
-
@query[:q] << query
|
63
|
-
self
|
64
|
-
end
|
65
|
-
alias :contains :containing
|
66
|
-
alias :q :containing
|
67
|
-
|
68
|
-
# Negative search query
|
69
|
-
#
|
70
|
-
# @param query [String] The negative search query.
|
71
|
-
# @return [Twitter::Search] self
|
72
|
-
# @example Return an array of tweets containing "beer" but not "root"
|
73
|
-
# Twitter::Search.new.containing("beer").not_containing("root").fetch
|
74
|
-
# Twitter::Search.new.containing("beer").does_not_contain("root").fetch # Same as above
|
75
|
-
# Twitter::Search.new.containing("beer").excluding("root").fetch # Shortcut for the above
|
76
|
-
# Twitter::Search.new.contains("beer").excludes("root").fetch # Even shorter
|
77
|
-
# Twitter::Search.new.q("beer").exclude("root").fetch # Shorter still
|
78
|
-
def not_containing(query)
|
79
|
-
@query[:q] << "-#{query}"
|
80
|
-
self
|
81
|
-
end
|
82
|
-
alias :does_not_contain :not_containing
|
83
|
-
alias :excluding :not_containing
|
84
|
-
alias :excludes :not_containing
|
85
|
-
alias :exclude :not_containing
|
86
|
-
|
87
|
-
# Search for a specific phrase instead of a group of words
|
88
|
-
#
|
89
|
-
# @param phrase [String] The search phrase.
|
90
|
-
# @return [Twitter::Search] self
|
91
|
-
# @example Return an array of tweets containing the phrase "happy hour"
|
92
|
-
# Twitter::Search.new.phrase("happy hour").fetch
|
93
|
-
def phrase(phrase)
|
94
|
-
@query[:phrase] = phrase
|
95
|
-
self
|
96
|
-
end
|
97
|
-
|
98
|
-
# Only include tweets that contain URLs
|
99
|
-
#
|
100
|
-
# @param filter [String] A type of search filter. Only 'links' is currently effective.
|
101
|
-
# @return [Twitter::Search] self
|
102
|
-
# @example Return an array of tweets containing "twitter" and URLs
|
103
|
-
# Twitter::Search.new.containing("twitter").filter.fetch
|
104
|
-
def filter(filter='links')
|
105
|
-
@query[:q] << "filter:#{filter}"
|
106
|
-
self
|
107
|
-
end
|
108
|
-
|
109
|
-
# Only include tweets from after a given date
|
110
|
-
#
|
111
|
-
# @param date [String] A date in the format YYYY-MM-DD.
|
112
|
-
# @return [Twitter::Search] self
|
113
|
-
# @example Return an array of tweets containing "twitter" since October 1, 2010
|
114
|
-
# Twitter::Search.new.containing("twitter").since_date("2010-10-01").fetch
|
115
|
-
def since_date(date)
|
116
|
-
@query[:since] = date
|
117
|
-
self
|
118
|
-
end
|
119
|
-
alias :since :since_date
|
120
|
-
|
121
|
-
# Only include tweets from before a given date
|
122
|
-
#
|
123
|
-
# @param date [String] A date in the format YYYY-MM-DD.
|
124
|
-
# @return [Twitter::Search] self
|
125
|
-
# @example Return an array of tweets containing "twitter" up until October 1, 2010
|
126
|
-
# Twitter::Search.new.containing("twitter").since_date("2010-10-01").fetch
|
127
|
-
def until_date(date)
|
128
|
-
@query[:until] = date
|
129
|
-
self
|
130
|
-
end
|
131
|
-
alias :until :until_date
|
132
|
-
|
133
|
-
# Only include tweets with a positive attitude
|
134
|
-
#
|
135
|
-
# @return [Twitter::Search] self
|
136
|
-
# @example Return an array of tweets containing happy emoticons
|
137
|
-
# Twitter::Search.new.positive.fetch
|
138
|
-
def positive
|
139
|
-
@query[:tude] << ":)"
|
140
|
-
self
|
141
|
-
end
|
142
|
-
|
143
|
-
# Only include tweets with a negative attitude
|
144
|
-
#
|
145
|
-
# @return [Twitter::Search] self
|
146
|
-
# @example Return an array of tweets containing sad emoticons
|
147
|
-
# Twitter::Search.new.negative.fetch
|
148
|
-
def negative
|
149
|
-
@query[:tude] << ":("
|
150
|
-
self
|
151
|
-
end
|
152
|
-
|
153
|
-
# Only include tweets that are asking a question
|
154
|
-
#
|
155
|
-
# @return [Twitter::Search] self
|
156
|
-
# @example Return an array of tweets containing question marks
|
157
|
-
# Twitter::Search.new.question.fetch
|
158
|
-
def question
|
159
|
-
@query[:tude] << "?"
|
160
|
-
self
|
161
|
-
end
|
162
|
-
|
163
|
-
# @group Demographic filters
|
164
|
-
|
165
|
-
# Only include tweets in a given language, specified by an ISO 639-1 code
|
166
|
-
#
|
167
|
-
# @param code [String] An ISO 639-1 code.
|
168
|
-
# @return [Twitter::Search] self
|
169
|
-
# @example Return an array of French-language tweets containing "twitter"
|
170
|
-
# Twitter::Search.new.containing("twitter").language("fr").fetch
|
171
|
-
# Twitter::Search.new.containing("twitter").lang("fr").fetch # Shortcut for the above
|
172
|
-
# @see http://en.wikipedia.org/wiki/ISO_639-1
|
173
|
-
def language(code)
|
174
|
-
@query[:lang] = code
|
175
|
-
self
|
176
|
-
end
|
177
|
-
alias :lang :language
|
178
|
-
|
179
|
-
# Specify the locale of the query you are sending
|
180
|
-
#
|
181
|
-
# @param code [String] An ISO 639-1 code (only 'ja' is currently effective).
|
182
|
-
# @return [Twitter::Search] self
|
183
|
-
# @example Return an array of tweets from Japan containing "twitter"
|
184
|
-
# Twitter::Search.new.containing("twitter").locale("ja").fetch
|
185
|
-
# @see http://en.wikipedia.org/wiki/ISO_639-1
|
186
|
-
def locale(code)
|
187
|
-
@query[:locale] = code
|
188
|
-
self
|
189
|
-
end
|
190
|
-
|
191
|
-
# Only include tweets from users in a given radius of a given location
|
192
|
-
#
|
193
|
-
# @param lat [Float] A latitude.
|
194
|
-
# @param long [Float] A longitude.
|
195
|
-
# @param radius [String] A search radius, specified in either 'mi' (miles) or 'km' (kilometers).
|
196
|
-
# @return [Twitter::Search] self
|
197
|
-
# @example Return an array of tweets within a 1-mile radius of Twitter HQ
|
198
|
-
# Twitter::Search.new.containing("twitter").geocode(37.781157, -122.398720, "1mi").fetch
|
199
|
-
def geocode(lat, long, radius)
|
200
|
-
@query[:geocode] = [lat, long, radius].join(",")
|
201
|
-
self
|
202
|
-
end
|
203
|
-
|
204
|
-
# Only include tweets from users in a given place, specified by a place ID
|
205
|
-
#
|
206
|
-
# @param place_id [String] A place ID.
|
207
|
-
# @return [Twitter::Search] self
|
208
|
-
# @example Return an array of tweets from San Francisco
|
209
|
-
# Twitter::Search.new.place("5a110d312052166f").fetch
|
210
|
-
def place(place_id)
|
211
|
-
@query[:q] << "place:#{place_id}"
|
212
|
-
self
|
213
|
-
end
|
214
|
-
|
215
|
-
# Only include tweets from users near a given location
|
216
|
-
#
|
217
|
-
# @param location [String] A location name.
|
218
|
-
# @return [Twitter::Search] self
|
219
|
-
# @example Return an array of tweets near San Francisco
|
220
|
-
# Twitter::Search.new.near("San Francisco").fetch
|
221
|
-
def near(location)
|
222
|
-
@query[:q] << "near:#{location.inspect}"
|
223
|
-
self
|
224
|
-
end
|
225
|
-
|
226
|
-
# @group User filters
|
227
|
-
|
228
|
-
# Only include tweets from a given user, specified by screen_name
|
229
|
-
#
|
230
|
-
# @param screen_name [String] A Twitter user name.
|
231
|
-
# @return [Twitter::Search] self
|
232
|
-
# @example Return an array of tweets containing "twitter" from @sferik
|
233
|
-
# Twitter::Search.new.containing("twitter").from("sferik").fetch
|
234
|
-
def from(screen_name)
|
235
|
-
@query[:q] << "from:#{screen_name}"
|
236
|
-
self
|
237
|
-
end
|
238
|
-
|
239
|
-
# Exclude tweets from a given user, specified by screen_name
|
240
|
-
#
|
241
|
-
# @param screen_name [String] A Twitter user name.
|
242
|
-
# @return [Twitter::Search] self
|
243
|
-
# @example Return an array of tweets containing "twitter" from everyone except @sferik
|
244
|
-
# Twitter::Search.new.containing("twitter").not_from("sferik").fetch
|
245
|
-
def not_from(screen_name)
|
246
|
-
@query[:q] << "-from:#{screen_name}"
|
247
|
-
self
|
248
|
-
end
|
249
|
-
|
250
|
-
# Only include tweets to a given user, specified by screen_name
|
251
|
-
#
|
252
|
-
# @param screen_name [String] A Twitter user name.
|
253
|
-
# @return [Twitter::Search] self
|
254
|
-
# @example Return an array of tweets containing "twitter" to @sferik
|
255
|
-
# Twitter::Search.new.containing("twitter").to("sferik").fetch
|
256
|
-
def to(screen_name)
|
257
|
-
@query[:q] << "to:#{screen_name}"
|
258
|
-
self
|
259
|
-
end
|
260
|
-
|
261
|
-
# Exclude tweets to a given user, specified by screen_name
|
262
|
-
#
|
263
|
-
# @param screen_name [String] A Twitter user name.
|
264
|
-
# @return [Twitter::Search] self
|
265
|
-
# @example Return an array of tweets containing "twitter" to everyone except @sferik
|
266
|
-
# Twitter::Search.new.containing("twitter").not_to("sferik").fetch
|
267
|
-
def not_to(screen_name)
|
268
|
-
@query[:q] << "-to:#{screen_name}"
|
269
|
-
self
|
270
|
-
end
|
271
|
-
|
272
|
-
# Only include tweets mentioning a given user, specified by screen_name
|
273
|
-
#
|
274
|
-
# @param screen_name [String] A Twitter user name.
|
275
|
-
# @return [Twitter::Search] self
|
276
|
-
# @example Return an array of tweets containing "twitter" and mentioning @sferik
|
277
|
-
# Twitter::Search.new.containing("twitter").mentioning("sferik").fetch
|
278
|
-
def mentioning(screen_name)
|
279
|
-
@query[:q] << "@#{screen_name.gsub('@', '')}"
|
280
|
-
self
|
281
|
-
end
|
282
|
-
alias :referencing :mentioning
|
283
|
-
alias :mentions :mentioning
|
284
|
-
alias :references :mentioning
|
285
|
-
|
286
|
-
# Exclude tweets mentioning a given user, specified by screen_name
|
287
|
-
#
|
288
|
-
# @param screen_name [String] A Twitter user name.
|
289
|
-
# @return [Twitter::Search] self
|
290
|
-
# @example Return an array of tweets containing "twitter" but not mentioning @sferik
|
291
|
-
# Twitter::Search.new.containing("twitter").not_mentioning("sferik").fetch
|
292
|
-
def not_mentioning(screen_name)
|
293
|
-
@query[:q] << "-@#{screen_name.gsub('@', '')}"
|
294
|
-
self
|
295
|
-
end
|
296
|
-
alias :not_referencing :not_mentioning
|
297
|
-
alias :does_not_mention :not_mentioning
|
298
|
-
alias :does_not_reference :not_mentioning
|
299
|
-
|
300
|
-
# @group Twitter filters
|
301
|
-
|
302
|
-
# Only include retweets
|
303
|
-
#
|
304
|
-
# @return [Twitter::Search] self
|
305
|
-
# @example Return an array of retweets containing "twitter"
|
306
|
-
# Twitter::Search.new.containing("twitter").retweets.fetch
|
307
|
-
def retweets
|
308
|
-
@query[:q] << "rt"
|
309
|
-
self
|
310
|
-
end
|
311
|
-
|
312
|
-
# Only include original status updates (i.e., not retweets)
|
313
|
-
#
|
314
|
-
# @return [Twitter::Search] self
|
315
|
-
# @example Return an array of tweets containing "twitter", excluding retweets
|
316
|
-
# Twitter::Search.new.containing("twitter").no_retweets.fetch
|
317
|
-
def no_retweets
|
318
|
-
@query[:q] << "-rt"
|
319
|
-
self
|
320
|
-
end
|
321
|
-
|
322
|
-
# Only include tweets containing a given hashtag
|
323
|
-
#
|
324
|
-
# @param tag [String] A Twitter hashtag.
|
325
|
-
# @return [Twitter::Search] self
|
326
|
-
# @example Return an array of tweets containing the hashtag #FollowFriday
|
327
|
-
# Twitter::Search.new.hashtag("FollowFriday").fetch
|
328
|
-
def hashtag(tag)
|
329
|
-
@query[:q] << "\##{tag.gsub('#', '')}"
|
330
|
-
self
|
331
|
-
end
|
332
|
-
|
333
|
-
# Exclude tweets containing a given hashtag
|
334
|
-
#
|
335
|
-
# @param tag [String] A Twitter hashtag.
|
336
|
-
# @return [Twitter::Search] self
|
337
|
-
# @example Return an array of tweets containing the hashtag #FollowFriday but not #FF
|
338
|
-
# Twitter::Search.new.hashtag("FollowFriday").excluding_hashtag("FF").fetch
|
339
|
-
# Twitter::Search.new.hashtag("FollowFriday").excludes_hashtag("FF").fetch # Shortcut for the above
|
340
|
-
# Twitter::Search.new.hashtag("FollowFriday").exclude_hashtag("FF").fetch # Even shorter
|
341
|
-
def excluding_hashtag(tag)
|
342
|
-
@query[:q] << "-\##{tag.gsub('#', '')}"
|
343
|
-
self
|
344
|
-
end
|
345
|
-
alias :excludes_hashtag :excluding_hashtag
|
346
|
-
alias :exclude_hashtag :excluding_hashtag
|
347
|
-
|
348
|
-
# Only include tweets with an ID greater than the specified ID
|
349
|
-
#
|
350
|
-
# @param id [Integer] A Twitter status ID.
|
351
|
-
# @return [Twitter::Search] self
|
352
|
-
# @example Return an array of tweets containing "twitter" with an ID greater than 123456789
|
353
|
-
# Twitter::Search.new.containing("twitter").since_id(123456789).fetch
|
354
|
-
def since_id(id)
|
355
|
-
@query[:since_id] = id
|
356
|
-
self
|
357
|
-
end
|
358
|
-
|
359
|
-
# Only include tweets with an ID less than or equal to the specified ID
|
360
|
-
#
|
361
|
-
# @param id [Integer] A Twitter status ID.
|
362
|
-
# @return [Twitter::Search] self
|
363
|
-
# @example Return an array of tweets containing "twitter" with an ID less than or equal to 123456789
|
364
|
-
# Twitter::Search.new.containing("twitter").max_id(123456789).fetch
|
365
|
-
#
|
366
|
-
def max_id(id)
|
367
|
-
@query[:max_id] = id
|
368
|
-
self
|
369
|
-
end
|
370
|
-
alias :max :max_id
|
371
|
-
|
372
|
-
# Specify what type of search results you want to receive
|
373
|
-
#
|
374
|
-
# @param result_type [String] The type of results you want to receive ('recent', 'popular', or 'mixed').
|
375
|
-
# @return [Twitter::Search] self
|
376
|
-
# @example Return an array of recent tweets containing "twitter"
|
377
|
-
# Twitter::Search.new.containing("twitter").result_type("recent").fetch
|
378
|
-
def result_type(result_type="mixed")
|
379
|
-
@query[:result_type] = result_type
|
380
|
-
self
|
381
|
-
end
|
382
|
-
|
383
|
-
# Only include tweets from a given source
|
384
|
-
#
|
385
|
-
# @param source [String] A Twitter source.
|
386
|
-
# @return [Twitter::Search] self
|
387
|
-
# @example Return an array of tweets containing "twitter", posted from Hibari
|
388
|
-
# Twitter::Search.new.containing("twitter").source("Hibari").fetch
|
389
|
-
def source(source)
|
390
|
-
@query[:q] << "source:#{source}"
|
391
|
-
self
|
392
|
-
end
|
393
|
-
|
394
|
-
# @group Paging
|
395
|
-
|
396
|
-
# Specify the number of tweets to return per page
|
397
|
-
#
|
398
|
-
# @param number [Integer] The number of tweets to return per page, up to a max of 100.
|
399
|
-
# @return [Twitter::Search] self
|
400
|
-
# @example Return an array of 100 tweets containing "twitter"
|
401
|
-
# Twitter::Search.new.containing("twitter").per_page(100).fetch
|
402
|
-
def per_page(number=15)
|
403
|
-
@query[:rpp] = number
|
404
|
-
self
|
405
|
-
end
|
406
|
-
alias :rpp :per_page
|
407
|
-
|
408
|
-
# Specify the page number to return, up to a maximum of roughly 1500 results
|
409
|
-
#
|
410
|
-
# @param number [Integer] The page number (starting at 1) to return, up to a max of roughly 1500 results (based on {Twitter::Client::Search#per_page} * {Twitter::Client::Search#page}).
|
411
|
-
# @return [Twitter::Search] self
|
412
|
-
# @example Return the second page of tweets containing "twitter"
|
413
|
-
# Twitter::Search.new.containing("twitter").page(2).fetch
|
414
|
-
def page(number)
|
415
|
-
@query[:page] = number
|
416
|
-
self
|
417
|
-
end
|
418
|
-
|
419
|
-
# Indicates if there are additional results to be fetched
|
420
|
-
#
|
421
|
-
# @return [Boolean]
|
422
|
-
# @example
|
423
|
-
# search = Twitter::Search.new.containing("twitter").fetch
|
424
|
-
# search.next_page? #=> true
|
425
|
-
def next_page?
|
426
|
-
fetch if @cache.nil?
|
427
|
-
!!@cache["next_page"]
|
428
|
-
end
|
429
|
-
|
430
|
-
# @group Fetching
|
431
|
-
|
432
|
-
# Fetch the next page of results of the query
|
433
|
-
#
|
434
|
-
# @return [Array] Tweets that match specified query.
|
435
|
-
# @example Return the first two pages of results
|
436
|
-
# search = Twitter::Search.new.containing("twitter").fetch
|
437
|
-
# search.fetch_next_page
|
438
|
-
def fetch_next_page
|
439
|
-
if next_page?
|
440
|
-
@cache = get("search", CGI.parse(@cache["next_page"][1..-1]))
|
441
|
-
@cache.results
|
442
|
-
end
|
443
|
-
end
|
444
|
-
|
445
|
-
# Fetch the results of the query
|
446
|
-
#
|
447
|
-
# @param force [Boolean] Ignore the cache and hit the API again.
|
448
|
-
# @return [Array] Tweets that match specified query.
|
449
|
-
# @example Return an array of tweets containing "twitter"
|
450
|
-
# search = Twitter::Search.new.containing("twitter").fetch
|
451
|
-
def fetch(force=false)
|
452
|
-
if @cache.nil? || force
|
453
|
-
options = query.dup
|
454
|
-
options[:q] = options[:q].join(" ")
|
455
|
-
@cache = get("search", options)
|
456
|
-
end
|
457
|
-
@cache.results
|
458
|
-
end
|
459
|
-
|
460
|
-
# Calls block once for each element in self, passing that element as a parameter
|
461
|
-
#
|
462
|
-
# @yieldparam [Hashie::Mash] result Tweet that matches specified query.
|
463
|
-
# @return [Array] Tweets that match specified query.
|
464
|
-
# @example
|
465
|
-
# Twitter::Search.new.containing('marry me').to('justinbieber').each do |result|
|
466
|
-
# puts "#{result.from_user}: #{result.text}"
|
467
|
-
# end
|
468
|
-
def each
|
469
|
-
fetch.each{|result| yield result}
|
470
|
-
end
|
471
|
-
|
472
|
-
end
|
473
|
-
end
|