/ Published in: Perl
Easily and quickly shorten URLs from the command line. Utilizes TinyURL and MetaMark APIs.
Expand |
Embed | Plain Text
#!/usr/bin/perl package shortLink; use Getopt::Std; use LWP::UserAgent; use strict; use Switch; our($opt_s, $opt_u); getopts('s:u:'); help_message() unless $opt_u; $opt_s = ( !$opt_s ) ? "tinyurl" : $opt_s; switch ( $opt_s ) { case "tinyurl" { makeUA(); my $r = $shortLink::ua->get('http://tinyurl.com/api-create.php?url=' . $opt_u); } case "metamark" { makeUA(); my $r = $shortLink::ua->post('http://metamark.net/api/rest/simple', { long_url => $opt_u }); } else { help_message(); } } sub errorCheck { if ( $response->is_success ) { } else { } } sub help_message { print "Usage: shortlink [ -s service ] -u url\n -s service\tSpecify URL shortener service to use. Possible values:\n\t\t\ttinyurl\n\t\t\tmetamark\n"; } sub makeUA { $shortLink::ua = LWP::UserAgent->new; }
You need to login to post a comment.
