| WebService-TagTheNet documentation | Contained in the WebService-TagTheNet distribution. |
WebService::TagTheNet - Retrieve tags using the tagthe.net REST API
use WebService::TagTheNet;
my $ttn = WebService::TagTheNet->new(count => 5);
my $result = $ttn->url('http://tagthe.net/');
print "Tags: ", join ", ", @{$result->{'topic'}};
WebService::TagTheNet - Retrieve tags using the tagthe.net REST API
The following methods can be used
new creates a new WebService::TagTheNet object.
If for some obscure reason you do not want to use the default http://tagthe.net/api/ URI, you can specify your own one here.
The agent string used for LWP::UserAgent. Defaults to
'WebService::TagTheNet v.'.$VERSION
Define the amount of topics/tags you'd like to receive. Defaults to 10.
Accepts a scalar and will pass that on to tagthe.net for analysis. It returns a hashref with the results (or croaks if something goes wrong).
Accepts an URL and will pass that on to tagthe.net for analysis. It returns a hashref with the results (or croaks if something goes wrong).
The hash with API results may contain any of these fields:
Please see http://www.tagthe.net/fordevelopers for more information.
Please report any bugs to http://rt.cpan.org/Ticket/Create.html?Queue=WebService::TagTheNet.
M. Blom, <blom@cpan.org>, http://menno.b10m.net/perl/
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
| WebService-TagTheNet documentation | Contained in the WebService-TagTheNet distribution. |
package WebService::TagTheNet; use strict; use Carp qw/croak/; use LWP::UserAgent; use XML::XPath; our $VERSION = '0.01'; sub new { my ($class, %args) = @_; my $self = bless ({}, ref ($class) || $class); $self->{'_opts'} = { uri => 'http://tagthe.net/api/', agent => 'WebService::TagTheNet v.'.$VERSION, count => 10, %args }; $self->{'_lwp'} = LWP::UserAgent->new(agent => $self->{'_opts'}->{'agent'}); return $self; } sub text { my ($self, $text) = @_; croak "No text found" unless($text); return $self->_post('text', $text); } sub url { my ($self, $url) = @_; croak "No URL found" unless($url); return $self->_post('url', $url); } sub _post { my ($self, $k, $v) = @_; my $status = $self->{'_lwp'}->post( $self->{'_opts'}->{'uri'}, { $k => $v, count => $self->{'_opts'}->{'count'} } ); croak ("Can't connect to ", $self->{'_opts'}->{'uri'},": ", $status->status_line) unless($status->is_success); return $self->_xml2hash($status->content); } sub _xml2hash { my ($self, $xml) = @_; my %result = (); my $xp = XML::XPath->new(xml => $xml); my $nodeset = $xp->find('/memes/meme/dim'); foreach my $node ($nodeset->get_nodelist) { my $type = $node->getAttribute('type'); foreach my $child ($node->getChildNodes) { next unless(ref $child eq 'XML::XPath::Node::Element'); push @{$result{$type}}, $child->string_value; } } return \%result; } #################### main pod documentation begin ###################
#################### main pod documentation end ################### 1;