| 1 | package WebService::IPStack; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 6 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 6 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 6 | ▶ | use strictures 2; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 6 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 6 | ▶ | use Carp qw(confess); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 6 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 6 | ▶ | use MooX::Enumeration; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 6 | ▶ | use Types::Standard qw(Str Enum); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 6 | with 'Role::REST::Client'; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | has api_key => ( | ||||||||||||||||||||||||||||
| 17 | 5 | ▶ | isa => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 18 | 5 | ▶ | confess "API key must be length of 32 characters!" if (length $_[0] != 32); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | }, | ||||||||||||||||||||||||||||
| 20 | 6 | is => 'rw', | |||||||||||||||||||||||||||
| 21 | required => 1 | ||||||||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | has api_plan => ( | ||||||||||||||||||||||||||||
| 25 | is => 'rw', | ||||||||||||||||||||||||||||
| 26 | isa => Enum[qw(free basic pro pro_plus)], | ||||||||||||||||||||||||||||
| 27 | handles => [qw/ is_free is_basic is_pro is_pro_plus /], | ||||||||||||||||||||||||||||
| 28 | 1 | ▶ | default => sub { 'free' }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | 6 | ); | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | has api_url => ( | ||||||||||||||||||||||||||||
| 32 | isa => Str, | ||||||||||||||||||||||||||||
| 33 | is => 'ro', | ||||||||||||||||||||||||||||
| 34 | 4 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 35 | 4 | ▶ | my $protocol = (shift->is_free) ? 'http' : 'https'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 4 | return qq|$protocol://api.ipstack.com/| | |||||||||||||||||||||||||||
| 37 | }, | ||||||||||||||||||||||||||||
| 38 | 6 | ); | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | ▶ | sub lookup { | ||||||||||||||||||||||||||
|
Subroutine
lookup: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 41 | 0 | my ($self, $ip, $params) = @_; | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 0 | return $self->_request($ip, $params); | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 0 | ▶ | sub bulk_lookup { | ||||||||||||||||||||||||||
|
Subroutine
bulk_lookup: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 47 | 0 | my ($self, $ips, $params) = @_; | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 0 | ▶ | confess "Expect an array of IP address" if (ref $ips ne 'ARRAY'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | if (!$self->is_pro || !$self->is_pro_plus) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->is_pro and $self->is_pro_plus
MC/DC0%0/2
$self->is_pro and $self->is_pro_plus
$self->is_pro
$self->is_pro_plus
Truth table0%0/3
A and B
A= $self->is_proB= $self->is_pro_plus
| |||||||||||||||||||||||||||||
| 52 | 0 | confess "Bulk IP lookup only for Business or Business Pro subscription plan" | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | my $endpoint = join(",", $ips); | |||||||||||||||||||||||||||
| 56 | 0 | return $self->_request($endpoint, $params); | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | sub check { | ||||||||||||||||||||||||||
|
Subroutine
check: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 60 | 0 | my ($self, $params) = @_; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | return $self->_request('check', $params); | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 0 | ▶ | sub _request { | ||||||||||||||||||||||||||
|
Subroutine
_request: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 66 | 0 | my ($self, $endpoint, $params) = @_; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | ▶ | if (exists($params->{security}) && !$self->is_business_pro) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $params->{"security"} and not $self->is_business_pro
MC/DC0%0/2
exists $params->{"security"} and not $self->is_business_pro
exists $params->{"security"}
not $self->is_business_pro
Truth table0%0/3
A and not(B)
A= exists $params->{"security"}B= not $self->is_business_pro
| |||||||||||||||||||||||||||||
| 69 | 0 | confess "Security data only for Business Pro subscription plan" | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | ▶ | my $format = exists($params->{output}) ? $params->{output} : 'json'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 0 | $self->set_persistent_header('User-Agent' => __PACKAGE__ . $WebService::IPStack::VERSION); | |||||||||||||||||||||||||||
| 75 | 0 | $self->server($self->api_url); | |||||||||||||||||||||||||||
| 76 | 0 | $self->type(qq|application/$format|); | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 0 | my $queries = { | |||||||||||||||||||||||||||
| 79 | access_key => $self->api_key | ||||||||||||||||||||||||||||
| 80 | }; | ||||||||||||||||||||||||||||
| 81 | 0 | ▶ | $queries = {%$queries, %$params} if (defined $params); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 0 | my $response = $self->get($endpoint, $queries); | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 0 | return $response->data; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 6 | 1; | |||||||||||||||||||||||||||
| 89 | __END__ | ||||||||||||||||||||||||||||