line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Pushover; |
2
|
|
|
|
|
|
|
# ABSTRACT: Net::Pushover - The Pushover API client implementation |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
# pragmas |
5
|
3
|
|
|
3
|
|
30308
|
use 5.10.0; |
|
3
|
|
|
|
|
8
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# imports |
8
|
3
|
|
|
3
|
|
1306
|
use Moo; |
|
3
|
|
|
|
|
26815
|
|
|
3
|
|
|
|
|
11
|
|
9
|
3
|
|
|
3
|
|
2949
|
use Carp; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
131
|
|
10
|
3
|
|
|
3
|
|
1157
|
use JSON; |
|
3
|
|
|
|
|
19774
|
|
|
3
|
|
|
|
|
12
|
|
11
|
3
|
|
|
3
|
|
1909
|
use LWP::UserAgent; |
|
3
|
|
|
|
|
84283
|
|
|
3
|
|
|
|
|
530
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# version |
14
|
|
|
|
|
|
|
our $VERSION = 0.021; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# accessors |
17
|
|
|
|
|
|
|
has token => (is => 'rw'); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
has user => (is => 'rw'); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has _ua => ( |
22
|
|
|
|
|
|
|
is => 'ro', default => sub { |
23
|
|
|
|
|
|
|
my $ua = LWP::UserAgent->new; |
24
|
|
|
|
|
|
|
$ua->agent('Net-Pushover/0.001 Perl API Client'); |
25
|
|
|
|
|
|
|
return $ua; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# methods |
31
|
|
|
|
|
|
|
sub message { |
32
|
3
|
|
|
3
|
1
|
4503
|
my ($self, $args) = (shift, {@_}); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# auth validation |
35
|
3
|
|
|
|
|
8
|
$self->_auth_validation; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# required fields |
38
|
|
|
|
|
|
|
Carp::confess("Field text is required for message body") |
39
|
3
|
100
|
|
|
|
102
|
unless $args->{text}; |
40
|
|
|
|
|
|
|
|
41
|
2
|
|
|
|
|
4
|
$args->{user} = $self->user; |
42
|
2
|
|
|
|
|
4
|
$args->{token} = $self->token; |
43
|
2
|
|
|
|
|
3
|
$args->{message} = delete $args->{text}; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# sending data |
46
|
2
|
|
|
|
|
7
|
my $res = $self->_ua->post( |
47
|
|
|
|
|
|
|
'https://api.pushover.net/1/messages.json', $args |
48
|
|
|
|
|
|
|
); |
49
|
|
|
|
|
|
|
|
50
|
2
|
|
|
|
|
12
|
return JSON::decode_json($res->decoded_content) |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub _auth_validation { |
54
|
6
|
|
|
6
|
|
7033
|
my $self = shift; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# auth exception |
57
|
6
|
100
|
|
|
|
172
|
Carp::confess("Error: token is undefined") unless $self->token; |
58
|
5
|
100
|
|
|
|
97
|
Carp::confess("Error: user is undefined") unless $self->user; |
59
|
|
|
|
|
|
|
|
60
|
4
|
|
|
|
|
6
|
return 1; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
__END__ |