Posted By

engel on 02/24/08


Tagged

url short shorten xrl metamark shortlink


Versions (?)

shortLink v2


 / Published in: Perl
 

Shorter, more simple, but with a GUI. Requires GNOME (and the Zenity program, which comes by default with GNOME).

I recommend setting a hotkey with GNOME or Compiz (mine is Ctrl+Alt+A) to run this program, so when the hotkey is pressed you can quickly and easily shorten URLs.

  1. #!/usr/bin/perl
  2.  
  3. package shortLink;
  4.  
  5. use LWP::UserAgent;
  6. use strict;
  7.  
  8. my $url = readpipe('zenity --entry --title="shortLink" --text="Please enter a URL to shorten." --entry-text=""');
  9.  
  10. $shortLink::ua = LWP::UserAgent->new;
  11. my $r = $shortLink::ua->post('http://metamark.net/api/rest/simple', { long_url => $url });
  12. system('zenity --info --text="' . errorCheck($r) . '"');
  13.  
  14. sub errorCheck {
  15. my $response = shift;
  16. if ( $response->is_success ) {
  17. return $response->content;
  18. } else {
  19. return "There was an error: " . $response->status_line . "\n";
  20. }
  21. }

Report this snippet  

You need to login to post a comment.