Wednesday, October 19, 2005

Tagyu Perl API


Tagyu is a service that can suggest you tags relevant to your content. They have a REST interface available so I quickly rolled up a simple Perl wrapper over it.

Simple to use

Using Tagyu Web Service from Perl is now very simple and all you need to do is:

use Tagyu::Search;

my @tags = Tagyu::Search->SuggestTags("[PUT YOUR TEXT HERE]");

SuggestTags method returns an array of strings containing the tags received from Tagyu for the specified text using its REST API.

Passing options

You can also specify options to the SuggestTags method of Tagyu::Search module as key-value pairs to modify its behavior when it dispatches requests to the servers. Here's an example that sets the timeout parameter.

my @tags = Tagyu::Search->SuggestTags("[PUT YOUR TEXT HERE]",
(timeout => 600)
Tagyu::Search uses LWP::UserAgent behind the scenes. So for details of all supported options and their default values, please check the documentation of LWP::UserAgent's constructor.

Supports HTTP Basic Authentication

Tagyu imposes a limit of one request per minute from a single IP address and requests beyond this limit result in an error. However registered users have a soft cap of 1000 requests per day. Tagyu::Search package allows you to pass your username/password to Tagyu in the following manner:

# Instantiate a new Tagyu::Search object.
my $tagyu = Tagyu::Search->new(
username => "[YOUR-USERNAME]",
password => "[YOUR-PASSWORD]"

# Invoke the SuggestTags method on the Tagyu::Search object.
my @tags = $tagyu->SuggestTags("[YOUR-TEXT]");
You can register at Tagyu here.


Need Ideas?

For some ideas on what you can do with Tagyu::Search, have a look here.

Comments and suggestions are welcome

Before posting my module to CPAN I have sent an RFC for my Perl module on comp.lang.perl.modules USENET group. So download the latest relase of Tagyu::Search and give it a try. Please share your feedback! Thanks.


Adam Kalsey said...

Very cool. I've added a link to your module from the Tagyu tools page.

Sid said...

Thanks Adam! I hope some people would find this Perl module useful.

nmcfarl said...

I find this module useful -- I've integrated it with my Furl workflow and am very happy indeed. I would love to see it on CPAN.

As for the code - it looks great!

I did however make one alteration: On line 34 I added the parameters " timeout => 10, " to the constructor of LWP::UserAgent - as I was occasionally having excessive waits, for my usage senario.

Sid said...

Wow! I am so glad to hear that you find the module useful.

I'll add support for specifying a timeout value. Thanks!

Sid said...

@nmcfarl: I have incorporated support for specifying options to the LWP::UserAgent's constructor in the Tagyu::Search::SuggestTags method. Do let me know how it looks?

nmcfarl said...


It looks sweet. Much cleaner than adding the options elsewhere - or worse by hand as I did. And a drop in replacement for those who didn't hack the code by hand :)

I've updated my code. And published it on my blog, so you can see how I'm using it.

My only other note is that most web service interfaces that go on cpan, go in the Net:: namespace. So when you upload it :) , it should probably get a new name.

Sid said...

@nmcfarl: Now that SuggestTags method of Tagyu::Search accepts a hash of options and passes it onto the constructor of LWP::UserAgent, it should potentially be easier for you to modify the behavior of the module.

I just saw your script that uses Tagyu::Search. Looks cool!

I'll keep the naming convention pointed out by you in mind when preparing the module for uploading at CPAN. Thanks!