Module: Twumper::Search

Included in:
Client
Defined in:
lib/twumper/search.rb

Constant Summary collapse

BASE_URL =
"https://api.twitter.com/1.1/search/tweets.json"
DEFAULT_OPTIONS =
{ 
  count: 100, 
  limit: 200, 
  result_type: 'mixed', 
  max_id: nil 
}

Instance Method Summary collapse

Instance Method Details

#search(keyword, options = DEFAULT_OPTIONS) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/twumper/search.rb', line 12

def search(keyword, options=DEFAULT_OPTIONS) 
  tweets = Array.new
  while tweets.count < options[:limit]
    url = "#{BASE_URL}?q=#{keyword}&result_type=#{options[:result_type]}&count=#{options[:count]}"
    url += "&max_id=#{options[:max_id]}" if !options[:max_id].nil?
    headers = set_headers
    response = connection.get(url, headers: headers)
    tweets += response['statuses']
    options[:max_id] = tweets.last['id']
  end
  tweets
end