Can create clients from shell

This commit is contained in:
Pierre
2018-05-07 18:50:50 +02:00
parent 97ef188167
commit 0b5019d487
5 changed files with 104 additions and 12 deletions

46
bin/add_client Executable file
View File

@ -0,0 +1,46 @@
#!/usr/bin/env php
###########################
# ComunicAPI clients add #
# #
# @author Pierre HUBERT #
###########################
<?php
/**
* Display a message
*/
function msg(string $message){
echo $message."\n";
}
/**
* Display help
*/
function help(){
msg("Usage: ./add_client [name] [token]");
}
//Check for arguments
if(count($_SERVER['argv']) < 3){
exit(help());
}
//Initialize page
require __DIR__."/../init.php";
//Extract the arguments
$client = new APIClient();
$client->set_time_insert(time());
$client->set_name($_SERVER['argv'][1]);
$client->set_token($_SERVER['argv'][2]);
//Try to create the client
if(!cs()->clients->create($client)){
msg("Err! Could not create client tokens!");
exit(10);
}
//Success
msg("The client has been created!");