Parent

Included Modules

Files

Twitter::Search

Attributes

result[R]
query[R]

Public Class Methods

new(q=nil, options={}) click to toggle source
    # File lib/twitter/search.rb, line 11
11:     def initialize(q=nil, options={})
12:       @options = options
13:       clear
14:       containing(q) if q && q.strip != ""
15:       endpoint_url = options[:api_endpoint]
16:       endpoint_url = "#{endpoint_url}/search" if endpoint_url && !endpoint_url.include?("/search")
17:       self.class.base_uri(endpoint_url) if endpoint_url
18:     end

Public Instance Methods

clear() click to toggle source

Clears all the query filters to make a new search

     # File lib/twitter/search.rb, line 120
120:     def clear
121:       @fetch = nil
122:       @query = {}
123:       @query[:q] = []
124:       self
125:     end
containing(word, exclude=false) click to toggle source
    # File lib/twitter/search.rb, line 41
41:     def containing(word, exclude=false)
42:       @query[:q] << "#{exclude ? "-" : ""}#{word}"
43:       self
44:     end
Also aliased as: contains
contains(word, exclude=false) click to toggle source
Alias for: containing
each() click to toggle source
     # File lib/twitter/search.rb, line 137
137:     def each
138:       results = fetch()['results']
139:       return if results.nil?
140:       results.each {|r| yield r}
141:     end
fetch(force=false) click to toggle source
     # File lib/twitter/search.rb, line 127
127:     def fetch(force=false)
128:       if @fetch.nil? || force
129:         query = @query.dup
130:         query[:q] = query[:q].join(" ")
131:         perform_get(query)
132:       end
133: 
134:       @fetch
135:     end
fetch_next_page() click to toggle source
     # File lib/twitter/search.rb, line 147
147:     def fetch_next_page
148:       if next_page?
149:         s = Search.new(nil, :user_agent => user_agent)
150:         s.perform_get(fetch()["next_page"][1..1])
151:         s
152:       end
153:     end
from(user, exclude=false) click to toggle source
    # File lib/twitter/search.rb, line 24
24:     def from(user, exclude=false)
25:       @query[:q] << "#{exclude ? "-" : ""}from:#{user}"
26:       self
27:     end
geocode(lat, long, range) click to toggle source

Ranges like 25km and 50mi work.

     # File lib/twitter/search.rb, line 109
109:     def geocode(lat, long, range)
110:       @query[:geocode] = [lat, long, range].join(",")
111:       self
112:     end
hashed(tag, exclude=false) click to toggle source

adds filtering based on hash tag ie: #

    # File lib/twitter/search.rb, line 48
48:     def hashed(tag, exclude=false)
49:       @query[:q] << "#{exclude ? "-" : ""}\##{tag}"
50:       self
51:     end
lang(lang) click to toggle source

lang must be ISO 639-1 code ie: en, fr, de, ja, etc.

when I tried en it limited my results a lot and took out several tweets that were english so i’d avoid this unless you really want it

    # File lib/twitter/search.rb, line 64
64:     def lang(lang)
65:       @query[:lang] = lang
66:       self
67:     end
max(id) click to toggle source
     # File lib/twitter/search.rb, line 114
114:     def max(id)
115:       @query[:max_id] = id
116:       self
117:     end
next_page?() click to toggle source
     # File lib/twitter/search.rb, line 143
143:     def next_page?
144:       !!fetch()["next_page"]
145:     end
page(num) click to toggle source

Which page of results to fetch

    # File lib/twitter/search.rb, line 82
82:     def page(num)
83:       @query[:page] = num
84:       self
85:     end
per_page(num) click to toggle source

Limits the number of results per page

    # File lib/twitter/search.rb, line 76
76:     def per_page(num)
77:       @query[:rpp] = num
78:       self
79:     end
phrase(phrase) click to toggle source

Search for a phrase instead of a group of words

    # File lib/twitter/search.rb, line 54
54:     def phrase(phrase)
55:       @query[:phrase] = phrase
56:       self
57:     end
ref(user, exclude=false) click to toggle source
Alias for: referencing
references(user, exclude=false) click to toggle source
Alias for: referencing
referencing(user, exclude=false) click to toggle source
    # File lib/twitter/search.rb, line 34
34:     def referencing(user, exclude=false)
35:       @query[:q] << "#{exclude ? "-" : ""}@#{user}"
36:       self
37:     end
Also aliased as: references, ref
result_type(result_type) click to toggle source

popular|recent

    # File lib/twitter/search.rb, line 70
70:     def result_type(result_type)
71:       @query[:result_type] = result_type
72:       self
73:     end
since(since_id) click to toggle source

Only searches tweets since a given id. Recommended to use this when possible.

    # File lib/twitter/search.rb, line 89
89:     def since(since_id)
90:       @query[:since_id] = since_id
91:       self
92:     end
since_date(since_date) click to toggle source

From the advanced search form, not documented in the API Format YYYY-MM-DD

    # File lib/twitter/search.rb, line 96
96:     def since_date(since_date)
97:       @query[:since] = since_date
98:       self
99:     end
to(user, exclude=false) click to toggle source
    # File lib/twitter/search.rb, line 29
29:     def to(user, exclude=false)
30:       @query[:q] << "#{exclude ? "-" : ""}to:#{user}"
31:       self
32:     end
until_date(until_date) click to toggle source

From the advanced search form, not documented in the API Format YYYY-MM-DD

     # File lib/twitter/search.rb, line 103
103:     def until_date(until_date)
104:       @query[:until] = until_date
105:       self
106:     end
user_agent() click to toggle source
    # File lib/twitter/search.rb, line 20
20:     def user_agent
21:       @options[:user_agent] || "Ruby Twitter Gem"
22:     end

Protected Instance Methods

perform_get(query) click to toggle source
     # File lib/twitter/search.rb, line 157
157:     def perform_get(query)
158:       response = self.class.get("#{self.class.base_uri}.json", :query => query, :format => :json, :headers => {"User-Agent" => user_agent})
159:       @fetch = Twitter.mash(response)
160:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.