NAME
WWW::Spinn3r - An interface to the Spinn3r API (http://www.spinn3r.com)
SYNOPSIS
use WWW::Spinn3r;
use DateTime;
my $API = {
vendor => 'acme', # required
limit => 5,
lang => 'en',
tier => '0:5',
after => DateTime->now()->subtract(hours => 48),
};
my $spnr = new WWW::Spinn3r (
api => 'permalink3.getDelta', params => $API, debug => 1);
);
while(1) {
my $item = $spnr->next;
print $item->{title};
print $item->{link};
print $item->{dc}->{source};
print $item->{description};
}
DESCRIPTION
WWW::Spinn3r is an iterative interface to the Spinn3r API. The Spinn3r API is implemented over REST and XML and documented at http://spinn3r.com/documentation
.
OBTAINING A VENDOR KEY
Spinn3r service is available through a vendor key, which you can get from the good folks at Tailrank, http://spinn3r.com/contact
.
HOW TO USE
Most commonly, you'll need just two functions from this module: new()
and next()
. new()
creates a new instance of the API and next()
returns the next item from the Spinn3r feed, as hashref. Details are below.
new()
The contructor. This function takes a hash with the following keys:
- api
-
permalink3.getDelta
orfeed3.getDelta
, one of the two APIs provided by Spinn3r. - params
-
These are parameters that are passed to the API call. See
http://spinn3r.com/documentation
for a list of available parameters and their values.The version parameter to the API is a function of version of this module. and the version() accessor method returns the version of the API. By default, the version will be set to the version that corresponds to this module.
If the version of the spinn3r API has changed, you can specify it as a parameter. While the module is not guranteed to work with higher versions of the Spinn3r API than it is designed for, it might if the underlying formats and encodings have not changed.
- want
-
This parameter defines the type of item returned by the next() call. WWW::Spinn3r uses XML::Twig to parse the XML returned by Spinn3r and comes with three Twig parsers,
WWW::Spinn3r::item
,WWW::Spinn3r::link
andWWW::Spinn3r::next_request_url
. The default value forwant
isitem
, which corresponds to theWWW::Spinn3r::item
module and returns all fields for an item included in the Spinn3r feed.The motivation for having multiple parsers is speed. If you only want certain fields from the feed, for example the link and title, it is significantly faster to write a parser that just extracts those two fields from the feed with XML::Twig.
- debug
-
Emits debug noise on STDOUT if set to 1.
- retries
-
The number of HTTP retries in case of a 5xx failure from the API. The default is 5.
next()
This method returns the next item from the Spinn3r feed. The item is a reference to a hash, which contains the various fields of an item as parsed by the parser specified in the want
field of the consutructor (item
by default).
The module transparently fetches a new set of results from Spinn3r, using the api:next_request_url
returned by Spinn3r with every request, and caches the result to implement next()
.
You can control the number of results that are fetched with every call by changing the limit
parameter at new()
.
last_url()
The last API URL that was fetched.
mirror()
WWW::Spinn3r supports mirroring of the Spinn3r feed to local files and then recreating WWW:Spinn3r objects from these files. This is useful if you want to distribute processing of the feeds over multiple processes or computers.
To mirror feeds to disk, use the alternative constructor mirror, which takes all the same arguments as new plus the path
argument, which specifies where the files should saved.
my $m = mirror WWW::Spinn3r ( path => $mirror_dir, ... )
$m->next_mirror();
The iteration is done with next_mirror() method, which stores the next feed to a new file, whose filename is derived from the API url.
WWW::Spinn3r objects can be created from these disk files when new() is called with the from_file
key:
my $m = new WWW::Spinn3r ( from_file => ... );
DATE STRING FORMAT
Spinn3r supports ISO 8601 timestamps in the after
parameter. To create ISO 8601 timestamps, use the DateTime module that returns ISO 8601 date strings by default. eg:
after => DateTime->now()->subtract(hours => 48),
after => DateTime->now()->subtract(days => 31),
REPORTING BUGS
Bugs should be reported at http://rt.cpan.org
SEE ALSO
WWW::Spinn3r::Synced
AUTHOR
Vipul Ved Prakash <vipul@slaant.com>
LICENSE
This software is distributed under the same terms as perl itself.