Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the WWW-Shorten CPAN distribution.

Report information
The Basics
Id: 4354
Status: resolved
Priority: 0/
Queue: WWW-Shorten

People
Owner: spoon [...] cpan.org
Requestors: pjg [...] 1sl.net
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: Another Short Link Service
I put together a short link server (http://1sl.net). The attached patch file "works for me" for adding and retrieving URLs. Let me know if you have questions / problems. thanks. pj.
diff -Naur WWW-Shorten-1.87.orig/lib/WWW/Shorten/OneShortLink.pm WWW-Shorten-1.87/lib/WWW/Shorten/OneShortLink.pm --- WWW-Shorten-1.87.orig/lib/WWW/Shorten/OneShortLink.pm 1969-12-31 16:00:00.000000000 -0800 +++ WWW-Shorten-1.87/lib/WWW/Shorten/OneShortLink.pm 2003-11-10 18:21:10.000000000 -0800 @@ -0,0 +1,106 @@ +package WWW::Shorten::OneShortLink; + +use 5.006; +use strict; +use warnings; + +use base qw( WWW::Shorten::generic Exporter ); +our @EXPORT = qw(makeashorterlink makealongerlink); +our $VERSION = "1.81"; + +use Carp; + +sub makeashorterlink ($) +{ + my $url = shift or croak 'No URL passed to makeashorterlink'; + my $ua = __PACKAGE__->ua(); + + my $resp = $ua->post( 'http://1sl.net/', [ + rurl => $url, + ] ); +print $url, "\n"; + return unless $resp->is_success; + return if $resp->content =~ />Operation Failed!/; + if ($resp->content =~ m!your Short Link<[^>]*>\s*<[^>]*><a\s+href="[^"]+">(http://1sl.net/[^<]*)</a>!s) { + return $1; + } + + return; +} + +sub makealongerlink ($) +{ + my $short_url = shift + or croak '1 Short Link ID / URL passed to makealongerlink'; + my $ua = __PACKAGE__->ua(); + + $short_url = "http://1sl.net/$short_url" + unless $short_url =~ m!^http://!i; + + my $resp = $ua->get($short_url); + + return undef unless $resp->is_success; + + return undef + if $resp->content =~ m!That doesn\'t look like a Make A Shorter Link key.!; + + if ($resp->content =~ m!<meta HTTP-EQUIV="Refresh" CONTENT="[0-9]+\; URL=(.*)"!i) { + return $1; + } + + return undef unless $resp->is_redirect; + my $url = $resp->header('Location'); + return $url; + +} +1; + +__END__ + +=head1 NAME + +WWW::Shorten::OneShortLink - Perl interface to 1sl.net + +=head1 SYNOPSIS + + use WWW::Shorten::OneShortLink; + + use WWW::Shorten 'OneShortLink'; + + $short_url = makeashorterlink($long_url); + + $long_url = makealongerlink($short_url); + +=head1 DESCRIPTION + +A Perl interface to the web site 1sl.net. OneShortLink simply maintains +a database of long URLs, each of which has a unique identifier. + +The function C<makeashorterlink> will call the OneShortLink web site passing it +your long URL and will return the shorter OneShortLink version. + +The function C<makealongerlink> does the reverse. C<makealongerlink> +will accept as an argument either the full OneShortLink URL or just the +OneShortLink identifier. + +If anything goes wrong, then either function will return C<undef>. + +=head2 EXPORT + +makeashorterlink, makealongerlink + +=head1 SUPPORT, LICENCE, THANKS and SUCH + +See the main L<WWW::Shorten> docs. + +=head1 AUTHOR + +Iain Truskett <spoon@cpan.org> + +Based on WWW::MakeAShorterLink by Dave Cross <dave@dave.org.uk> + +=head1 SEE ALSO + +L<WWW::Shorten>, L<perl>, L<http://1sl.net/> + +=cut diff -Naur WWW-Shorten-1.87.orig/lib/WWW/Shorten.pm WWW-Shorten-1.87/lib/WWW/Shorten.pm --- WWW-Shorten-1.87.orig/lib/WWW/Shorten.pm 2003-09-07 07:05:34.000000000 -0700 +++ WWW-Shorten-1.87/lib/WWW/Shorten.pm 2003-11-10 17:47:10.000000000 -0800 @@ -56,6 +56,7 @@ use WWW::Shorten 'MakeAShorterLink'; use WWW::Shorten 'Metamark'; use WWW::Shorten 'NotLong'; + use WWW::Shorten 'OneShortLink'; use WWW::Shorten 'qURL'; use WWW::Shorten 'Shorl'; use WWW::Shorten 'ShortLink'; @@ -123,6 +124,7 @@ MakeAShorterLink http://makeashorterlink.com/ Metamark http://xrl.us/ NotLong http://notlong.com/ + OneShortLink http://1sl.net/ qURL http://qurl.net/ Shorl http://shorl.com/ ShortLink http://shortlink.us/
[guest - Mon Nov 10 21:47:18 2003]: Show quoted text
> I put together a short link server (http://1sl.net). The attached > patch file "works for me" for adding and retrieving URLs.
Nice work. I've just released WWW-Shorten 1.88, which includes your service =) cheers, -- Iain.