| 1 | package IP::Info; | ||||||||||
| 2 | |||||||||||
| 3 | 6 | $IP::Info::VERSION = '0.16'; | |||||||||
| 4 | 6 | $IP::Info::AUTHOR = 'cpan:MANWAR'; | |||||||||
| 5 | |||||||||||
| 6 | =head1 NAME | ||||||||||
| 7 | |||||||||||
| 8 | IP::Info - Interface to IP geographic and network data. | ||||||||||
| 9 | |||||||||||
| 10 | =head1 VERSION | ||||||||||
| 11 | |||||||||||
| 12 | Version 0.16 | ||||||||||
| 13 | |||||||||||
| 14 | =cut | ||||||||||
| 15 | |||||||||||
| 16 | 6 | ▶ | use JSON; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | 6 | ▶ | use Data::Dumper; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | |||||||||||
| 19 | 6 | ▶ | use IP::Info::Response; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | 6 | ▶ | use IP::Info::Response::Network; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | 6 | ▶ | use IP::Info::Response::Location; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | 6 | ▶ | use IP::Info::UserAgent; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 23 | 6 | ▶ | use IP::Info::UserAgent::Exception; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 24 | |||||||||||
| 25 | 6 | ▶ | use Digest::MD5 qw(md5_hex); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 26 | 6 | ▶ | use Data::Validate::IP qw(is_ipv4); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 27 | |||||||||||
| 28 | 6 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 29 | 6 | ▶ | use namespace::clean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 30 | 6 | extends 'IP::Info::UserAgent'; | |||||||||
| 31 | |||||||||||
| 32 | 2 | ▶ | has 'base_url' => (is => 'ro', default => sub { return 'http://api.quova.com/v1/ipinfo'; }); | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 33 | |||||||||||
| 34 | =head1 DESCRIPTION | ||||||||||
| 35 | |||||||||||
| 36 | Quova RESTful API provides the geographic location & network data for any Internet | ||||||||||
| 37 | Protocol address in the public address space. The information includes: | ||||||||||
| 38 | |||||||||||
| 39 | =over 5 | ||||||||||
| 40 | |||||||||||
| 41 | =item * Postal code, city, state, region, country, and continent | ||||||||||
| 42 | |||||||||||
| 43 | =item * Area code (US and Canada only) and time zone | ||||||||||
| 44 | |||||||||||
| 45 | =item * Longitude and latitude | ||||||||||
| 46 | |||||||||||
| 47 | =item * DMA (Designated Market Area) and MSA (Metropolitan Statistical Area) | ||||||||||
| 48 | |||||||||||
| 49 | =item * Network information, including type, speed, carrier, and registering | ||||||||||
| 50 | organization | ||||||||||
| 51 | |||||||||||
| 52 | =back | ||||||||||
| 53 | |||||||||||
| 54 | To obtain your Quova API key and the shared secret, register your application L<here|http://developer.quova.com>. | ||||||||||
| 55 | |||||||||||
| 56 | =head1 CONSTRUCTOR | ||||||||||
| 57 | |||||||||||
| 58 | The constructor requires the following parameters as listed below: | ||||||||||
| 59 | |||||||||||
| 60 | +---------+----------+----------------------------------------+ | ||||||||||
| 61 | | Key | Required | Description | | ||||||||||
| 62 | +---------+----------+----------------------------------------+ | ||||||||||
| 63 | | api_key | Yes | API Key given by Quova. | | ||||||||||
| 64 | | secret | Yes | Allocated share secret given by Quova. | | ||||||||||
| 65 | +---------+----------+----------------------------------------+ | ||||||||||
| 66 | |||||||||||
| 67 | use strict; use warnings; | ||||||||||
| 68 | use IP::Info; | ||||||||||
| 69 | |||||||||||
| 70 | my $api_key = 'Your_API_Key'; | ||||||||||
| 71 | my $secret = 'Your_shared_secret'; | ||||||||||
| 72 | my $info = IP::Info->new({ api_key => $api_key, secret => $secret }); | ||||||||||
| 73 | |||||||||||
| 74 | =head1 METHODS | ||||||||||
| 75 | |||||||||||
| 76 | =head2 ip_address($ip_address) | ||||||||||
| 77 | |||||||||||
| 78 | If an IP address is specified in the correct format, then the call returns an | ||||||||||
| 79 | object of type L<IP::Info::Response> object which can be queried further to look | ||||||||||
| 80 | for specific information for that IP. In case it encounters any error it'll throw | ||||||||||
| 81 | an exception. | ||||||||||
| 82 | |||||||||||
| 83 | =over 2 | ||||||||||
| 84 | |||||||||||
| 85 | =item * dot-decimal e.g. 4.2.2.2 | ||||||||||
| 86 | |||||||||||
| 87 | =item * decimal notation e.g. 67240450 | ||||||||||
| 88 | |||||||||||
| 89 | =back | ||||||||||
| 90 | |||||||||||
| 91 | use strict; use warnings; | ||||||||||
| 92 | use IP::Info; | ||||||||||
| 93 | |||||||||||
| 94 | my $api_key = 'Your_API_Key'; | ||||||||||
| 95 | my $secret = 'Your_shared_secret'; | ||||||||||
| 96 | my $info = IP::Info->new({ api_key => $api_key, secret => $secret }); | ||||||||||
| 97 | my $response = $info->ip_address('4.2.2.2'); | ||||||||||
| 98 | |||||||||||
| 99 | print "Carrier: ", $response->network->carrier , "\n"; | ||||||||||
| 100 | print "Country: ", $response->location->country, "\n"; | ||||||||||
| 101 | |||||||||||
| 102 | =cut | ||||||||||
| 103 | |||||||||||
| 104 | sub ip_address { | ||||||||||
| 105 | 3 | ▶ | my ($self, $ip) = @_; | ||||||||
|
Subroutine
ip_address: called CC=3 SCAR=13.5
Pod
documented
| |||||||||||
| 106 | |||||||||||
| 107 | 3 | ▶ | die ("ERROR: Missing parameter IP Address.") unless defined $ip; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 108 | 2 | ▶ | die ("ERROR: Invalid IP Address [$ip].") unless is_ipv4($ip); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 109 | |||||||||||
| 110 | 0 | my $url = sprintf("%s/%s?apikey=%s&sig=%s&format=json", $self->base_url(), $ip, $self->api_key, $self->_sig()); | |||||||||
| 111 | 0 | my $response = $self->get($url); | |||||||||
| 112 | 0 | my $content = from_json($response->{content}); | |||||||||
| 113 | |||||||||||
| 114 | return IP::Info::Response->new({ | ||||||||||
| 115 | ip_address => $content->{ipinfo}->{ip_address}, | ||||||||||
| 116 | ip_type => $content->{ipinfo}->{ip_type}, | ||||||||||
| 117 | network => IP::Info::Response::Network->new($content->{ipinfo}->{Network}), | ||||||||||
| 118 | location => IP::Info::Response::Location->new($content->{ipinfo}->{Location}) | ||||||||||
| 119 | 0 | }); | |||||||||
| 120 | } | ||||||||||
| 121 | |||||||||||
| 122 | =head2 schema($file_name) | ||||||||||
| 123 | |||||||||||
| 124 | Saves the XML Schema Document in the given file (.xsd file).In case it encounters | ||||||||||
| 125 | any error it will throw an exception. | ||||||||||
| 126 | |||||||||||
| 127 | use strict; use warnings; | ||||||||||
| 128 | use IP::Info; | ||||||||||
| 129 | |||||||||||
| 130 | my $api_key = 'Your_API_Key'; | ||||||||||
| 131 | my $secret = 'Your_shared_secret'; | ||||||||||
| 132 | my $info = IP::Info->new({ api_key => $api_key, secret => $secret }); | ||||||||||
| 133 | $info->schema('User_supplied_filename.xsd'); | ||||||||||
| 134 | |||||||||||
| 135 | =cut | ||||||||||
| 136 | |||||||||||
| 137 | sub schema { | ||||||||||
| 138 | 1 | ▶ | my ($self, $file) = @_; | ||||||||
|
Subroutine
schema: called CC=3 SCAR=18.7
Pod
documented
| |||||||||||
| 139 | |||||||||||
| 140 | 1 | ▶ | die ("ERROR: Please supply the file name for the schema document.") unless defined $file; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 141 | |||||||||||
| 142 | 0 | my $url = sprintf("%s/schema?apikey=%s&sig=%s", $self->base_url(), $self->api_key, $self->_sig()); | |||||||||
| 143 | 0 | my $response = $self->get($url); | |||||||||
| 144 | |||||||||||
| 145 | 0 | ▶ | open(SCHEMA, ">$file") or die ("ERROR: Couldn't open file [$file] for writing: [$!]"); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 146 | 0 | print SCHEMA $response->{content}; | |||||||||
| 147 | 0 | close(SCHEMA); | |||||||||
| 148 | } | ||||||||||
| 149 | |||||||||||
| 150 | sub _sig { | ||||||||||
| 151 | 0 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
_sig: not called CC=1 SCAR=6.9
| |||||||||||
| 152 | |||||||||||
| 153 | 0 | my $time = time; | |||||||||
| 154 | 0 | return md5_hex($self->api_key . $self->secret . $time); | |||||||||
| 155 | } | ||||||||||
| 156 | |||||||||||
| 157 | =head1 AUTHOR | ||||||||||
| 158 | |||||||||||
| 159 | Mohammad S Anwar, C<< <mohammad.anwar at yahoo.com> >> | ||||||||||
| 160 | |||||||||||
| 161 | =head1 REPOSITORY | ||||||||||
| 162 | |||||||||||
| 163 | L<https://github.com/manwar/IP-Info> | ||||||||||
| 164 | |||||||||||
| 165 | =head1 BUGS | ||||||||||
| 166 | |||||||||||
| 167 | Please report any bugs or feature requests to C<bug-ip-info at rt.cpan.org> or | ||||||||||
| 168 | through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=IP-Info>. | ||||||||||
| 169 | I will be notified and then you'll automatically be notified of progress on your | ||||||||||
| 170 | bug as I make changes. | ||||||||||
| 171 | |||||||||||
| 172 | =head1 SUPPORT | ||||||||||
| 173 | |||||||||||
| 174 | You can find documentation for this module with the perldoc command. | ||||||||||
| 175 | |||||||||||
| 176 | perldoc IP::Info | ||||||||||
| 177 | |||||||||||
| 178 | You can also look for information at: | ||||||||||
| 179 | |||||||||||
| 180 | =over 4 | ||||||||||
| 181 | |||||||||||
| 182 | =item * RT: CPAN's request tracker | ||||||||||
| 183 | |||||||||||
| 184 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=IP-Info> | ||||||||||
| 185 | |||||||||||
| 186 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||
| 187 | |||||||||||
| 188 | L<http://annocpan.org/dist/IP-Info> | ||||||||||
| 189 | |||||||||||
| 190 | =item * CPAN Ratings | ||||||||||
| 191 | |||||||||||
| 192 | L<http://cpanratings.perl.org/d/IP-Info> | ||||||||||
| 193 | |||||||||||
| 194 | =item * Search CPAN | ||||||||||
| 195 | |||||||||||
| 196 | L<http://search.cpan.org/dist/IP-Info/> | ||||||||||
| 197 | |||||||||||
| 198 | =back | ||||||||||
| 199 | |||||||||||
| 200 | =head1 LICENSE AND COPYRIGHT | ||||||||||
| 201 | |||||||||||
| 202 | Copyright (C) 2011 - 2016 Mohammad S Anwar. | ||||||||||
| 203 | |||||||||||
| 204 | This program is free software; you can redistribute it and/or modify it under | ||||||||||
| 205 | the terms of the the Artistic License (2.0). You may obtain a copy of the full | ||||||||||
| 206 | license at: | ||||||||||
| 207 | |||||||||||
| 208 | L<http://www.perlfoundation.org/artistic_license_2_0> | ||||||||||
| 209 | |||||||||||
| 210 | Any use, modification, and distribution of the Standard or Modified Versions is | ||||||||||
| 211 | governed by this Artistic License.By using, modifying or distributing the Package, | ||||||||||
| 212 | you accept this license. Do not use, modify, or distribute the Package, if you do | ||||||||||
| 213 | not accept this license. | ||||||||||
| 214 | |||||||||||
| 215 | If your Modified Version has been derived from a Modified Version made by someone | ||||||||||
| 216 | other than you,you are nevertheless required to ensure that your Modified Version | ||||||||||
| 217 | complies with the requirements of this license. | ||||||||||
| 218 | |||||||||||
| 219 | This license does not grant you the right to use any trademark, service mark, | ||||||||||
| 220 | tradename, or logo of the Copyright Holder. | ||||||||||
| 221 | |||||||||||
| 222 | This license includes the non-exclusive, worldwide, free-of-charge patent license | ||||||||||
| 223 | to make, have made, use, offer to sell, sell, import and otherwise transfer the | ||||||||||
| 224 | Package with respect to any patent claims licensable by the Copyright Holder that | ||||||||||
| 225 | are necessarily infringed by the Package. If you institute patent litigation | ||||||||||
| 226 | (including a cross-claim or counterclaim) against any party alleging that the | ||||||||||
| 227 | Package constitutes direct or contributory patent infringement,then this Artistic | ||||||||||
| 228 | License to you shall terminate on the date that such litigation is filed. | ||||||||||
| 229 | |||||||||||
| 230 | Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND | ||||||||||
| 231 | CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED | ||||||||||
| 232 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR | ||||||||||
| 233 | NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS | ||||||||||
| 234 | REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, | ||||||||||
| 235 | INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE | ||||||||||
| 236 | OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||||||||
| 237 | |||||||||||
| 238 | =cut | ||||||||||
| 239 | |||||||||||
| 240 | 6 | 1; # End of IP::Info | |||||||||