WWW::Google::API - Perl client to the Google API C<< <http://code.google.com/apis/> >>


WWW-Google-API documentation Contained in the WWW-Google-API distribution.

Index


Code Index:

NAME

Top

WWW::Google::API - Perl client to the Google API <http://code.google.com/apis/>

VERSION

Top

version 0.003

  $Id$

SYNOPSIS

Top

A base Google API client.

You probably want one of the subclasses of this module WWW::Google::API::Base

METHODS

Top

new

Create a new client.

do

Execute some action with the client.

AUTHOR

Top

John Cappiello, <jcap@cpan.org>

BUGS

Top

http://rt.cpan.org/Public/Dist/Display.html?Name=WWW-Google-API

COPYRIGHT

Top


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;