NAME
HTTP::Thin::UserAgent - A Thin UserAgent around some useful modules.
VERSION
version 0.016
SYNOPSIS
use HTTP::Thin::UserAgent;
my $favorites = http(GET 'http://api.metacpan.org/v0/author/PERIGRIN?join=favorite')->as_json->decoded_content;
my $results = http(GET 'http://www.imdb.com/find?q=Kevin+Bacon')->scraper(
scraper {
process '.findResult', 'results[]' => scraper {
process '.result_text', text => 'TEXT';
process '.result_text > a', link => '@href';
}
}
);
DESCRIPTION
HTTP::Thin::UserAgent
provides a layer over HTTP::Thin. It exposes an functional API that hopefully makes writing HTTP clients easier.
EXPORTS
- http
-
A function that returns a new
HTTP::Thin::UserAgent::Client
object, which does the actual work for the request. You pas in an HTTP::Request object. - GET / PUT / POST
-
Exports from HTTP::Request::Common to make generating HTTP::Request objects easier.
- scraper / process
-
Exports from Web::Scraper to assist in building scrapers for HTML documents.
METHODS
HTTP::Thin::UserAgent::Client
has the following methods.
- response( )
-
Returns the HTTP::Response object returned by HTTP::Thin
- as_json( $data )
-
This sets the request up to use
application/json
and then adds a decoder to decode the HTTP::Response content. If data is passed in it will be encoded into JSON and supplied in as the request data. - scraper( $scraper )
-
Sets up the request to process the response through the Web::Scraper object supplied. It will return the data (if any) returned by the scraper object.
- decoded_content( )
-
Returns the decoded content, currently we only support HTML (in which case we return scraped content) and JSON (in which case we decode the JSON using JSON::Any).
- tree( )
-
Returns a HTML::TreeBuilder::XPath object.
- find( $exp )
-
Takes a CSS or XPath expression and returns an arrayref of HTML::TreeBuilder::XPath nodes.
- on_error( $coderef )
-
A code reference that if there is an error in fetching the HTTP response handles that error.
$_
will be set to the error being handled. Exceptions are HTTP::Throwable objects for server side errors.
ENVIRONMENT
- TRACE
-
When set to true the
TRACE
variable will causeHTTP::Thin::UserAgent::Client
to emit dumps of the request and response objects as it processes them. This is to help you in debugging the HTTP requests.
AUTHOR
Chris Prather <chris@prather.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2013 by Chris Prather.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.