line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::Google::ClientLogin; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
433721
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
92
|
|
4
|
3
|
|
|
3
|
|
14
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
67
|
|
5
|
3
|
|
|
3
|
|
13
|
use Carp (); |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
46
|
|
6
|
3
|
|
|
3
|
|
3002
|
use LWP::UserAgent; |
|
3
|
|
|
|
|
113468
|
|
|
3
|
|
|
|
|
100
|
|
7
|
3
|
|
|
3
|
|
2785
|
use LWP::Protocol::https; # preload |
|
3
|
|
|
|
|
303232
|
|
|
3
|
|
|
|
|
137
|
|
8
|
3
|
|
|
3
|
|
82472
|
use HTTP::Request::Common qw(POST); |
|
3
|
|
|
|
|
7090
|
|
|
3
|
|
|
|
|
258
|
|
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
1987
|
use WWW::Google::ClientLogin::Response; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
84
|
|
11
|
|
|
|
|
|
|
|
12
|
3
|
|
|
3
|
|
73
|
use 5.008_001; |
|
3
|
|
|
|
|
11
|
|
|
3
|
|
|
|
|
1487
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $URL = 'https://www.google.com/accounts/ClientLogin'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new { |
18
|
10
|
|
|
10
|
1
|
121287
|
my ($class, %params) = @_; |
19
|
10
|
100
|
66
|
|
|
294
|
unless ($params{email} && $params{password} && $params{service}) { |
|
|
|
100
|
|
|
|
|
20
|
3
|
|
|
|
|
379
|
Carp::croak("Usage: $class->new(email => \$email, password => \$password, service => \$service)"); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
7
|
|
100
|
|
|
123
|
$params{type} ||= 'HOSTED_OR_GOOGLE'; |
24
|
7
|
|
66
|
|
|
43
|
$params{source} ||= __PACKAGE__ .'_'.$VERSION; |
25
|
7
|
|
66
|
|
|
404
|
$params{ua} ||= LWP::UserAgent->new(agent => __PACKAGE__.' / '.$VERSION); |
26
|
|
|
|
|
|
|
|
27
|
7
|
|
|
|
|
14589
|
bless { %params }, $class; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub authenticate { |
31
|
5
|
|
|
5
|
1
|
115
|
my $self = shift; |
32
|
5
|
100
|
|
|
|
302
|
my $http_request = POST $URL, [ |
|
|
100
|
|
|
|
|
|
33
|
|
|
|
|
|
|
accountType => $self->{type}, |
34
|
|
|
|
|
|
|
Email => $self->{email}, |
35
|
|
|
|
|
|
|
Passwd => $self->{password}, |
36
|
|
|
|
|
|
|
service => $self->{service}, |
37
|
|
|
|
|
|
|
source => $self->{source}, |
38
|
|
|
|
|
|
|
$self->{logintoken} ? (logintoken => $self->{logintoken}) : (), |
39
|
|
|
|
|
|
|
$self->{logincaptcha} ? (logincaptcha => $self->{logincaptcha}) : (), |
40
|
|
|
|
|
|
|
]; |
41
|
5
|
|
|
|
|
5579
|
my $http_response = $self->{ua}->request($http_request); |
42
|
|
|
|
|
|
|
|
43
|
5
|
|
|
|
|
754973
|
my $res; |
44
|
5
|
100
|
|
|
|
313
|
if ($http_response->is_success) { |
|
|
100
|
|
|
|
|
|
45
|
2
|
|
|
|
|
51
|
my $content = $http_response->content; |
46
|
2
|
|
|
|
|
31
|
my $params = { map { split '=', $_, 2 } split /\n/, $content }; |
|
6
|
|
|
|
|
24
|
|
47
|
2
|
|
|
|
|
75
|
$res = WWW::Google::ClientLogin::Response->new( |
48
|
|
|
|
|
|
|
is_success => 1, |
49
|
|
|
|
|
|
|
http_response => $http_response, |
50
|
|
|
|
|
|
|
params => { |
51
|
|
|
|
|
|
|
auth_token => $params->{Auth}, |
52
|
|
|
|
|
|
|
sid => $params->{SID}, |
53
|
|
|
|
|
|
|
lsid => $params->{LSID}, |
54
|
|
|
|
|
|
|
}, |
55
|
|
|
|
|
|
|
); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
elsif ($http_response->code == 403) { |
58
|
2
|
|
|
|
|
83
|
my $content = $http_response->content; |
59
|
2
|
|
|
|
|
39
|
my $params = { map { split '=', $_, 2 } split /\n/, $content }; |
|
4
|
|
|
|
|
24
|
|
60
|
2
|
|
|
|
|
100
|
$res = WWW::Google::ClientLogin::Response->new( |
61
|
|
|
|
|
|
|
is_success => 0, |
62
|
|
|
|
|
|
|
http_response => $http_response, |
63
|
|
|
|
|
|
|
error_code => $params->{Error}, |
64
|
|
|
|
|
|
|
); |
65
|
2
|
100
|
|
|
|
11
|
if ($params->{Error} eq 'CaptchaRequired') { |
66
|
1
|
|
|
|
|
29
|
$res->{is_captcha_required} = 1; |
67
|
1
|
|
|
|
|
13
|
$res->{params} = { |
68
|
|
|
|
|
|
|
captcha_token => $params->{CaptchaToken}, |
69
|
|
|
|
|
|
|
captcha_url => $params->{CaptchaUrl}, |
70
|
|
|
|
|
|
|
}; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
else { |
74
|
1
|
|
|
|
|
71
|
$res = WWW::Google::ClientLogin::Response->new( |
75
|
|
|
|
|
|
|
is_success => 0, |
76
|
|
|
|
|
|
|
http_response => $http_response, |
77
|
|
|
|
|
|
|
); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
5
|
|
|
|
|
29
|
return $res; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
1; |
84
|
|
|
|
|
|
|
__END__ |