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";
#################################################################################
#