File Coverage

blib/lib/Map/Tube/API/UserAgent.pm
Criterion Covered Total %
statement 20 30 66.6
branch 0 4 0.0
condition n/a
subroutine 7 9 77.7
pod 2 2 100.0
total 29 45 64.4


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