line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::Google::Cloud::Messaging; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
593744
|
use strict; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
105
|
|
4
|
4
|
|
|
4
|
|
20
|
use warnings; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
111
|
|
5
|
4
|
|
|
4
|
|
84
|
use 5.008_001; |
|
4
|
|
|
|
|
22
|
|
6
|
|
|
|
|
|
|
|
7
|
4
|
|
|
4
|
|
21
|
use Carp qw(croak); |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
254
|
|
8
|
4
|
|
|
4
|
|
6338
|
use LWP::UserAgent; |
|
4
|
|
|
|
|
157654
|
|
|
4
|
|
|
|
|
125
|
|
9
|
4
|
|
|
4
|
|
3891
|
use LWP::ConnCache; |
|
4
|
|
|
|
|
5021
|
|
|
4
|
|
|
|
|
117
|
|
10
|
4
|
|
|
4
|
|
24
|
use HTTP::Request; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
119
|
|
11
|
4
|
|
|
4
|
|
2164
|
use JSON qw(encode_json); |
|
4
|
|
|
|
|
26458
|
|
|
4
|
|
|
|
|
25
|
|
12
|
|
|
|
|
|
|
use Class::Accessor::Lite ( |
13
|
4
|
|
|
|
|
34
|
new => 0, |
14
|
|
|
|
|
|
|
rw => [qw/ua api_url api_key/], |
15
|
4
|
|
|
4
|
|
3885
|
); |
|
4
|
|
|
|
|
4459
|
|
16
|
|
|
|
|
|
|
|
17
|
4
|
|
|
4
|
|
2835
|
use WWW::Google::Cloud::Messaging::Response; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
1393
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $VERSION = '0.06'; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our $API_URL = 'https://gcm-http.googleapis.com/gcm/send'; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub new { |
24
|
17
|
|
|
17
|
1
|
47429
|
my ($class, %args) = @_; |
25
|
17
|
100
|
|
|
|
226
|
croak 'Usage: WWW::Google::Cloud::Messaging->new(api_key => $api_key)' unless defined $args{api_key}; |
26
|
|
|
|
|
|
|
|
27
|
16
|
|
66
|
|
|
222
|
$args{ua} ||= LWP::UserAgent->new(agent => __PACKAGE__.'/'.$VERSION, conn_cache => LWP::ConnCache->new); |
28
|
16
|
|
66
|
|
|
18254
|
$args{api_url} ||= $API_URL; |
29
|
|
|
|
|
|
|
|
30
|
16
|
|
|
|
|
122
|
bless { %args }, $class; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub send { |
34
|
9
|
|
|
9
|
1
|
56016
|
my ($self, $payload) = @_; |
35
|
9
|
100
|
|
|
|
546
|
croak 'Usage: $gcm->send(\%payload)' unless ref $payload eq 'HASH'; |
36
|
|
|
|
|
|
|
|
37
|
5
|
|
|
|
|
47
|
my $res = $self->ua->request($self->build_request($payload)); |
38
|
5
|
|
|
|
|
173689
|
return WWW::Google::Cloud::Messaging::Response->new($res); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub build_request { |
42
|
10
|
|
|
10
|
1
|
58
|
my ($self, $payload) = @_; |
43
|
10
|
100
|
|
|
|
542
|
croak 'Usage: $gcm->build_request(\%payload)' unless ref $payload eq 'HASH'; |
44
|
|
|
|
|
|
|
|
45
|
6
|
100
|
|
|
|
28
|
if (exists $payload->{delay_while_idle}) { |
46
|
1
|
50
|
|
|
|
7
|
$payload->{delay_while_idle} = $payload->{delay_while_idle} ? JSON::true : JSON::false; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
6
|
|
|
|
|
35
|
my $req = HTTP::Request->new(POST => $self->api_url); |
50
|
6
|
|
|
|
|
22501
|
$req->header(Authorization => 'key='.$self->api_key); |
51
|
6
|
|
|
|
|
1211
|
$req->header('Content-Type' => 'application/json; charset=UTF-8'); |
52
|
6
|
|
|
|
|
530
|
$req->content(encode_json $payload); |
53
|
6
|
|
|
|
|
335
|
return $req; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
1; |
57
|
|
|
|
|
|
|
__END__ |