SEARCH
NEW RPMS
DIRECTORIES
ABOUT
FAQ
VARIOUS
BLOG

 
 

MAN page from RedHat Other ruby-google-0.5.1-1.i386.rpm

lib/google.rb

Section: User Commands (1)
Updated: May 2003
Index 

NAME

Ruby/Google 

SYNOPSIS

    require 'google'        KEY = File.open("#{ENV['HOME']}/.google_key") {|kf| kf.readline.chomp}        query = ARGV.shift || 'ruby programming language'    google = Google::Search.new(KEY)        i = 0    q = google.search(query)    q.resultElements.each do |result|      printf "\nResult # %d\n\n", i += 1      result.each do |key|        printf("%s = %s\n", key, result.send(key))      end    end        puts '---------------------------------'    i = 0    q.directoryCategories.each do |category|      printf "\nCategory # %d\n\n", i += 1      category.each do |key|        printf("%s = %s\n", key, category.send(key))      end    end        printf "Estimated number of results is %d.\n",
    q.estimatedTotalResultsCount
    printf "Your query took %6f seconds.\n", q.searchTime
 

DESCRIPTION

Ruby/Google allows you to programmatically query theGoogle search-engine. It is currently in thealpha 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 keythat Google assigned to you when you registered for the Web API download.If you don't yet have a key, go toGoogleand obtain one.

Search.query_length_ok?(query)This checks to see whether the query length is under MAX_QUERY_LENGTHcharacters. It returns either true or false.

Search.query_words_ok?(query)This checks to see whether the number of words in query is underMAX_QUERY_WORDS. It returns either true or false.

Search.query_sites_ok?(query)This checks to see whether the number of site: restrict terms inquery is below MAX_QUERY_SITES. It returns either trueor false.
 

-

The above 3 methods check for compliance with the limitations of the GoogleWeb API, as defined in section 2.7 of the APIs_Reference.html file that camewith your Google API archive.

Search.query_ok?(query)This encapsulates the above 3 methods and can be used when one wishes toknow if query is bad, but not necessarily why it is bad. It returnseither true or false.

Search.restrict(type, *data)This assembles a query term, based on the restrict type and itsparameter(s), passed as *data. A full list of query terms isgiven in section 2.2 of APIs_Reference.html.
• If type is phrase, a double-quoted copy of each string passed as *data is returned.
• If type is daterange, the first three parameters of *data must be the year, month, and day of a start date. The next three parameters, if given, form the year, month, and day of an end date. If these last three parameters are not given, today's date will be substituted.
• Other supported restrict types are site, intitle, allintitle, inurl, allinurl, allintext, allinlinks, filetype, notfiletype, info, link, related, cache, include and exclude. Some of these names differ slightly from those given in section 2.2 of APIs_Reference.html in order to simplify their use and memorability.
 

INSTANCE METHODS

Search#search(query, start, max, filter, restrict, safe, lr, ie, oe)This performs a standard Google query search. Only the queryparameter is mandatory.

The meaning of the other parameters can be obtained from section 2.1 ofAPIs_Reference.html, although the ie and oe parameters arenow deprecated and should not be used. A warning will be issued if Rubyis run in verbose mode and either of these parameters is used.

This method returns a Struct::Response object, the members of which aredescribed in section 3.1 of APIs_Reference.html.

The resultElements member is an Array of Struct::ResultElementobjects. Members of the Struct::ResultElement object are described insection 3.2 of APIs_Reference.html. Note that the URL parameter isactually represented by the url member, since Ruby does not allowa variable name to begin with a capital letter.

The directoryCategories member is an Array ofStruct::DirectoryCategory. Members of the Struct::DirectoryCategory objectare described in section 3.3 of APIs_Reference.html.

Search#spell(phrase)This performs a Google spell-check on phrase. If Google has aspelling suggestion to make, a String is returned. Otherwise, nil isreturned.

Search#cache(url)This attempts to retrieve a copy of the page corresponding to urlfrom Google's cache. If Google has not cached the URL in question, a pagecontaining a message to this effect will be returned instead.

This method always returns a String.

 

ENVIRONMENT

HTTP_PROXY or http_proxyIf this is defined, the named system will be used as an HTTP proxy.
 

AUTHOR

Written by Ian Macdonald <ianAATTcaliban.org> 

COPYRIGHT

    Copyright (C) 2002-2003 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

Ruby/Google home page - http://www.caliban.org/ruby/Google Web APIs - http://www.google.com/apis/ 

BUGS

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

HISTORY

$Id: google.rb,v 1.32 2003/05/20 07:09:22 ianmacd Exp $


 

Index

NAME
SYNOPSIS
DESCRIPTION
CLASS METHODS
-
INSTANCE METHODS
ENVIRONMENT
AUTHOR
COPYRIGHT
SEE ALSO
BUGS
HISTORY

This document was created byman2html,using the manual pages.
 
ICM Bot detect detector