]> git.nbdom.net Git - nb.git/commitdiff
ovi-api
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 21 Mar 2016 12:13:01 +0000 (13:13 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 21 Mar 2016 12:13:01 +0000 (13:13 +0100)
bin/ovh-api

index be4efbea2dadcdb81413461c9fa185823c7de4a4..eade10a90b3e539b2d47cc46d93f1240b78fbe8d 100755 (executable)
@@ -37,9 +37,20 @@ $main::_DATA_ = undef;
 #
 #################################################################################
 #use Data::Dumper;
-@_ = split(":",$ARGV[0]);
-my $o = OvhApi->new(type => OvhApi::OVH_API_EU, applicationKey => $_[0], applicationSecret => $_[1], consumerKey => $_[2]);
-print JSON::encode_json($o->get(path=>$ARGV[1])->content);
+my @KEY = split(":",shift @ARGV);
+my $URL = shift @ARGV;
+my $METHOD = @ARGV ? shift(@ARGV) : 'GET';
+
+my $o = OvhApi->new(type => OvhApi::OVH_API_EU, applicationKey => $KEY[0], applicationSecret => $KEY[1], consumerKey => $KEY[2]);
+
+my $response = $o->get(path=>$URL,method=>$METHOD);
+
+if (!$response) {
+  die "$NAME: $ARGV[1] failed!"
+}
+
+my $content = $response->content;
+print ref($content) eq '' ? $content : JSON::encode_json($content);
 
 #################################################################################
 #
@@ -174,6 +185,10 @@ This program is distributed in the hope that it will be useful, but WITHOUT ANY
 
 See <http://www.gnu.org/licenses/>.
 
+=head1 SEE ALSO
+
+OvhApi
+
 =head1 AUTHOR
 
 Nicolas Boisselier nicolas.boisselier@gmail.com