]> git.99rst.org Git - irssi-scripts.irssi.org.git/commitdiff
Updated tinyurl.pl to make use of HTTP::Tiny instead of LWP::UserAgent.
authorefuce <redacted>
Wed, 15 Jun 2016 20:52:36 +0000 (22:52 +0200)
committerefuce <redacted>
Wed, 15 Jun 2016 20:52:36 +0000 (22:52 +0200)
Slightly adapted url detection regex to make it work with the current
iteration of tinyurl.com.

_data/scripts.yaml
scripts/tinyurl.pl

index 0d384cd5c10222c210eef42644e8c3f540e27dfc..fd03348f092f3ed7fa1e387189871afa52dd0efc 100644 (file)
   description: 'create a tinyurl from a long one'
   filename: tinyurl.pl
   license: GPL
-  modified: '2008-08-29 13:51:48'
-  modules: LWP::UserAgent
+  modified: '2016-06-15 22:48:48'
+  modules: HTTP::Tiny
   name: tinyurl
-  version: '1.0'
+  version: '1.1'
 -
   authors: 'Timo Sirainen, David Leadbeater'
   contact: 'tss@iki.fi, dgl@dgl.cx'
index 31a097bff63e6c7804b117bc9eeebb8eb08d3e0f..d1ecf8474042fccd3c95acae76ef131498202190 100644 (file)
@@ -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;
 }
git clone https://git.99rst.org/PROJECT