blib/lib/MailboxValidator/SingleValidation.pm untested

filter: Statementstmt 0.0% 0 / 42 Branchbran 0.0% 0 / 6 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 62 CC 4 SCAR 13.5
CC
4
Cov
0%
ValidateEmail
6.0
DisposableEmail
6.0
FreeEmail
6.0
CRAP 3.8
1 # Copyright (c) 2023 MailboxValidator.com
2  
3 # Permission is hereby granted, free of charge, to any person obtaining a copy
4 # of this software and associated documentation files (the "Software"), to deal
5 # in the Software without restriction, including without limitation the rights
6 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 # copies of the Software, and to permit persons to whom the Software is
8 # furnished to do so, subject to the following conditions:
9  
10 # The above copyright notice and this permission notice shall be included in all
11 # copies or substantial portions of the Software.
12  
13 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 # SOFTWARE.
20  
21 package MailboxValidator::SingleValidation;
22  
23 use strict;
24 use vars qw(@ISA $VERSION @EXPORT);
25 use LWP::Simple;
26 use URI::Escape;
27 use JSON::PP;
28  
29 $VERSION = '2.00';
30  
31 require Exporter;
32 @ISA = qw(Exporter);
33  
34 sub Init
35 {
36 my ($class, $apikey) = @_;
37 my $self = {
38 api_key => $apikey
39 };
40 return bless $self, $class;
41 }
42  
43 sub ValidateEmail
44 {
45 my ($self, $email) = @_;
46 my $url = 'http://api.mailboxvalidator.com/v2/validation/single?key=' . uri_escape($self->{api_key}) . '&format=json&email=' . uri_escape($email);
47
48 my $contents = get($url);
49
50 if (defined($contents))
51 {
52 return decode_json $contents;
53 }
54 else
55 {
56 return; # error calling API
57 }
58 }
59  
60 sub DisposableEmail
61 {
62 my ($self, $email) = @_;
63 my $url = 'http://api.mailboxvalidator.com/v2/email/disposable?key=' . uri_escape($self->{api_key}) . '&format=json&email=' . uri_escape($email);
64
65 my $contents = get($url);
66
67 if (defined($contents))
68 {
69 return decode_json $contents;
70 }
71 else
72 {
73 return; # error calling API
74 }
75 }
76  
77 sub FreeEmail
78 {
79 my ($self, $email) = @_;
80 my $url = 'http://api.mailboxvalidator.com/v2/email/free?key=' . uri_escape($self->{api_key}) . '&format=json&email=' . uri_escape($email);
81
82 my $contents = get($url);
83
84 if (defined($contents))
85 {
86 return decode_json $contents;
87 }
88 else
89 {
90 return; # error calling API
91 }
92 }
93  
94 1;
95  
96 __END__