Module: GoogleCustomSearch
- Defined in:
- lib/google_cse.rb
Defined Under Namespace
Classes: Result, ResultSet, Start
Class Method Summary collapse
-
.search(query, start) ⇒ Object
Search the site.
Class Method Details
.search(query, start) ⇒ Object
Search the site.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/google_cse.rb', line 22 def self.search(query, start) # Get and parse results. url = url(query, start) json = fetch_json(url) data = Crack::JSON.parse(json) # Extract and return pages data and search result data. if data['responseData'] if data['responseData']['cursor']['pages'] ResultSet.new( parse_start(data['responseData']['cursor']['pages']), parse_results(data['responseData']['results']) ) else ResultSet.new( false, #return false if pages < 1 parse_results(data['responseData']['results']) ) end else ResultSet.new(0, []) end end |