Permalink
Browse files

Fixed a new failure in testing. Yahoo! no longer permits shortening U…

…RLs which redirect with a 3xx HTTP response code.
  • Loading branch information...
1 parent b055e42 commit 0cbd6a49196aabadda34eccefbc0ac79eb054eae @cwimmer committed Oct 30, 2012
Showing with 54 additions and 6 deletions.
  1. +38 −0 README
  2. +10 −4 lib/WWW/Shorten/Yahooit.pm
  3. +6 −2 t/001_shorten.t
View
38 README
@@ -0,0 +1,38 @@
+NAME
+ WWW::Shorten::Yahooit - Perl interface to y.ahoo.it
+
+VERSION
+ version 0.003_01
+
+SYNOPSIS
+ use WWW::Shorten::Yahooit; use WWW::Shorten 'Yahooit';
+
+ $short_url = makeashorterlink($long_url);
+
+ $long_url = makealongerlink($short_url);
+
+ DESCRIPTION
+ This module uses YQL to create shortened URLs using the y.ahoo.it URL
+ shortening service from Yahoo!
+
+METHODS
+ makeashorterlink
+ The function makeashorterlink will do an insert on the yahoo.y.ahoo.it
+ table on the Yahoo! YQL service passing it your long URL and will return
+ the shorter version.
+
+ makealongerlink
+ The function makealongerlink will do an select on the yahoo.y.ahoo.it
+ table on the Yahoo! YQL service passing it your short URL and will
+ return the longer version.
+
+AUTHOR
+ Charles A. Wimmer <charles@wimmer.net>
+
+COPYRIGHT AND LICENSE
+ This software is Copyright (c) 2012 by Charles A. Wimmer.
+
+ This is free software, licensed under:
+
+ The (three-clause) BSD License
+
View
@@ -38,8 +38,11 @@ sub makeashorterlink{
my $yql = WWW::YQL->new();
my $data = $yql->query("insert into yahoo.y.ahoo.it (url) values ('".$url."')");
-
- return $data->{'query'}->{'results'}->{'url'};
+ if (defined $data->{'query'}->{'results'}->{'error'}){
+ die $data->{'query'}->{'results'}->{'error'};
+ }else{
+ return $data->{'query'}->{'results'}->{'url'};
+ }
}
=method makealongerlink
@@ -53,7 +56,10 @@ sub makealongerlink{
my $url = shift or croak 'No URL passed to makeashorterlink';
my $yql = WWW::YQL->new();
my $data = $yql->query("select * from yahoo.y.ahoo.it where url='".$url."'");
- return $data->{'query'}->{'results'}->{'url'};
-
+ if (defined $data->{'query'}->{'results'}->{'error'}){
+ die $data->{'query'}->{'results'}->{'error'};
+ }else{
+ return $data->{'query'}->{'results'}->{'url'};
+ }
}
1;
View
@@ -1,4 +1,4 @@
-use Test::More tests => 7;
+use Test::More tests => 8;
BEGIN { use_ok WWW::Shorten::Yahooit };
@@ -7,11 +7,15 @@ my $return = makeashorterlink($url);
is ( makeashorterlink($url), $return, 'make it shorter');
is ( makealongerlink($return), $url, 'make it longer');
-$url = 'http://wimmer.net/';
+$url = 'http://www.wimmer.net/';
$return = makeashorterlink($url);
is ( makeashorterlink($url), $return, 'make it shorter');
is ( makealongerlink($return), $url, 'make it longer');
+$url = 'http://wimmer.net/';
+eval { &makeashorterlink($url) };
+ok($@, 'makeashorterlink files with a 3xx URL');
+
eval { &makeashorterlink() };
ok($@, 'makeashorterlink fails with no args');
eval { &makealongerlink() };

0 comments on commit 0cbd6a4

Please sign in to comment.