| WWW-Google-API documentation | Contained in the WWW-Google-API distribution. |
WWW::Google::API - Perl client to the Google API <http://code.google.com/apis/>
version 0.003
$Id$
A base Google API client.
You probably want one of the subclasses of this module WWW::Google::API::Base
Create a new client.
Execute some action with the client.
John Cappiello, <jcap@cpan.org>
Copyright 2006-2007 John Cappiello, all rights reserved.
This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself.
| WWW-Google-API documentation | Contained in the WWW-Google-API distribution. |
package WWW::Google::API; use strict; use warnings;
our $VERSION = '0.003'; use base qw(Class::Accessor); use LWP::UserAgent; __PACKAGE__->mk_accessors(qw(ua token auth_client));
sub new { my $class = shift; my $service = shift; my $connection = shift; my $lwp_cnf = shift; my $auth_class = 'WWW::Google::API::Account::'.$connection->{auth_type}; eval "require $auth_class" or die $@; my $self = { ua => LWP::UserAgent->new( agent => 'WWW::Google::API', %$lwp_cnf ) }; bless($self, $class); $self->ua->default_header( 'X-Google-Key' => $connection->{api_key} ); $self->auth_client("$auth_class"->new($self->ua)); $self->token( $self->auth_client->authenticate( ( { service => $service, %$connection }, ) ) ); $self->ua->default_header( 'Authorization' => "GoogleLogin auth=" . $self->token ); return $self; }
sub do { my $self = shift; my $request = shift; my $response = $self->ua->request($request); if ($response->is_success) { return $response; } else { die $response; } }
1;