'method' => 'GET',
);
get_options(\%Opt);
-help() unless @ARGV;
$main::_DATA_ = undef;
+# Auth
+if ($_ = $Opt{activate}) {
+ exec qq|curl -s -XPOST -H"X-Ovh-Application: $_" -H "Content-type: application/json" https://eu.api.ovh.com/1.0/auth/credential -d '{"accessRules": [ { "method": "GET", "path": "/*" } ] }'|.'|jq .';
+ #print qq|curl -XPOST -H"X-Ovh-Application: $_" -H "Content-type: application/json" https://eu.api.ovh.com/1.0/auth/credential -d '{"accessRules": [ { "method": "GET", "path": "/*" } ], "redirection":"https://www.mywebsite.com/" }'\n|;
+ #exec("curl","-XPOST",'-H',"X-Ovh-Application: $_",'-H','Content-type: application/json','https://eu.api.ovh.com/1.0/auth/credential','-d',qq|'{"accessRules": [ { "method": "GET", "path": "/*" } ],"redirection":"https://www.mywebsite.com/" }'|);
+ exit 0;
+}
+help() unless @ARGV;
+
#################################################################################
#
#################################################################################
#use Data::Dumper;
my $config = "$ENV{HOME}/.$NAME";
-my @KEY = split(":",-e $config ? chomp($_=`cat "$config"`)&&$_ : shift @ARGV);
-my $URL = @ARGV == 1 ? shift @ARGV : join('/',map{uri_escape($_)} @ARGV);
+my @KEY = ();
+
+if (@ARGV and $ARGV[0] =~ /^(\w+):(\w+):(\w+)$/) {
+ @KEY = split(":",$ARGV[0]);
+ shift @ARGV;
+
+} elsif ($ENV{$NAME.'_KEY'}) {
+ @KEY = split(':',$ENV{$NAME.'_KEY'});
+} elsif (-e $config) {
+ open(CONFIG,"$config") or die "$NAME: can't read $config";
+ @KEY = split(":",chomp($_=join('',<CONFIG>)) && $_);
+ close CONFIG;
-# Auth
-if (@KEY==1) {
- #print qq|curl -XPOST -H"X-Ovh-Application: $KEY[0]" -H "Content-type: application/json" https://eu.api.ovh.com/1.0/auth/credential -d '{"accessRules": [ { "method": "GET", "path": "/*" } ], "redirection":"https://www.mywebsite.com/" }'\n|;
- exec qq|curl -s -XPOST -H"X-Ovh-Application: $KEY[0]" -H "Content-type: application/json" https://eu.api.ovh.com/1.0/auth/credential -d '{"accessRules": [ { "method": "GET", "path": "/*" } ] }'|.'|jq .';
- #exec("curl","-XPOST",'-H',"X-Ovh-Application: $KEY[0]",'-H','Content-type: application/json','https://eu.api.ovh.com/1.0/auth/credential','-d',qq|'{"accessRules": [ { "method": "GET", "path": "/*" } ],"redirection":"https://www.mywebsite.com/" }'|);
- exit 0;
}
+@KEY or help();
+die map{"$_\n"} @KEY;
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 $URL = @ARGV == 1 ? shift @ARGV : join('/',map{uri_escape($_)} @ARGV);
my $response = $o->get(path=>$URL,method=>$Opt{method});
if (!$response) {
=head1 SYNOPSIS
-Quick usage: $NAME k1:k2:k3 URL or $NAME k1 to activate a first account
-
-=head1 DESCRIPTION
+Quick usage:
-https://api.ovh.com/g934.first_step_with_api
-https://api.ovh.com/console/#/domain
+ $NAME k1:k2:k3 /PATH
+ $NAME /PATH
+ $NAME -activate JSHFDlkhaKJHGSF...
=head1 OPTIONS
+ option[activate=s] [KEY] Activate a key (first bit before ":" or KEY[0])
option[method|m] Method (default: GET)
option[verbose|v+] Verbose mode: increase the verbosity level.
option[debug+] Debug mode: increase the verbosity level.
=cut
-=head1 EXAMPLES
+=head1 DESCRIPTION
$NAME k1:k2:k3 /domain
+$NAME /domain
+$NAME -activate MNBaskfjh
+
+ {
+ "validationUrl": "https://eu.api.ovh.com/auth/?credentialToken=KJHDSFLAF...",
+ "consumerKey": "KJHDSF...",
+ "state": "pendingValidation"
+ }
=head1 REQUIRES
Copyright (C) 2016 Nicolas Boisselier
-This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
-
-This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
See <http://www.gnu.org/licenses/>.
-=head1 SEE ALSO
-
-OvhApi
-
=head1 AUTHOR
Nicolas Boisselier nicolas.boisselier@gmail.com