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