line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::Google::C2DM; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
250326
|
use strict; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
115
|
|
4
|
3
|
|
|
3
|
|
18
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
95
|
|
5
|
3
|
|
|
3
|
|
15
|
use Carp qw(croak); |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
200
|
|
6
|
3
|
|
|
3
|
|
2328
|
use HTTP::Request; |
|
3
|
|
|
|
|
58413
|
|
|
3
|
|
|
|
|
98
|
|
7
|
3
|
|
|
3
|
|
3906
|
use LWP::UserAgent; |
|
3
|
|
|
|
|
64123
|
|
|
3
|
|
|
|
|
96
|
|
8
|
3
|
|
|
3
|
|
2863
|
use LWP::Protocol::https; |
|
3
|
|
|
|
|
334766
|
|
|
3
|
|
|
|
|
145
|
|
9
|
3
|
|
|
3
|
|
29
|
use URI; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
69
|
|
10
|
|
|
|
|
|
|
|
11
|
3
|
|
|
3
|
|
1811
|
use WWW::Google::C2DM::Response; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
78
|
|
12
|
|
|
|
|
|
|
|
13
|
3
|
|
|
3
|
|
111
|
use 5.008_001; |
|
3
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
1751
|
|
14
|
|
|
|
|
|
|
our $VERSION = '0.08'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $URL = 'https://android.apis.google.com/c2dm/send'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub new { |
19
|
12
|
|
|
12
|
1
|
105080
|
my ($class, %args) = @_; |
20
|
12
|
100
|
|
|
|
240
|
croak "Usage: $class->new(auth_token => \$auth_token)" unless $args{auth_token}; |
21
|
11
|
|
66
|
|
|
729
|
$args{ua} ||= LWP::UserAgent->new(agent => __PACKAGE__.' / '.$VERSION); |
22
|
11
|
100
|
66
|
|
|
13553
|
if ($args{ua}->isa('LWP::UserAgent') && $LWP::UserAgent::VERSION >= 6.00) { |
23
|
10
|
|
|
|
|
233
|
$args{ua}->ssl_opts(verify_hostname => 0); |
24
|
|
|
|
|
|
|
} |
25
|
11
|
|
|
|
|
729
|
bless { %args }, $class; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub send { |
29
|
9
|
|
|
9
|
1
|
190
|
my ($self, %args) = @_; |
30
|
9
|
100
|
100
|
|
|
551
|
croak 'Usage: $self->send(registration_id => $reg_id, collapse_key => $collapse_key)' |
|
|
|
100
|
|
|
|
|
31
|
|
|
|
|
|
|
unless $args{registration_id} && defined $args{collapse_key} && length $args{collapse_key}; |
32
|
|
|
|
|
|
|
|
33
|
6
|
100
|
|
|
|
28
|
if (my $data = delete $args{data}) { |
34
|
3
|
100
|
|
|
|
214
|
croak 'data parameter must be HASHREF' unless ref $data eq 'HASH'; |
35
|
1
|
|
|
|
|
14
|
map { $args{"data.$_"} = $data->{$_} } keys %$data; |
|
3
|
|
|
|
|
33
|
|
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
4
|
|
|
|
|
213
|
my $req = HTTP::Request->new(POST => $URL); |
39
|
4
|
|
|
|
|
1699
|
$req->header('Content-Type' => 'application/x-www-form-urlencoded'); |
40
|
4
|
|
|
|
|
436
|
$req->header(Authorization => 'GoogleLogin auth='.$self->{auth_token}); |
41
|
|
|
|
|
|
|
|
42
|
4
|
|
|
|
|
213
|
my $uri = URI->new('http://'); |
43
|
4
|
|
|
|
|
360
|
$uri->query_form(\%args); |
44
|
4
|
|
|
|
|
784
|
$req->content($uri->query); |
45
|
|
|
|
|
|
|
|
46
|
4
|
|
|
|
|
273
|
my $http_response = $self->{ua}->request($req); |
47
|
|
|
|
|
|
|
|
48
|
4
|
|
|
|
|
160183
|
my $result; |
49
|
4
|
100
|
|
|
|
18
|
if ($http_response->code == 200) { |
50
|
3
|
|
|
|
|
50
|
my $content = $http_response->content; |
51
|
3
|
|
|
|
|
39
|
my $params = { map { split '=', $_, 2 } split /\n/, $content }; |
|
3
|
|
|
|
|
23
|
|
52
|
3
|
100
|
|
|
|
13
|
if ($params->{Error}) { |
53
|
1
|
|
|
|
|
38
|
$result = WWW::Google::C2DM::Response->new( |
54
|
|
|
|
|
|
|
is_success => 0, |
55
|
|
|
|
|
|
|
error_code => $params->{Error}, |
56
|
|
|
|
|
|
|
http_response => $http_response, |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
else { |
60
|
2
|
|
|
|
|
62
|
$result = WWW::Google::C2DM::Response->new( |
61
|
|
|
|
|
|
|
is_success => 1, |
62
|
|
|
|
|
|
|
http_response => $http_response, |
63
|
|
|
|
|
|
|
params => $params, |
64
|
|
|
|
|
|
|
); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
else { |
68
|
1
|
|
|
|
|
44
|
$result = WWW::Google::C2DM::Response->new( |
69
|
|
|
|
|
|
|
is_success => 0, |
70
|
|
|
|
|
|
|
http_response => $http_response, |
71
|
|
|
|
|
|
|
); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
4
|
|
|
|
|
36
|
return $result; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |
78
|
|
|
|
|
|
|
__END__ |