line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::Google::API; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
33363
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
72
|
|
4
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
99
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
WWW::Google::API - Perl client to the Google API C<< >> |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 VERSION |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
version 0.003 |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
$Id$ |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 SYNOPSIS |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
A base Google API client. |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
You probably want one of the subclasses of this module L |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=cut |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
our $VERSION = '0.003'; |
25
|
|
|
|
|
|
|
|
26
|
2
|
|
|
2
|
|
9
|
use base qw(Class::Accessor); |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
3421
|
|
27
|
|
|
|
|
|
|
|
28
|
2
|
|
|
2
|
|
27613
|
use LWP::UserAgent; |
|
2
|
|
|
|
|
125907
|
|
|
2
|
|
|
|
|
645
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw(ua token auth_client)); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 METHODS |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head2 new |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
Create a new client. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=cut |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub new { |
42
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
43
|
0
|
|
|
|
|
|
my $service = shift; |
44
|
0
|
|
|
|
|
|
my $connection = shift; |
45
|
0
|
|
|
|
|
|
my $lwp_cnf = shift; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
my $auth_class = 'WWW::Google::API::Account::'.$connection->{auth_type}; |
49
|
0
|
0
|
|
|
|
|
eval "require $auth_class" or die $@; |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
my $self = { ua => LWP::UserAgent->new( agent => 'WWW::Google::API', |
52
|
|
|
|
|
|
|
%$lwp_cnf ) }; |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
bless($self, $class); |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
$self->ua->default_header( 'X-Google-Key' => $connection->{api_key} ); |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
$self->auth_client("$auth_class"->new($self->ua)); |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
$self->token( $self->auth_client->authenticate( ( { service => $service, |
61
|
|
|
|
|
|
|
%$connection |
62
|
|
|
|
|
|
|
}, |
63
|
|
|
|
|
|
|
) |
64
|
|
|
|
|
|
|
) |
65
|
|
|
|
|
|
|
); |
66
|
0
|
|
|
|
|
|
$self->ua->default_header( 'Authorization' => "GoogleLogin auth=" . $self->token ); |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
return $self; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head2 do |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Execute some action with the client. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=cut |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub do { |
78
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
79
|
0
|
|
|
|
|
|
my $request = shift; |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
my $response = $self->ua->request($request); |
82
|
|
|
|
|
|
|
|
83
|
0
|
0
|
|
|
|
|
if ($response->is_success) { |
84
|
0
|
|
|
|
|
|
return $response; |
85
|
|
|
|
|
|
|
} else { |
86
|
0
|
|
|
|
|
|
die $response; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 AUTHOR |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
John Cappiello, C<< >> |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 BUGS |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
L |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 COPYRIGHT |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Copyright 2006-2007 John Cappiello, all rights reserved. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
This program is free software; you may redistribute it and/or modify it |
103
|
|
|
|
|
|
|
under the same terms as Perl itself. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=cut |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
1; |