AbuseIPDB/Response.pm

filter: Statementstmt 100% 17 / 17 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 100% 3 / 3 totaltotal 100% 28 / 28 SCAR 6.9
CC
2
Cov
100%
new
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.0
« AbuseIPDB/Category.pm ↑ Summary AbuseIPDB/BlacklistMember.pm »
1 package WebService::AbuseIPDB::Response;
2  
3 #===============================================================================
4 # FILE: Response.pm
5 # DESCRIPTION: Generic Response Object - See POD for details
6 # AUTHOR: Pete Houston (pete), cpan@openstrike.co.uk
7 # ORGANIZATION: Openstrike
8 # CREATED: 12/08/19 14:38:21
9 #===============================================================================
10  
11 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 6 ▶use WebService::AbuseIPDB;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 6 our $VERSION = $WebService::AbuseIPDB::VERSION;
17  
18 sub new {
19 9 ▶ my ($class, $res) = @_;
Subroutine new: called CC=2 SCAR=6.9
Pod documented
20 9 ▶ my $self =
Branch: 1 branch
BranchTrueFalseTotal
ref $res ? : 6 3 9
21 ref $res
22 ? $res
23 : {
24 errors => [
25 { status => 500,
26 detail => 'Client could not connect'
27 }
28 ]
29 };
30 9 bless ($self, $class);
31 9 return $self;
32 }
33  
34 # Accessors
35  
36 8 ▶sub successful { return not exists shift->{errors} }
Subroutine successful: called CC=1 SCAR=0.0
Pod documented
37 4 ▶sub errors { return shift->{errors} }
Subroutine errors: called CC=1 SCAR=0.0
Pod documented
38  
39 6 1;
40  
41 __END__
42  
43 =pod
44  
45 =encoding utf8
46  
47 =head1 NAME
48  
49 WebService::AbuseIPDB::Response - Generic class for API responses
50  
51 =head1 SYNOPSIS
52  
53 Any of the WebService::AbuseIPDB methods which send a request to the
54 server will return an object of this class (or its children).
55  
56 use WebService::AbuseIPDB;
57  
58 my $ipdb = WebService::AbuseIPDB->new (key => 'abc123...');
59 my $res = $ipdb->check (ip => '127.0.0.2');
60 unless ($res->successful) {
61 for my $err (@{$res->errors}) {
62 warn "Error $err->{status}: $err->{detail}\n";
63 }
64 die "Cannot continue.\n";
65 }
66  
67 =head1 SUBROUTINES/METHODS
68  
69 =head2 new
70  
71 my $res = WebService::AbuseIPDB::Response->new ($href);
72  
73 The constructor takes a hashref constructed from the JSON returned by
74 the API. If the argument is missing or not a reference it assumes a
75 catastrophic problem and sets the generic error code and message (500,
76 "Client could not connect");
77  
78 =head2 successful
79  
80 my $ok = $res->successful;
81  
82 Returns true if there were no errors, otherwise false.
83  
84 =head2 errors
85  
86 my $err = $res->errors;
87  
88 Returns a ref to an AoH of errors exactly as returned by the API.
89  
90 =head1 STABILITY
91  
92 This is currently alpha software. Be aware that both the internals and
93 the interface are liable to change.
94  
95 =head1 AUTHOR
96  
97 Pete Houston, C<< <cpan at openstrike.co.uk> >>
98  
99 =head1 SEE ALSO
100  
101 L<WebService::AbuseIPDB> for general use of the client,
102 L<Version 2 of the AbuseIPDB API|https://docs.abuseipdb.com/> for API
103 details/restrictions and L<WebService::AbuseIPDB::ReportResponse> and
104 L<WebService::AbuseIPDB::CheckResponse> for specific subclasses.
105  
106 =head1 LICENCE AND COPYRIGHT
107  
108 Copyright © 2020 Pete Houston
109  
110 This program is free software; you can redistribute it and/or modify
111 it under the terms of the GNU General Public License as published by
112 the Free Software Foundation; version 2 dated June, 1991 or at your option
113 any later version.
114  
115 This program is distributed in the hope that it will be useful,
116 but WITHOUT ANY WARRANTY; without even the implied warranty of
117 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
118 GNU General Public License for more details.
119  
120 A copy of the GNU General Public License is available in the source tree;
121 if not, write to the Free Software Foundation, Inc.,
122 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
123  
124 =cut
« AbuseIPDB/Category.pm ↑ Summary AbuseIPDB/BlacklistMember.pm »