Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Metamark is dead :-(
  • Loading branch information
davorg committed Sep 15, 2014
1 parent c811d01 commit 96dabb0
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 112 deletions.
2 changes: 1 addition & 1 deletion bin/shorten
Expand Up @@ -17,7 +17,7 @@ unless ($@) {
}

my $service = $args{service} || $ENV{SHORTEN_SERVICE} ||
$config->{service} || 'Metamark';
$config->{service} || 'TinyURL';
$service = "WWW::Shorten::$service";

# Import it
Expand Down
9 changes: 5 additions & 4 deletions lib/WWW/Shorten.pm
Expand Up @@ -8,7 +8,6 @@ WWW::Shorten - Interface to URL shortening sites.
use WWW::Shorten 'Linkz';
use WWW::Shorten 'MakeAShorterLink';
use WWW::Shorten 'Metamark';
use WWW::Shorten 'NotLong';
use WWW::Shorten 'OneShortLink';
use WWW::Shorten 'Shorl';
Expand All @@ -28,7 +27,7 @@ WWW::Shorten - Interface to URL shortening sites.
$long_url = makealongerlink($short_url);
# If you don't like the function names:
use WWW::Shorten 'Metamark', ':short';
use WWW::Shorten 'TinyURL', ':short';
$short_url = short_link( $long_url );
$long_url = long_link( $short_url );
Expand Down Expand Up @@ -58,9 +57,9 @@ use warnings;

use base qw(WWW::Shorten::generic);
our @EXPORT = qw(makeashorterlink makealongerlink);
our $VERSION = '3.05';
our $VERSION = '3.06';

our $DEFAULT_SERVICE = 'Metamark';
our $DEFAULT_SERVICE = 'TinyURL';

use Carp;

Expand Down Expand Up @@ -136,6 +135,8 @@ longer with us:
=item EkDk
=item Metamark
=item qURL (although the differently capitalised Qurl.com now uses their old domain)
=item ShortLink
Expand Down
88 changes: 6 additions & 82 deletions lib/WWW/Shorten/Metamark.pm
Expand Up @@ -6,18 +6,13 @@ WWW::Shorten::Metamark - Perl interface to metamark.net
=head1 SYNOPSIS
use WWW::Shorten::Metamark;
use WWW::Shorten 'Metamark';
$short_url = makeashorterlink($long_url);
$long_url = makealongerlink($short_url);
# No appropriate synopsis
=head1 DESCRIPTION
A Perl interface to the web site metamark.net. Metamark simply maintains
a database of long URLs, each of which has a unique identifier.
A Perl interface to the web site metamark.net.
From September 2014, Metamark is no longer accepting new URLs.
=cut

Expand All @@ -27,79 +22,8 @@ use 5.006;
use strict;
use warnings;

use base qw( WWW::Shorten::generic Exporter );
our @EXPORT = qw(makeashorterlink makealongerlink);
our $VERSION = '1.91';

use Carp;

=head1 Functions
=head2 makeashorterlink
The function C<makeashorterlink> will call the Metamark web site passing it
your long URL and will return the shorter Metamark version.
=cut

sub makeashorterlink
{
my $url = shift or croak 'No URL passed to makeashorterlink';
my $ua = __PACKAGE__->ua();
my $resp = $ua->post( 'http://metamark.net/api/rest/simple', [
long_url => $url,
] );
return unless $resp->is_success;
return if $resp->content =~ /^ERROR:/;
# I love REST. It's so simple when done properly.
return $resp->content;
}

=head2 makealongerlink
The function C<makealongerlink> does the reverse. C<makealongerlink>
will accept as an argument either the full Metamark URL or just the
Metamark identifier.
If anything goes wrong, then either function will return C<undef>.
=cut
require WWW::Shorten::_dead;

sub makealongerlink
{
my $short_url = shift
or croak 'No Metamark key / URL passed to makealongerlink';
my $ua = __PACKAGE__->ua();

my $resp = $ua->post( 'http://metamark.net/api/rest/simple', [
short_url => $short_url,
] );
return unless $resp->is_success;
return if $resp->content =~ /^ERROR:/;
# I love REST. It's so simple when done properly.
return $resp->content;
}

1;

__END__
=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://metamark.net/>
=cut
0;
2 changes: 1 addition & 1 deletion t/00load_a.t
@@ -1,6 +1,6 @@
use Test::More tests => 3;
# Basic test of 'does the module load, damnit!'
BEGIN { use_ok 'WWW::Shorten::Metamark' }
BEGIN { use_ok 'WWW::Shorten::TinyURL' }

ok( exists $::{'makeashorterlink'}, 'shorter exists');
ok( exists $::{'makealongerlink'}, 'longer exists');
2 changes: 1 addition & 1 deletion t/00load_b.t
@@ -1,6 +1,6 @@
use Test::More tests => 3;
# Basic test of 'does the module load, damnit!'
BEGIN { use_ok 'WWW::Shorten', 'Metamark' }
BEGIN { use_ok 'WWW::Shorten', 'TinyURL' }

ok( exists $::{'makeashorterlink'}, 'shorter exists');
ok( exists $::{'makealongerlink'}, 'longer exists');
4 changes: 2 additions & 2 deletions t/00noexp.t
@@ -1,7 +1,7 @@
use Test::More tests => 1;
# Basic test of 'does the module load, damnit!'
use WWW::Shorten::Metamark;
use WWW::Shorten::TinyURL;

eval { WWW::Shorten::Metamark->import(':invalid') };
eval { WWW::Shorten::TinyURL->import(':invalid') };

ok($@);
21 changes: 3 additions & 18 deletions t/metamark.t
@@ -1,18 +1,3 @@
use Test::More tests => 7;

BEGIN { use_ok WWW::Shorten::Metamark };

my $url = 'http://dave.org.uk/';
my $short = makeashorterlink( $url );
ok((defined $short), 'Reasonable response');
like ( $short => qr{^http://xrl\.us/\w+$}, 'make it shorter' );

is ( makealongerlink( $short ) => $url, 'make it longer' );

my ($rs) = $short =~ m# / (\w+) $ #x;
is ( makealongerlink($rs) => $url, 'make it longer by Id' );

eval { makeashorterlink() };
ok($@);
eval { makealongerlink() };
ok($@);
use Test::More tests => 1;
eval { require WWW::Shorten::Metamark };
like( $@, qr/inactive/, "Service correctly reports it is inactive." );
5 changes: 2 additions & 3 deletions t/newnames.t
@@ -1,12 +1,11 @@
use Test::More tests => 6;


use WWW::Shorten qw( Metamark :short );
use WWW::Shorten qw( TinyURL :short );

ok( exists $::{'short_link'}, 'shorter exists');
ok( exists $::{'long_link'}, 'longer exists');

use WWW::Shorten qw( Metamark :default );
use WWW::Shorten qw( TinyURL :default );

ok( exists $::{'makeashorterlink'}, 'shorter exists');
ok( exists $::{'makealongerlink'}, 'longer exists');
Expand Down

0 comments on commit 96dabb0

Please sign in to comment.