NAME

App::Wubot::Util::WebFetcher - fetch content from the web

VERSION

version 0.3.8

SYNOPSIS

use App::Wubot::Util::WebFetcher;

has 'fetcher' => ( is  => 'ro',
                   isa => 'App::Wubot::Util::WebFetcher',
                   lazy => 1,
                   default => sub {
                       return App::Wubot::Util::WebFetcher->new();
                   },
               );

my $content;
eval {                          # try
    $content = $self->fetcher->fetch( $config->{url}, $config );
    1;
} or do {                       # catch
    my $error = $@;
    my $subject = "Request failure: $error";
    $self->logger->error( $self->key . ": $subject" );
    return { cache => $cache, react => { subject => $subject } };
};

DESCRIPTION

Fetch data from a URL using LWP::UserAgent.

This utility class is designed to be used by wubot plugins in the classes App::Wubot::Plugin and App::Wubot::Reactor.

SUBROUTINES/METHODS

$obj->fetch( $url, $config );

Fetches content from the specified URL.

If the fetch attempt fails, then this method will die with the error message. Plugins that wish to use this library should wrap the fetch() method in an eval block (see the example above).

The data fetched will be passed to utf8::encode().

The 'config' may contain the following settings:

timeout

Number of seconds before the fetch times out. Defaults to 20 seconds.

agent

The user agent string. Defaults to 'Mozilla/6.0'.

user

User id for basic auth. See also 'pass'

pass

Password for basic auth. See also 'user'.

proxy

The proxy URL.

decompress

If true, sets the Accept-Encoding using HTTP::message::decodable.