| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# http://blogs.perl.org/users/sawyer_x/2010/08/distzilla-strictures-tip.html |
|
2
|
1
|
|
|
1
|
|
59371
|
use strictures 1; |
|
|
1
|
|
|
|
|
834
|
|
|
|
1
|
|
|
|
|
30
|
|
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package WebService::NotifyMyAndroid; |
|
5
|
|
|
|
|
|
|
{ |
|
6
|
|
|
|
|
|
|
$WebService::NotifyMyAndroid::VERSION = '0.0.6'; |
|
7
|
|
|
|
|
|
|
} |
|
8
|
|
|
|
|
|
|
{ |
|
9
|
|
|
|
|
|
|
$WebService::NotifyMyAndroid::DIST = 'WebService-NotifyMyAndroid'; |
|
10
|
|
|
|
|
|
|
} |
|
11
|
1
|
|
|
1
|
|
84
|
use base qw( WebService::Simple ); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
795
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
binmode STDOUT, ":encoding(UTF-8)"; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use Carp; |
|
16
|
|
|
|
|
|
|
use Params::Validate qw( :all ); |
|
17
|
|
|
|
|
|
|
use Readonly; |
|
18
|
|
|
|
|
|
|
use Regexp::Common qw( number ); |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# make sure we have the https protocol available to us; |
|
21
|
|
|
|
|
|
|
# we need this to do anything this the API url |
|
22
|
|
|
|
|
|
|
use LWP::Protocol::https; |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# Module implementation here |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# constants |
|
27
|
|
|
|
|
|
|
Readonly my $NMA_URL => 'https://www.notifymyandroid.com/publicapi/'; |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# string lengths in characters |
|
30
|
|
|
|
|
|
|
Readonly my $KEYLENGTH => 48; |
|
31
|
|
|
|
|
|
|
Readonly my $APPLENGTH => 256; |
|
32
|
|
|
|
|
|
|
Readonly my $EVENTLENGTH => 1000; |
|
33
|
|
|
|
|
|
|
Readonly my $DESCLENGTH => 10000; |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# validation regexes |
|
36
|
|
|
|
|
|
|
## we're using the 'weird' format for setting flags because strictures |
|
37
|
|
|
|
|
|
|
## complains about 'use of multidimensional array emulation' with the |
|
38
|
|
|
|
|
|
|
## "{-base => 16}" syntax |
|
39
|
|
|
|
|
|
|
## for more information read the documentation for strictures, |
|
40
|
|
|
|
|
|
|
## multidimensional and Regexp::Common (Flag syntax) |
|
41
|
|
|
|
|
|
|
Readonly my $KEYREGEX => $RE{num}{int}{"-base$;16"}{"-places$;$KEYLENGTH"}; |
|
42
|
|
|
|
|
|
|
Readonly my $APPREGEX => ".{1,$APPLENGTH}"; |
|
43
|
|
|
|
|
|
|
Readonly my $EVENTREGEX => ".{1,$EVENTLENGTH}"; |
|
44
|
|
|
|
|
|
|
Readonly my $DESCREGEX => ".{1,$DESCLENGTH}"; |
|
45
|
|
|
|
|
|
|
Readonly my $PRIOREGEX => "(?:-?[12]+|0)"; |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# NMA-specific configuration |
|
48
|
|
|
|
|
|
|
__PACKAGE__->config( |
|
49
|
|
|
|
|
|
|
base_url => $NMA_URL, |
|
50
|
|
|
|
|
|
|
response_parser => 'XML::Simple', |
|
51
|
|
|
|
|
|
|
); |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# public functions |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
my %verify_spec = ( |
|
56
|
|
|
|
|
|
|
apikey => { |
|
57
|
|
|
|
|
|
|
type => SCALAR, |
|
58
|
|
|
|
|
|
|
callbacks => { |
|
59
|
|
|
|
|
|
|
'valid API key' => \&_valid_api_key, |
|
60
|
|
|
|
|
|
|
}, |
|
61
|
|
|
|
|
|
|
}, |
|
62
|
|
|
|
|
|
|
developerkey => { |
|
63
|
|
|
|
|
|
|
optional => 1, |
|
64
|
|
|
|
|
|
|
type => SCALAR, |
|
65
|
|
|
|
|
|
|
callbacks => { |
|
66
|
|
|
|
|
|
|
'valid API key' => \&_valid_api_key, |
|
67
|
|
|
|
|
|
|
}, |
|
68
|
|
|
|
|
|
|
}, |
|
69
|
|
|
|
|
|
|
); |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub verify { |
|
72
|
|
|
|
|
|
|
my ($self, @args) = @_; |
|
73
|
|
|
|
|
|
|
my %params = validate( @args, \%verify_spec ); |
|
74
|
|
|
|
|
|
|
return $self->get( 'verify', \%params )->parse_response; |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
my %notify_spec = ( |
|
78
|
|
|
|
|
|
|
apikey => { |
|
79
|
|
|
|
|
|
|
type => SCALAR | ARRAYREF, |
|
80
|
|
|
|
|
|
|
callbacks => { |
|
81
|
|
|
|
|
|
|
'valid API key' => \&_valid_api_key, |
|
82
|
|
|
|
|
|
|
}, |
|
83
|
|
|
|
|
|
|
}, |
|
84
|
|
|
|
|
|
|
application => { |
|
85
|
|
|
|
|
|
|
type => SCALAR, |
|
86
|
|
|
|
|
|
|
regex => qr/^$APPREGEX$/xms, |
|
87
|
|
|
|
|
|
|
}, |
|
88
|
|
|
|
|
|
|
event => { |
|
89
|
|
|
|
|
|
|
type => SCALAR, |
|
90
|
|
|
|
|
|
|
regex => qr/^$EVENTREGEX$/xms, |
|
91
|
|
|
|
|
|
|
}, |
|
92
|
|
|
|
|
|
|
description => { |
|
93
|
|
|
|
|
|
|
type => SCALAR, |
|
94
|
|
|
|
|
|
|
regex => qr/^$DESCREGEX$/xms, |
|
95
|
|
|
|
|
|
|
}, |
|
96
|
|
|
|
|
|
|
priority => { |
|
97
|
|
|
|
|
|
|
optional => 1, |
|
98
|
|
|
|
|
|
|
type => SCALAR, |
|
99
|
|
|
|
|
|
|
regex => qr/^$PRIOREGEX$/xms, |
|
100
|
|
|
|
|
|
|
default => 0, |
|
101
|
|
|
|
|
|
|
}, |
|
102
|
|
|
|
|
|
|
developerkey => { |
|
103
|
|
|
|
|
|
|
optional => 1, |
|
104
|
|
|
|
|
|
|
type => SCALAR, |
|
105
|
|
|
|
|
|
|
callbacks => { |
|
106
|
|
|
|
|
|
|
'valid API key' => \&_valid_api_key, |
|
107
|
|
|
|
|
|
|
}, |
|
108
|
|
|
|
|
|
|
}, |
|
109
|
|
|
|
|
|
|
); |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub notify { |
|
112
|
|
|
|
|
|
|
my ($self, @args) = @_; |
|
113
|
|
|
|
|
|
|
my %params = validate( @args, \%notify_spec ); |
|
114
|
|
|
|
|
|
|
return $self->post( 'notify', \%params )->parse_response; |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
# private functions |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub _valid_api_key { |
|
120
|
|
|
|
|
|
|
my( $candidate, $params ) = @_; |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
if ( ref( $candidate ) eq 'ARRAY' ) { |
|
123
|
|
|
|
|
|
|
foreach my $key ( @{$candidate} ) { |
|
124
|
|
|
|
|
|
|
_valid_api_key( $key ) or return; |
|
125
|
|
|
|
|
|
|
} |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
else { |
|
128
|
|
|
|
|
|
|
$candidate =~ /^$KEYREGEX$/ixms or return; |
|
129
|
|
|
|
|
|
|
} |
|
130
|
|
|
|
|
|
|
return( $candidate ); |
|
131
|
|
|
|
|
|
|
} |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
1; # Magic true value required at end of module |
|
134
|
|
|
|
|
|
|
# ABSTRACT: Perl interface to Notify My Android web API |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
__END__ |