home
#!/usr/bin/perl
use warnings;
use strict;
use Data::Dumper;
use HTTP::Request::Common;
use Perl6::Slurp;
use Getopt::Long;
use LWP::UserAgent;
# * title - The title of this piece of code, could be its filename or a human readable title.
# * src - It is the source code of this script.
# * tags - Enumerate here the tags that you want to use for this program.
# * user - The user login should be included in the method call in order to be accepted.
# * password - The password is also necesary to accept the upload.
my $URL = 'http://kelpi.com/api/post';
my $rh_params = { };
GetOptions($rh_params,
'file:s',
'username:s',
'password:s',
'tags:s',
'title:s',
);
unless ($rh_params->{file} && -e $rh_params->{file}){
die 'You really must specify a source file using --file';
}
my $data = slurp $rh_params->{file};
my $ua = LWP::UserAgent->new;
my $rv = $ua->request(POST $URL,
[
user => $rh_params->{username},
password => $rh_params->{password},
tags => $rh_params->{tags},
title => $rh_params->{title},
src => $data,
]
);
if ($rv->is_success) {
print "Done !\n";
} else {
print "Error " . $rv->status_line . "\n";
}
exit;