| 1 | #! /bin/false | ||
| 2 | |||
| 3 | # Copyright (C) 2016-2018 Guido Flohr <guido.flohr@cantanea.com>, | ||
| 4 | # all rights reserved. | ||
| 5 | |||
| 6 | # This program is free software: you can redistribute it and/or modify | ||
| 7 | # it under the terms of the GNU General Public License as published by | ||
| 8 | # the Free Software Foundation; either version 3 of the License, or | ||
| 9 | # (at your option) any later version. | ||
| 10 | |||
| 11 | # This program is distributed in the hope that it will be useful, | ||
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | # GNU General Public License for more details. | ||
| 15 | |||
| 16 | # You should have received a copy of the GNU General Public License | ||
| 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 18 | |||
| 19 | package Qgoda::Repository::Fetcher::LWP; | ||
| 20 | $Qgoda::Repository::Fetcher::LWP::VERSION = 'v0.9.2'; | ||
| 21 | use strict; | ||
| 22 | |||
| 23 | use Locale::TextDomain qw(qgoda); | ||
| 24 | use LWP::UserAgent; | ||
| 25 | use File::Temp; | ||
| 26 | |||
| 27 | use Qgoda; | ||
| 28 | use Qgoda::Util qw(archive_extender); | ||
| 29 | |||
| 30 | use base qw(Qgoda::Repository::Fetcher::File); | ||
| 31 | |||
| 32 | sub fetch { | ||
| 33 | my ($self, $uri, $destination) = @_; | ||
| 34 | |||
| 35 | my $logger = Qgoda->new->logger; | ||
| 36 | |||
| 37 | # FIXME! More configuration option needed here. | ||
| 38 | my $ua = LWP::UserAgent->new; | ||
| 39 | $ua->timeout(10); | ||
| 40 | $ua->env_proxy; | ||
| 41 | $ua->show_progress(1); | ||
| 42 | |||
| 43 | $logger->info(__x("downloading '{uri}' with lwp-perl"), uri => $uri); | ||
| 44 | |||
| 45 | my $response = $ua->get($uri); | ||
| 46 | $logger->fatal(__x("error downloading '{uri}': {error}", | ||
| 47 | uri => $$uri, | ||
| 48 | error => $response->status_line)) | ||
| 49 | if $response->is_error; | ||
| 50 | |||
| 51 | my $fh = File::Temp->new(SUFFIX => archive_extender $uri->path); | ||
| 52 | my $path = $fh->filename; | ||
| 53 | |||
| 54 | # Leave errors to the extractor. | ||
| 55 | print $fh $response->decoded_content; | ||
| 56 | |||
| 57 | return $self->_extractArchive($path, $destination); | ||
| 58 | } | ||
| 59 | |||
| 60 | 1; |