summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--_data/scripts.yaml6
-rw-r--r--scripts/tinyurl.pl41
2 files changed, 27 insertions, 20 deletions
diff --git a/_data/scripts.yaml b/_data/scripts.yaml
index 0d384cd..fd03348 100644
--- a/_data/scripts.yaml
+++ b/_data/scripts.yaml
@@ -4312,10 +4312,10 @@
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'
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;
}