NAME

Google::Search

SYNOPSIS

require 'google'

KEY = 'shajhdkhfjdfhjdfdjfdjfhdsgdhsgdg'

query = ARGV.shift || 'ruby programming language'
google = Google::Search.new(KEY)

i = 0
q = google.search(query)
q.response['results'].each do |result|
  printf "\nResult # %d\n\n", i += 1
  result.each do |key|
    printf("%s = %s\n", key, result.attribute[key])
  end
end

puts '---------------------------------'
printf "Estimated number of results is %d.\n",
        q.response['estimatedTotalResultsCount']
printf "Your query took %6f seconds.\n", q.response['searchTime']

DESCRIPTION

Google::Search allows you to programmatically query the Google search-engine at www.google.com. It is currently in the alpha stage and the interface is liable to change at any time.

CLASS METHODS

Search.new(key)

This constructs a new Google search object. The key parameter is the key that Google assigned to you when you registered for the Web API download. If you don't yet have a key, go to Google and obtain one.

INSTANCE METHODS

Search#search(query, start, max, filter, restrict, safe, lr, ie, oe)

This performs a standard Google query search. Only the query parameter is mandatory.

The meaning of the other parameters can be obtained from section 2.1 of the APIs_Reference.html file that came with your Google API archive.

This method returns a Hash, the keys of which are described in section 3.1 of APIs_Reference.html.

The resultElements element is, itself, a Hash, the elements of which are described in section 3.2 of APIs_Reference.html.

Search#spell(phrase)

This attempts to perform a Google spell-check on phrase. If Google has no spelling suggestions to make, nil is returned. Otherwise, a String is returned.

Search#cache(url)

This attempts to retrieve the cached Google copy of the page corresponding to url. If Google has not cached the URL in question, a page containing a message to this effect will be returned by the search-engine.

This method always returns a String.

AUTHOR

Written by Ian Macdonald <ian@caliban.org>.

COPYRIGHT

Copyright (c) 2002 Ian Macdonald
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE.

SEE ALSO

http://www.caliban.org/ruby
http://www.google.com/

BUGS

Send all bug reports, enhancement requests and patches to the
author.

HISTORY

$Id: google.rb,v 1.5 2002/04/11 21:33:22 ianmacd Exp $