]> git.nbdom.net Git - nb.git/commitdiff
ovh-api
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 14 Dec 2016 15:39:55 +0000 (16:39 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 14 Dec 2016 15:39:55 +0000 (16:39 +0100)
bin/ovh-api

index a1b2d48fe426824135c2bc8e6aa2c52be850b2bd..10e2066ac7de5ae65dadd55af45c72705ce4e316 100755 (executable)
@@ -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";
 
 #################################################################################
 #