NAME

REST::Google::Search - OO interface to Google Search API

SYNOPSIS

use REST::Google::Search;

REST::Google::Search->http_referer('http://example.com');

my $res = REST::Google::Search->new(
	q => 'Larry Wall',
);

die "response status failure" if $res->responseStatus != 200;

my $data = $res->responseData;

my $cursor = $data->cursor;
my $pages = $cursor->pages;

printf "current page index: %s\n", $cursor->currentPageIndex;
printf "estimated result count: %s\n", $cursor->estimatedResultCount;

my @results = $data->results;

foreach my $r (@results) {
	printf "\n";
	printf "title: %s\n", $r->title;
	printf "url: %s\n", $r->url;
}

DESCRIPTION

REST::Google::Search provides OO interface to Google REST (aka AJAX) API for searching.

METHODS

__PACKAGE__->service()

Get/set service to use.

The following table lists the URL used to access Google search services:

service   address
-------   ------------------------------------------------------
WEB       http://ajax.googleapis.com/ajax/services/search/web
VIDEO     http://ajax.googleapis.com/ajax/services/search/video
NEWS      http://ajax.googleapis.com/ajax/services/search/news
LOCAL     http://ajax.googleapis.com/ajax/services/search/local
IMAGES    http://ajax.googleapis.com/ajax/services/search/images
BOOKS     http://ajax.googleapis.com/ajax/services/search/books
BLOGS     http://ajax.googleapis.com/ajax/services/search/blogs

Service constants are exported on demand, so you can use the constants instead of service URLs:

use REST::Google::Search qw/VIDEO/;
REST::Google::Search->service( VIDEO );

Default service is WEB.

__PACKAGE__->http_referer()

Get/set HTTP Referer header.

Note: Google says that you should supply a valid HTTP referer header each time you perform a request to their AJAX API, so new() raises warning unless referer is specified.

__PACKAGE__->new()

The constructor use it's arguments to build a valid HTTP GET request to Google Search service, so it takes the same arguments as the web service takes. Please refer to 'Google Search AJAX API' documentation for complete list of arguments for Google Search. E.g.:

my $res = REST::Google::Search->new(
	q => 'Pamela Anderson',
	start => 4,
	hl => 'fr'
);

If you're using the default (WEB) search, the code above will perform a following HTTP GET request:

http://ajax.googleapis.com/ajax/services/search/web?hl=fr&q=Pamela+Anderson&v=1.0&start=4

Note: You can left protocol version number unspecified while making your searches since v=1.0 is passed by default.

CLASSES

REST::Google::Search contains dedicated classes for each of supported search services. You may use them instead of specifying certain service with service class method. E.g:

use REST::Google::Search::Blogs;
# ...
# set referer, etc
my $r = REST::Google::Search::Blogs->new( q => 'foobar' );

is the same as:

use REST::Google::Search qw/BLOGS/;
REST::Google::Search->service( BLOGS );
# ...
# set referer, etc
my $r = REST::Google::Search->new( q => 'foobar' );

Available classes:

REST::Google::Search::Web
REST::Google::Search::Blogs
REST::Google::Search::Books
REST::Google::Search::Images
REST::Google::Search::Local
REST::Google::Search::Video
REST::Google::Search::News

SEE ALSO

REST::Google - the base class for this module;

http://code.google.com/apis/ajaxsearch/documentation/#fonje - brief information about Google Search AJAX API in non-Javascript environments;

http://code.google.com/apis/ajaxsearch/documentation/reference.html#_intro_fonje - Google Search AJAX API documentation;

Google::Search - high-level class for Google Search AJAX API;

LICENSE AND COPYRIGHT

Copyright 2008, Eugen Sobchenko <ejs@cpan.org> and Sergey Sinkovskiy <glorybox@cpan.org>

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.