File Coverage

blib/lib/IP/Info/UserAgent.pm
Criterion Covered Total %
statement 17 25 68.0
branch 0 4 0.0
condition n/a
subroutine 6 7 85.7
pod 1 1 100.0
total 24 37 64.8


line stmt bran cond sub pod time code
1             package IP::Info::UserAgent;
2              
3             $IP::Info::UserAgent::VERSION = '0.16';
4             $IP::Info::UserAgent::AUTHORITY = 'cpan:MANWAR';
5              
6             =head1 NAME
7              
8             IP::Info::UserAgent - User agent for IP::Info.
9              
10             =head1 VERSION
11              
12             Version 0.16
13              
14             =cut
15              
16 6     6   132 use 5.006;
  6         50  
17 6     6   24 use Data::Dumper;
  6         9  
  6         269  
18              
19 6     6   4404 use HTTP::Tiny;
  6         247880  
  6         205  
20 6     6   2687 use IP::Info::UserAgent::Exception;
  6         13  
  6         226  
21              
22 6     6   35 use Moo;
  6         8  
  6         21  
23 6     6   1386 use namespace::clean;
  6         12  
  6         34  
24              
25             has 'api_key' => ( is => 'ro', required => 1 );
26             has 'secret' => ( is => 'ro', required => 1 );
27             has 'ua' => ( is => 'rw', default => sub { HTTP::Tiny->new(agent => "IP-Info/v1"); } );
28              
29             =head1 DESCRIPTION
30              
31             The helper library for L module.
32              
33             =head1 METHODS
34              
35             =head2 get()
36              
37             The method get() expects one parameter i.e. URL and returns the standard response.
38             On error throws exception of type L.
39              
40             =cut
41              
42             sub get {
43 0     0 1   my ($self, $url) = @_;
44              
45 0           my $ua = $self->ua;
46 0           my $response = $ua->request('GET', $url);
47              
48 0           my @caller = caller(1);
49 0 0         @caller = caller(2) if $caller[3] eq '(eval)';
50              
51 0 0         unless ($response->{success}) {
52             IP::Info::UserAgent::Exception->throw({
53             method => $caller[3],
54             message => "request to API failed",
55             code => $response->{status},
56             reason => $response->{reason},
57 0           filename => $caller[1],
58             line_number => $caller[2] });
59             }
60              
61 0           return $response;
62             }
63              
64             =head1 AUTHOR
65              
66             Mohammad S Anwar, C<< >>
67              
68             =head1 REPOSITORY
69              
70             L
71              
72             =head1 BUGS
73              
74             Please report any bugs or feature requests to C or
75             through the web interface at L.
76             I will be notified and then you'll automatically be notified of progress on your
77             bug as I make changes.
78              
79             =head1 SUPPORT
80              
81             You can find documentation for this module with the perldoc command.
82              
83             perldoc IP::Info
84              
85             You can also look for information at:
86              
87             =over 4
88              
89             =item * RT: CPAN's request tracker
90              
91             L
92              
93             =item * AnnoCPAN: Annotated CPAN documentation
94              
95             L
96              
97             =item * CPAN Ratings
98              
99             L
100              
101             =item * Search CPAN
102              
103             L
104              
105             =back
106              
107             =head1 LICENSE AND COPYRIGHT
108              
109             Copyright (C) 2011 - 2016 Mohammad S Anwar.
110              
111             This program is free software; you can redistribute it and/or modify it under
112             the terms of the the Artistic License (2.0). You may obtain a copy of the full
113             license at:
114              
115             L
116              
117             Any use, modification, and distribution of the Standard or Modified Versions is
118             governed by this Artistic License.By using, modifying or distributing the Package,
119             you accept this license. Do not use, modify, or distribute the Package, if you do
120             not accept this license.
121              
122             If your Modified Version has been derived from a Modified Version made by someone
123             other than you,you are nevertheless required to ensure that your Modified Version
124             complies with the requirements of this license.
125              
126             This license does not grant you the right to use any trademark, service mark,
127             tradename, or logo of the Copyright Holder.
128              
129             This license includes the non-exclusive, worldwide, free-of-charge patent license
130             to make, have made, use, offer to sell, sell, import and otherwise transfer the
131             Package with respect to any patent claims licensable by the Copyright Holder that
132             are necessarily infringed by the Package. If you institute patent litigation
133             (including a cross-claim or counterclaim) against any party alleging that the
134             Package constitutes direct or contributory patent infringement,then this Artistic
135             License to you shall terminate on the date that such litigation is filed.
136              
137             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND
138             CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
139             WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
140             NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS
141             REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT,
142             INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
143             OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
144              
145             =cut
146              
147             1; # End of IP::Info::UserAgent