NAME

WWW::Shorten::ptl - interface to shorten URLs with http://p.tl/

SYNOPSIS

use WWW::Shorten::ptl ();

my $ptl = WWW::Shorten::ptl->new(apikey => $apikey);
my $res = $ptl->shorten($url);
my $shorturl = $res->{short_url} || die "failed to shorten $url";

my $longurl = $ptl->extract($shorturl);

or

use WWW::Shorten::ptl;

my $shorturl = makeashorterlink($url, 'API-Key');
my $url = makealongerlink($shorturl);

DESCRIPTION

WWW::Shorten::ptl provides interface to shorten URLs using http://p.tl/.

API KEY

As p.tl requires API-Key for each access using its APIs, you should apply your API-Key for p.tl to shorten URLs with this module.

you can get API-Key for p.tl at http://p.tl/key_create.php.

API-Key is required only for shortening URLs. URL extraction service doesn't need API-Key

OO INTERFACE

new([apikey => API-Key])

creates an instance of WWW::Shorten::ptl with given API-Key.

$obj->apikey([API-Key])

set or get API-Key for this instance.

$obj->shorten($url)

shorten $url, and returns HASHREF with following keys.

status    -- see 'RESULT STATUS' section
long_url  -- given (original) url
short_url -- shortened url
counter   -- # of requests in a period. (currently, api request is limited to 1000 calls/day)

dies if no API-Key is set.

RESULT STATUS

the 'status' should be one of below.

'ok'							-- url is successfully shortened 
'empty long url'	-- input url is empty (should not occur when using this module)
'empty API key'		-- API key is not specified (ditto.)
'API limit'				-- request limit exceeded.
'invalid API key' -- given API key is invalid
'invalid long url'-- given url cannot be shortened (that url may be already shortened)

$obj->extract($url)

returns extracted $url. or undef when $url is not a form of p.tl.

FUNCTION INTERFACE

As mentioned above, additional parameter API-Key is required for each shorten/expand functions.

makeashorterlink($url, API-Key)

returns shortened url. or undef when failed to shorten url.

makealongerlink($url)

returns expanded url for $url or undef when $url is not a form of p.tl

AUTHOR

turugina <turugina {at} cpan.org>

SEE ALSO

WWW::Shorten http://p.tl/ http://dev.pixiv.net/archives/1156026.html

LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.