From e006fcaa4798c92838c24ec4b3c235216e4b6789 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Wed, 14 Dec 2016 16:39:55 +0100 Subject: [PATCH] ovh-api --- bin/ovh-api | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/bin/ovh-api b/bin/ovh-api index a1b2d48f..10e2066a 100755 --- a/bin/ovh-api +++ b/bin/ovh-api @@ -71,23 +71,32 @@ help() unless @ARGV; my $o = OvhApi->new(type => OvhApi::OVH_API_EU, applicationKey => $KEY[0], applicationSecret => $KEY[1], consumerKey => $KEY[2]); my $URL = shift @ARGV or help(); -my $BODY = @ARGV ? shift @ARGV : ''; +my $BODY = @ARGV ? shift(@ARGV) : {}; +#use Data::Dumper; die Dumper(JSON::encode_json($BODY)); # NB 14.12.16 use LWP::Simple; # NB 14.12.16 if ($URL eq '/help') { # NB 14.12.16 die LWP::Simple::get('https://eu.api.ovh.com/console/'); # NB 14.12.16 } #my $URL = @ARGV == 1 ? shift @ARGV : join('/',map{uri_escape($_)} @ARGV); -$BODY = -e $BODY ? JSON::decode_json(`cat $BODY`) : JSON::encode_json($BODY) if $BODY; +if ( -e $BODY ) { + $BODY = JSON::decode_json(`cat $BODY`); +} elsif (ref($BODY) eq '') { + $BODY = JSON::encode_json($BODY); +} +#$BODY = -e $BODY ? JSON::decode_json(`cat $BODY`) : JSON::encode_json($BODY);# if $BODY; #use Data::Dumper; die Dumper($BODY); my $response = $o->rawCall(path=>$URL,method=>$Opt{method},body=>$BODY); if ($response->isFailure()) { - die "$NAME: ".$response->error()."\n"; + die "$NAME: ERR: ".$response->error()."\n"; } my $content = $response->content; -print ref($content) eq '' ? $content : JSON::encode_json($content)."\n"; +exit unless defined $content; +$content = JSON::encode_json($content) if $content and ref($content) ne ''; +#use Data::Dumper; die Dumper($content); +print "$content\n"; ################################################################################# # -- 2.47.3