Skip to content

Commit

Permalink
updated tests to skip. updated docs to show our lack of confidence in…
Browse files Browse the repository at this point in the history
… the service
  • Loading branch information
genio committed Mar 13, 2016
1 parent 63831d8 commit 5ed1989
Show file tree
Hide file tree
Showing 9 changed files with 171 additions and 49 deletions.
128 changes: 107 additions & 21 deletions MANIFEST.SKIP
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,132 @@
\bRCS\b
\bCVS\b
,v$
,B$
,D$
\B\.svn\b
\B\.cvsignore$
\B\.git\b
\B\.gitignore$
\B\.bzr\b
\B\.bzrignore$

# Avoid Makemaker generated and utility files.
\bMakefile$
\bblib
\bMakeMaker-\d
\bpm_to_blib$
\bblibdirs$
^blib/
^blibdirs$
^blibdirs\.ts$
^bpm_to_blib\.ts$
^Makefile$
^Makefile\.old$
^MakeMaker-\d
^MANIFEST\.bak$
^MANIFEST\.SKIP$
^MYMETA\.
^pm_to_blib$
^pod2htm.*

# Avoid VMS specific Makmaker generated files
# Module::Build
^Build$
^_build/
^Build.bat$
^Build.COM$
^BUILD.COM$
^build.com$

# Author Extras
^inc/.*\.pod$
^pkg/
# ^xt/
^dist.ini$

# Editors
~$
\#$
\b\.#
\.kpf$
\.sw[pmno]$
^\.vimrc$

# OS X
^\.DS_Store$
^\.Trash/
\B\._

# VMS
\bDescrip.MMS$
\bDESCRIP.MMS$
\bdescrip.mms$

# Avoid Module::Build generated and utility files.
\bBuild$
\bBuild.bat$
\b_build
\bBuild.COM$
\bBUILD.COM$
\bbuild.com$
# Development
^benchmarks/
^core$
^cover_db\b
^nytprof\b
^covered\b
^debian/
^devel\.
^.devel-local$
^out$
^tmon.out$

# Author Notes
^notes
^todo
^ToDo$

# Common Junk Files
\.bak$
\.diff$
^foo\b.*
\.old$
\.orig$
\.patch$
\.rej$
\.tdy$
\.tmp$
^\w$
\.ttc$
\.pmc$

# Distribution tarballs
^[^/]+\.tar\.gz$

# Avoid Devel::Cover generated files
\bcover_db
# Travis CI
.travis.yml
.perltidyrc

# Avoid temp and backup files.
~$
\.tmp$
\.old$
\.bak$
\#$
\.#
\.rej$

# Avoid OS-specific files/dirs
# Mac OSX metadata
\B\.DS_Store
# Mac OSX SMB mount metadata files
\B\._

# Avoid archives of this distribution
\bWWW-Shorten-SnipURL-[\d\.\_]+
\.gz$
\.ppd$
\.ppmx$
\.tgz$
\.deb$
\bdebian
\bDebian_CPANTS.txt$
-stamp$

# Avoid Eclipse files
.cproject
.includepath
.project
.settings

# Avoid distdir
\d+\.\d+\b
^MYMETA.yml$
^MYMETA\.json$

# Avoid compiler artifacts
\bcompilet
\btest-
\.exe$
\.o$
2 changes: 1 addition & 1 deletion META.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"abstract" : "Perl interface to SnipURL.com",
"abstract" : "Perl interface to L<http://SnipURL.com>",
"author" : [
"Shashank Tripathi <shank@shank.com>"
],
Expand Down
2 changes: 1 addition & 1 deletion Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use 5.006;
use ExtUtils::MakeMaker;

my %WriteMakefileArgs = (
"ABSTRACT" => "Perl interface to SnipURL.com",
"ABSTRACT" => "Perl interface to L<http://SnipURL.com>",
"AUTHOR" => "Shashank Tripathi <shank\@shank.com>",
"CONFIGURE_REQUIRES" => {
"ExtUtils::MakeMaker" => 0
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ $long_url = makealongerlink($short_url);

# DESCRIPTION

**WARNING:** [http://shorl.com](http://shorl.com) does not provide an API. We must scrape the
resulting HTML.

- Also, their service has been up and down quite a bit lately. We have disabled live tests due to this.
- You have been warned. We suggest using another [WWW::Shorten](https://metacpan.org/pod/WWW::Shorten) service.

A Perl interface to the web service [http://SnipURL.com](http://snipurl.com). The service maintains a
database of long URLs, each of which has a unique identifier or
nickname. For more features, please visit [http://snipurl.com/features](http://snipurl.com/features).
Expand Down
1 change: 1 addition & 0 deletions dist.ini
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ perl = 5.006
strict = 0
warnings = 0
Carp = 0
HTTP::Request::Common = 0
WWW::Shorten = 3.08
URI = 0
Try::Tiny = 0
Expand Down
10 changes: 9 additions & 1 deletion lib/WWW/Shorten/SnipURL.pm
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ $VERSION = eval $VERSION;
sub makeashorterlink {
my $url = shift or Carp::croak('No URL passed to makeashorterlink');
my $ua = __PACKAGE__->ua();
my $snipurl = 'http://snipurl.com/site/index';
my $snipurl = 'http://wwww.snipurl.com/site/index';
my $req = POST $snipurl, [url => $url,];
my $resp
= try { return $ua->request($req); } catch { warn $_; return undef };
Expand Down Expand Up @@ -66,6 +66,14 @@ WWW::Shorten::SnipURL - Perl interface to L<http://SnipURL.com>
=head1 DESCRIPTION
B<WARNING:> L<http://snipurl.com> does not provide an API. We must scrape the
resulting HTML.
* Also, their service has been up and down quite a bit lately. We have disabled
live tests due to this.
* You have been warned. We suggest using another L<WWW::Shorten> service.
A Perl interface to the web service L<http://SnipURL.com>. The service maintains a
database of long URLs, each of which has a unique identifier or
nickname. For more features, please visit L<http://snipurl.com/features>.
Expand Down
4 changes: 0 additions & 4 deletions t/98pod-coverage.t

This file was deleted.

6 changes: 0 additions & 6 deletions t/99pod.t

This file was deleted.

61 changes: 46 additions & 15 deletions t/snipurl.t
Original file line number Diff line number Diff line change
@@ -1,23 +1,54 @@
use Test::More tests => 7;
use strict;
use warnings;
use Test::More;
use Try::Tiny qw(try catch);

BEGIN { use_ok WWW::Shorten::SnipURL };
BEGIN { use_ok('WWW::Shorten::SnipURL') or BAIL_OUT("Can't use!") };
can_ok('WWW::Shorten::SnipURL', qw(makealongerlink makeashorterlink));
can_ok('main', qw(makealongerlink makeashorterlink));

my $url = 'http://code.mag-sol.com/WWW-Shorten/WWW-Shorten.1.95.tar.gz';
my $code;
my $prefix_RE = qr{http://sn(?:ip)?url\.com/};
my $prefix = 'http://snipurl.com/';
my $shortened = makeashorterlink($url);

if ($shortened =~ m|\Q$prefix\E(\w+)|) {
$code = $1;
{ # blank call errors
my $err = try { makeashorterlink() } catch { "no dice: $_" };
like($err, qr/^no dice/, 'makeashorterlink: error on empty call');
$err = undef;

$err = try { makeashorterlink() } catch { "no dice: $_" };
like($err, qr/^no dice/, 'makealongerlink: error on empty call');
}

like ( $shortened, qr/$prefix_RE$code/, 'make it shorter');
is ( makealongerlink($prefix.$code), $url, 'make it longer');
is ( makealongerlink($code), $url, 'make it longer by Id',);
is ( makealongerlink($shortened), $url, 'make it long with what we were given');
SKIP: {
skip "Can't run live tests", 10;
my $err;
my $shortened = try { makeashorterlink($url) } catch { $err=$_; undef };
is($err,undef, "makeashorterlink: no errors");
skip "Got an error trying to shorten", 9 if $err;
ok($shortened, "makeashorterlink: got a response");
skip "Got no shortened response", 8 unless $shortened;
like($shortened, qr{^http://sn(?:ip)?url\.com/\w+$}, 'makeashorterlink: good url');

my $code;
if ($shortened =~ m{^http://sn(?:ip)?url\.com/(\w+)$}) {
$code = $1;
}
ok($code, "makeashorterlink: got a short code");

$err = undef;
my $longer = try { makealongerlink($prefix.$code) } catch { $err=$_; undef };
is($err, undef, "makealongerlink: whole - no errors");
is($longer,$url, "makealongerlink: whole - got back the URL");

$err = undef; $longer = undef;
$longer = try { makealongerlink($code) } catch { $err=$_; undef };
is($err, undef, "makealongerlink: code - no errors");
is($longer,$url, "makealongerlink: code - got back the URL");

$err = undef; $longer = undef;
$longer = try { makealongerlink($shortened) } catch { $err=$_; undef };
is($err, undef, "makealongerlink: shortened - no errors");
is($longer,$url, "makealongerlink: shortened - got back the URL");
}

eval { &makeashorterlink() };
ok($@);
eval { &makealongerlink() };
ok($@);
done_testing();

0 comments on commit 5ed1989

Please sign in to comment.