Version 2.1 250406 get_asset, set_asset, set_assetStatus eingebaut

This commit is contained in:
2025-04-06 16:00:16 +02:00
parent 04bf5adb1e
commit 478d39bd50
2 changed files with 37 additions and 8 deletions

View File

@@ -13,22 +13,22 @@ Das Speichern von Zugangsdaten auf öffentlichen Servern stellt ein hohes Risiko
*08.03.2025 -> Anpassungen sendHeaders für Clouflare Erkennung
Inspiriert durch https://github.com/oscarminus/steinapi/blob/main/steinapi.py
Version 2.0 250406 Update auf neue API
Version 2.1 250406 get_asset, set_asset, set_assetStatus eingebaut
curl und php >= 7.4
Mit diesem Script, kann man Fahrzeugstatuse und Berichte abholen.
Für die Berichte muss der User Berechtigung auf die Berichte haben
Beispiel:
<?php
include_once(__DIR__.'/steinAPPConnect.php');
$steinAPP = new steinAPPConnect('BENUTZER','PASSWORT');
$steinAPP = new steinAPPConnect('API-Token');
if($steinAPP->_get_UserName() !== false){
$sABasics = $steinAPP->get_basics();
if($steinAPP->_check() !== false){
$sAAssets = $steinAPP->get_assets();
$sAReports = $steinAPP->get_reports();
//$sAReports = $steinAPP->get_reports(); in der API Version nicht vorgesehen
}
?>

View File

@@ -13,10 +13,11 @@
Inspiriert durch https://github.com/oscarminus/steinapi/blob/main/steinapi.py
Version 2.0 250406 Update auf neue API
Version 2.1 250406 get_asset, set_asset, set_assetStatus eingebaut
*/
class steinAPPConnect{
private $VERSION = '2.0';
private $VERSION = '2.1';
private $MACHINENAME = 'default';
private $ServerURL = 'https://stein.app';
private $APIURL = '/api/api/ext';
@@ -148,6 +149,34 @@ class steinAPPConnect{
return false;
}
public function get_asset($_id){
$response = $this->request($this->ServerURL.$this->APIURL."/assets/".$_id,[]);
if($response !== false){
return $response;
}
return false;
}
public function set_asset($_id,$_asset,$_withNotifyRadio=false){
$notifyRadio = '';
if($_withNotifyRadio)
$notifyRadio = '?notifyRadio=1';
$response = $this->request($this->ServerURL.$this->APIURL."/assets/".$_id.$notifyRadio,$_asset,'PATCH');
if($response !== false){
return $response;
}
return false;
}
public function set_assetStatus($_id,$_status,$_withNotifyRadio=true){
$asset = $this->get_asset($_id);
if($asset !== false){
$_withNotifyRadio = $_withNotifyRadio && !empty($asset->issi) && (strlen($asset->issi) == 7);
$asset->status = $_status;
return $this->set_asset($_id, (array)$asset, $_withNotifyRadio);
}
return false;
}
/* funktioniert mit der neuen API (noch) nicht
public function get_reports(){
$response = $this->request($this->ServerURL.$this->APIURL."/reports/?buIds=".$this->businessunit,[]);