App-SpamcupNG
view release on metacpan or search on metacpan
lib/App/SpamcupNG/UserAgent.pm view on Meta::CPAN
if ( $self->_is_authenticated ) {
$logger->debug('Already authenticated');
$request = HTTP::Request->new( GET => $self->{domain} );
}
else {
if ($password) {
if ($is_basic) {
$request = HTTP::Request->new( GET => $self->{members_url} );
$request->authorization_basic( $id, $password );
}
else {
$request = POST $self->{form_login_url},
[
username => $id,
$self->{password_field} => $password,
duration => '+12h',
action => 'cookielogin',
returnurl => '/'
];
}
}
else {
$request =
HTTP::Request->new( GET => $self->{code_login_url} . $id );
}
}
$request->protocol('HTTP/1.1');
if ( $logger->is_debug() ) {
$logger->debug(
"Request details:\n" . ( $self->_redact_auth_req($request) ) );
}
my $response = $self->{user_agent}->request($request);
if ( $logger->is_debug() ) {
$logger->debug( "Got response:\n" . $response->as_string );
$logger->debug(
"After authentication cookies:\n" . $self->_dump_cookies );
}
return \( $response->content ) if ( $response->is_success );
my $status = $response->status_line();
if ( $response->code() == 500 ) {
$logger->die("Can\'t connect to server: $status");
}
else {
$logger->warn($status);
if ( ($password) and ( $is_basic == 0 ) ) {
$logger->warn('Retrying with basic authentication');
return $self->login( $id, $password, 1 );
}
$logger->die(
'Cannot connect to server or invalid credentials. Please verify your username and password and try again.'
);
}
return undef;
}
=head2 spam_report
Fetches a SPAM report.
Expects as parameter a report ID.
Returns the HTML content as a scalar reference.
=cut
sub spam_report {
my ( $self, $report_id ) = @_;
my $logger = get_logger('SpamcupNG');
my $request = HTTP::Request->new( GET => $self->{report_url} . $report_id );
if ( $logger->is_debug ) {
$logger->debug( "Request to be sent:\n" . $request->as_string );
}
my $response = $self->{user_agent}->request($request);
$self->{current_base_url} = $response->base;
if ( $logger->is_debug ) {
$logger->debug( "Got HTTP response:\n" . $response->as_string );
}
unless ( $response->is_success ) {
$logger->die("Can't connect to server. Try again later.");
}
return \( $response->content );
}
=head2 base
Returns the current base URL provided by the last response of getting a SPAM
report.
=cut
sub base {
my $self = shift;
return $self->{current_base_url};
}
=head2 complete_report
Complete the SPAM report, by confirming it's information is OK.
Returns the HTML content as a scalar reference.
=cut
sub complete_report {
( run in 1.365 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )