=head1 NAME

Search::Google - search Google using the REST (aka AJAX) API

=head1 VERSION

This documentation refers to Search::Google version 1.0.5

=head1 SYNOPSIS

	use Search::Google;

	# you should provide a valid http referer address according
	# to Google AJAX Search API terms of use!
	Search::Google->http_referer('http://example.com');

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

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

	my $data = $res->responseData;

	my $cursor = $data->cursor;

	printf "pages: %s\n", $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;
	}

=head1 DESCRIPTION

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

=head1 METHODS

=over

=item __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 by default, so following lines are equal:

	Search::Google->service( 'http://ajax.googleapis.com/ajax/services/search/video' );
	Search::Google->service( VIDEO );

Default service is WEB.

=item __PACKAGE__->http_referer()

Get/set HTTP C<Referer> header.

	Search::Google->http_referer('http://example.org/search.html');

I<Note:> Google says that you should supply a valid HTTP referer header each time you
perform the search request using their AJAX API, so C<new()> raises warning unless referer
is specified.

=item __PACKAGE__->new()

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

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

If you're using the default (WEB) serice, 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

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

C<Search::Google> objects are completely represent Google AJAX API search response objects
and have the following structure:

	{
		"responseData" => {
			"results" => [],
			"cursor" => {}
		},
		"responseDetails" => undef | string-on-error,
		"responseStatus" => 200 | error-code
	}

=item $res->responseStatus()

The responseStatus property contains a value of 200 on success and a non-200
HTTP error status code on failure. If there is a failure, C<responseDetails> contains
a diagnostic string.

=item $res->responseDetails()

Contain an error string if C<responseStatus> is not 200.

=item $res->responseData()

Returns an object that provides OO access to Google C<responseData> structure.
This object has actually two methods: a C<results> that returns the array of result
objects for the given service and C<cursor> method that return cursor object (if exists).

Please refer to 'Google AJAX Search API' documentation for response structure details.

=back

=head1 CLASSES

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

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

is the same as:

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

Available classes:

=over

=item L<Search::Google::Web>

=item L<Search::Google::Blogs>

=item L<Search::Google::Books>

=item L<Search::Google::Images>

=item L<Search::Google::Local>

=item L<Search::Google::Video>

=item L<Search::Google::News>

=back

=head1 DEPENDENCIES

C<Search::Google> uses L<JSON::Any> for decoding Google AJAX Search API response and L<LWP> for search request sending.

=head1 SEE ALSO

L<http://code.google.com/p/search-google/> - this project on Google code;

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

L<http://code.google.com/apis/ajaxsearch/documentation/reference.html#_intro_fonje> - detailed specification
for Google AJAX Search API.

=head1 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.
