mirror of
https://github.com/pierre42100/ComunicAPI
synced 2025-06-19 08:35:18 +00:00
Can create clients from shell
This commit is contained in:
@ -68,4 +68,40 @@ class APIClients {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new API client
|
||||
*
|
||||
* @param APIClient $client The client to create
|
||||
* @return bool TRUE for a success / FALSE else
|
||||
*/
|
||||
public function create(APIClient $client) : bool {
|
||||
|
||||
//Get database entry
|
||||
$entry = self::APIClientsToDb($client);
|
||||
|
||||
//Insert the entry in the database
|
||||
$tableName = CS::get()->config->get("dbprefix")."API_ServicesToken";
|
||||
return CS::get()->db->addLine($tableName, $entry);
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn a APIClient object into database entry
|
||||
*
|
||||
* @param APIClientsToDb $client
|
||||
* @return array Generated database entry
|
||||
*/
|
||||
private static function APIClientsToDb(APIClient $client) : array {
|
||||
|
||||
$data = array();
|
||||
|
||||
$data["time_insert"] = $client->get_time_insert();
|
||||
$data["serviceName"] = $client->get_name();
|
||||
$data["token"] = $client->get_token();
|
||||
if($client->has_client_domain())
|
||||
$data["client_domain"] = $client->get_client_domain();
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -11,9 +11,19 @@ require_once __DIR__."/BaseUniqueObject.php";
|
||||
class APIClient extends BaseUniqueObject {
|
||||
|
||||
//Private fields
|
||||
private $time_insert;
|
||||
private $name;
|
||||
private $token;
|
||||
private $url;
|
||||
private $client_domain;
|
||||
|
||||
//Set and get creation time
|
||||
public function set_time_insert(int $time_insert){
|
||||
$this->time_insert = $time_insert;
|
||||
}
|
||||
|
||||
public function get_time_insert() : int {
|
||||
return $this->time_insert;
|
||||
}
|
||||
|
||||
//Get and set client name
|
||||
public function set_name(string $name){
|
||||
@ -43,17 +53,17 @@ class APIClient extends BaseUniqueObject {
|
||||
}
|
||||
|
||||
|
||||
//Get and set client URL
|
||||
public function set_url(string $url){
|
||||
$this->url = $url == "" ? null : $url;
|
||||
//Get and set client domain
|
||||
public function set_client_domain(string $client_domain){
|
||||
$this->client_domain = $client_domain == "" ? null : $client_domain;
|
||||
}
|
||||
|
||||
public function has_url() : bool {
|
||||
return $this->url != null;
|
||||
public function has_client_domain() : bool {
|
||||
return $this->client_domain != null;
|
||||
}
|
||||
|
||||
public function get_url() : string {
|
||||
return $this->url != null ? $this->url : "null";
|
||||
public function get_client_domain() : string {
|
||||
return $this->client_domain != null ? $this->client_domain : "null";
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user