diff options
| author | efuce | 2016-06-15 22:52:36 +0200 | 
|---|---|---|
| committer | efuce | 2016-06-15 22:52:36 +0200 | 
| commit | 6a4c97ccada442bf5fd1b860ee10fb7a706d289e (patch) | |
| tree | afc1ef2dd0ab4a594429930c2ef3cf45f245e9d4 /scripts/tinyurl.pl | |
| parent | e55947044befa90248d1e0bf00f456d264b2f172 (diff) | |
| download | scripts.irssi.org-6a4c97ccada442bf5fd1b860ee10fb7a706d289e.tar.bz2 | |
Updated tinyurl.pl to make use of HTTP::Tiny instead of LWP::UserAgent.
Slightly adapted url detection regex to make it work with the current
iteration of tinyurl.com.
Diffstat (limited to 'scripts/tinyurl.pl')
| -rw-r--r-- | scripts/tinyurl.pl | 41 | 
1 files changed, 24 insertions, 17 deletions
| diff --git a/scripts/tinyurl.pl b/scripts/tinyurl.pl index 31a097b..d1ecf84 100644 --- a/scripts/tinyurl.pl +++ b/scripts/tinyurl.pl @@ -3,13 +3,12 @@  # by Atoms  use strict; -use IO::Socket; -use LWP::UserAgent; +use HTTP::Tiny;  use vars qw($VERSION %IRSSI);  use Irssi qw(command_bind active_win); -$VERSION = '1.0'; +$VERSION = '1.1';  %IRSSI = (      authors	=> 'Atoms',      contact	=> 'atoms@tups.lv', @@ -33,24 +32,32 @@ command_bind(  );  sub tinyurl { -	my $url = shift; +  my $url = shift; +  my $content = "url=$url";     -        #added to fix URLs containing a '&' -        $url=url_encode($url); +  #added to fix URLs containing a '&' +  $url=url_encode($url); -  my $ua = LWP::UserAgent->new; -  $ua->agent("tinyurl for irssi/1.0 "); -  my $req = HTTP::Request->new(POST => 'http://tinyurl.com/create.php'); -  $req->content_type('application/x-www-form-urlencoded'); -  $req->content("url=$url"); -  my $res = $ua->request($req); +  my %options = ( +    agent => "tinyurl for irssi/1.0 " +  ); -  if ($res->is_success) { -	  return get_tiny_url($res->content); +  my %form_params = ( +    url => $url +  ); +   +  my $ua = HTTP::Tiny->new(%options); +  my $res = $ua->request('POST', 'http://tinyurl.com/create.php', {  +      content => $content, +      headers => { 'content-type' => 'application/x-www-form-urlencoded' }, +  }); + +  if ($res->{success}) { +    return get_tiny_url($res->{content});    } else {      print CLIENTCRAP "ERROR: tinyurl: tinyurl is down or not pingable"; -		return ""; -	} +    return ""; +  }  }  #added because the URL was not being url_encoded. This would cause only  @@ -64,7 +71,7 @@ sub url_encode {  sub get_tiny_url($) {  	my $tiny_url_body = shift; -	$tiny_url_body =~ /(.*)(tinyurl\svalue=\")(.*)(\")(.*)/; +	$tiny_url_body =~ /(.*)(data\-clipboard\-text=\")(.*)(\")(.*)/;  	return $3;  } | 
