line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::FCM::HTTP::V1; |
2
|
3
|
|
|
3
|
|
259046
|
use 5.008001; |
|
3
|
|
|
|
|
26
|
|
3
|
3
|
|
|
3
|
|
13
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
52
|
|
4
|
3
|
|
|
3
|
|
11
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
132
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = "0.01"; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use Class::Accessor::Lite ( |
9
|
3
|
|
|
|
|
20
|
new => 0, |
10
|
|
|
|
|
|
|
rw => [qw/sender api_url/], |
11
|
3
|
|
|
3
|
|
1132
|
); |
|
3
|
|
|
|
|
2787
|
|
12
|
3
|
|
|
3
|
|
1294
|
use JSON qw(encode_json); |
|
3
|
|
|
|
|
17160
|
|
|
3
|
|
|
|
|
15
|
|
13
|
3
|
|
|
3
|
|
386
|
use Carp qw(croak); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
139
|
|
14
|
|
|
|
|
|
|
|
15
|
3
|
|
|
3
|
|
1166
|
use WWW::FCM::HTTP::V1::OAuth; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
567
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $SCOPE_FIREBASE_MESSAGING = "https://www.googleapis.com/auth/firebase.messaging"; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub new { |
20
|
7
|
|
|
7
|
1
|
19072
|
my $class = shift; |
21
|
7
|
100
|
100
|
|
|
47
|
my %args = $_[0] && ref $_[0] eq 'HASH' ? %{ $_[0] } : @_; |
|
1
|
|
|
|
|
4
|
|
22
|
|
|
|
|
|
|
croak 'Usage: WWW::FCM::HTTP::V1->new({ api_url => $api_url, api_key_json => $api_key_json })' |
23
|
7
|
100
|
100
|
|
|
410
|
unless (exists $args{api_url} && defined $args{api_url} && exists $args{api_key_json} && defined $args{api_key_json}); |
|
|
|
66
|
|
|
|
|
|
|
|
66
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
$args{sender} ||= WWW::FCM::HTTP::V1::OAuth->new( |
26
|
|
|
|
|
|
|
api_key_json => $args{api_key_json}, |
27
|
4
|
|
66
|
|
|
42
|
scopes => [$SCOPE_FIREBASE_MESSAGING], |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
4
|
|
|
|
|
20
|
bless { %args }, $class; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub send { |
34
|
8
|
|
|
8
|
1
|
99153
|
my ($self, $content) = @_; |
35
|
8
|
100
|
|
|
|
123
|
croak 'Usage: $fcm->send(\%content)' unless ref $content eq 'HASH'; |
36
|
|
|
|
|
|
|
|
37
|
4
|
|
|
|
|
292
|
$self->sender->request( |
38
|
|
|
|
|
|
|
method => "POST", |
39
|
|
|
|
|
|
|
uri => $self->api_url, |
40
|
|
|
|
|
|
|
content => encode_json($content), |
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
1; |
45
|
|
|
|
|
|
|
__END__ |