Google Search

Tiny wrapper for Google Search APIs.

Usage

require 'google_search'

GoogleSearch.web :q => "pink floyd"

=> {"responseData"=>{"results"=>[{"GsearchResultClass"=>"GwebSearch", "title"=>"<b>Pink Floyd</b> | The Official Site", 
   "url"=>"http://www.pinkfloyd.com/", "cacheUrl"=>"http://www.google.com/search?q=cache:iFN1qQtvV7gJ:www.pinkfloyd.com", 
   "content"=>"", "visibleUrl"=>"www.pinkfloyd.com"...yaddayadda

You can also search videos, images, books etc. by calling GoogleSearch.[SEARCH TYPE] (e.g. GoogleSearch.images :q => “apple pie”)

For documention on options and response formats see code.google.com/intl/hr/apis/ajaxsearch/documentation/reference.html#_intro_fonje

Default options

You may specify default options that go into every request. Usually you’ll put your API key here.

GoogleSearch.default_options = { :key => "my-key", :hl => "hr" }

Paginated search

GoogleSearch.with_pages(1..5) do |search|
  search.images(:q => "moon") 
end

This will do search 5 times, each time given a different page (1..5). Useful for getting more results at once.

Handling errors

On invalid response a GoogleSearchError is raised, describing the error.

Copyright © 2010 Sasa Brankovic. See LICENSE for details.