File Coverage

blib/lib/WebService/Wikimapia/UserAgent.pm
Criterion Covered Total %
statement 20 28 71.4
branch 0 4 0.0
condition n/a
subroutine 7 8 87.5
pod 1 1 100.0
total 28 41 68.2


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