358 lines
10 KiB
PHP
358 lines
10 KiB
PHP
<?php
|
|
|
|
class Rimoapi {
|
|
|
|
public static function getFtuData($oaid, $home_external_id) {
|
|
//$oaid = $oaid;
|
|
$log = mfLoghandler::singleton();
|
|
|
|
// query Home to get FTU data from RIMO - GET /queryHomeWithId
|
|
$params = [];
|
|
$params['apiKey'] = RIMO_API_JSON_APIKEY;
|
|
$params["homeId"] = $home_external_id;
|
|
|
|
$ctx_opts = [
|
|
'http' => [
|
|
'method' => 'GET',
|
|
'header' => 'accept: application/json'
|
|
]
|
|
];
|
|
|
|
$qs = http_build_query($params);
|
|
//echo $qs."\n";
|
|
|
|
$queryHomeEp = RIMO_API_JSON_URL.RIMO_API_JSON_EP_QUERY_HOME;
|
|
$get_url = $queryHomeEp."?".$qs;
|
|
$ctx = stream_context_create($ctx_opts);
|
|
$log->debug(__METHOD__.": Getting Home to fetch FTU: $get_url");
|
|
$response = file_get_contents($get_url, false, $ctx);
|
|
|
|
if($response === false) {
|
|
$log->error("Fehler beim auslesen der FTU ".$oaid);
|
|
return false;
|
|
}
|
|
|
|
$resp_data = json_decode($response);
|
|
if(!is_object($resp_data)) {
|
|
$log->error(__METHOD__.": OAID ".$oaid.": Cannot fetch Home from RIMO! Invalid Response!");
|
|
return false;
|
|
}
|
|
|
|
return $resp_data;
|
|
}
|
|
|
|
public static function getOaid($oaid) {
|
|
$log = mfLoghandler::singleton();
|
|
|
|
$params = [];
|
|
$params['apiKey'] = RIMO_API_JSON_APIKEY;
|
|
|
|
$ctx_opts = [
|
|
'http' => [
|
|
'method' => 'GET',
|
|
'header' => 'accept: application/json'
|
|
]
|
|
];
|
|
|
|
$qs = http_build_query($params);
|
|
//echo $qs."\n";
|
|
|
|
$getOaidEp = RIMO_API_JSON_URL.RIMO_API_JSON_EP_GET_OAID;
|
|
$getOaidEp .= "/".$oaid;
|
|
$get_url = $getOaidEp."?".$qs;
|
|
$ctx = stream_context_create($ctx_opts);
|
|
$log->debug(__METHOD__.": Getting OAID from Rimo: $get_url");
|
|
$response = file_get_contents($get_url, false, $ctx);
|
|
//var_dump($response);exit;
|
|
if($response === false) {
|
|
$log->error("Fehler beim abfragen der OAID in RIMO ".$oaid);
|
|
return false;
|
|
}
|
|
|
|
$resp_data = json_decode($response);
|
|
if(!is_object($resp_data)) {
|
|
$log->error(__METHOD__.": OAID ".$oaid.": Cannot fetch OAID from RIMO! Invalid Response!");
|
|
return false;
|
|
}
|
|
|
|
return $resp_data;
|
|
}
|
|
|
|
public static function createOaid($oaid) {
|
|
$log = mfLoghandler::singleton();
|
|
|
|
$params = [];
|
|
$params['apiKey'] = RIMO_API_JSON_APIKEY;
|
|
$params['oaidName'] = $oaid;
|
|
|
|
$ctx_opts = [
|
|
'http' => [
|
|
'method' => 'POST',
|
|
'header' => 'accept: application/json'
|
|
]
|
|
];
|
|
|
|
$qs = http_build_query($params);
|
|
//echo $qs."\n";
|
|
|
|
$createOrderEp = RIMO_API_JSON_URL.RIMO_API_JSON_EP_CREATE_OAID;
|
|
$post_url = $createOrderEp."?".$qs;
|
|
$ctx = stream_context_create($ctx_opts);
|
|
$log->debug(__METHOD__.": Creating OAID in Rimo: $post_url");
|
|
$response = file_get_contents($post_url, false, $ctx);
|
|
//var_dump($response);exit;
|
|
if($response === false) {
|
|
$log->error("Fehler beim Erstellen der OAID in RIMO ".$oaid);
|
|
return false;
|
|
}
|
|
|
|
$resp_data = json_decode($response);
|
|
if(!$resp_data->id || !$resp_data->name) {
|
|
$log->warning(__METHOD__.": Create OAID returned no ID or oaid name ".$oaid);
|
|
return false;
|
|
}
|
|
|
|
return $resp_data;
|
|
}
|
|
|
|
public static function unassignOaid($oaid, $ftu_external_id) {
|
|
$log = mfLoghandler::singleton();
|
|
|
|
$params = [];
|
|
$params['apiKey'] = RIMO_API_JSON_APIKEY;
|
|
|
|
$ctx_opts = [
|
|
'http' => [
|
|
'method' => 'DELETE',
|
|
'header' => 'accept: application/json'
|
|
]
|
|
];
|
|
|
|
$qs = http_build_query($params);
|
|
|
|
$unassignEp = RIMO_API_JSON_URL.RIMO_API_JSON_EP_UNASSIGN_OAID_TO_FTU;
|
|
$unassignEp = str_replace("{oaidName}", $oaid, $unassignEp);
|
|
$unassignEp = str_replace("{ftuExternalId}", $ftu_external_id, $unassignEp);
|
|
|
|
$delete_url = $unassignEp."?".$qs;
|
|
$ctx = stream_context_create($ctx_opts);
|
|
$log->debug(__METHOD__.": Unassigning OAID from FTU $ftu_external_id: $delete_url");
|
|
$response = file_get_contents($delete_url, false, $ctx);
|
|
|
|
if($response === false) {
|
|
$log->error("Fehler beim Unassignen der OAID in RIMO ".$oaid.": $delete_url");
|
|
return false;
|
|
}
|
|
|
|
$resp_data = json_decode($response);
|
|
return $resp_data;
|
|
}
|
|
|
|
public static function assignOaid($oaid, $ftu_external_id) {
|
|
$log = mfLoghandler::singleton();
|
|
|
|
$params = [];
|
|
$params['apiKey'] = RIMO_API_JSON_APIKEY;
|
|
|
|
$ctx_opts = [
|
|
'http' => [
|
|
'method' => 'POST',
|
|
'header' => 'accept: application/json'
|
|
]
|
|
];
|
|
|
|
$qs = http_build_query($params);
|
|
|
|
$assignEp = RIMO_API_JSON_URL.RIMO_API_JSON_EP_ASSIGN_OAID_TO_FTU;
|
|
$assignEp = str_replace("{oaidName}", $oaid, $assignEp);
|
|
$assignEp = str_replace("{ftuExternalId}", $ftu_external_id, $assignEp);
|
|
|
|
$post_url = $assignEp."?".$qs;
|
|
$ctx = stream_context_create($ctx_opts);
|
|
$log->debug(__METHOD__.": Assigning OAID to current FTU $ftu_external_id: $post_url");
|
|
$response = file_get_contents($post_url, false, $ctx);
|
|
|
|
if($response === false) {
|
|
$log->error("Fehler beim Assignen der OAID ".$oaid." in RIMO ".$oaid);
|
|
return false;
|
|
}
|
|
|
|
$resp_data = json_decode($response);
|
|
return $resp_data;
|
|
}
|
|
|
|
public static function updateWorkorder($rimo_id, Array $data = []) {
|
|
$log = mfLoghandler::singleton();
|
|
|
|
if(!$rimo_id || !count($data)) {
|
|
$log->debug(__METHOD__.": no rimo id or no update data");
|
|
return false;
|
|
}
|
|
|
|
$contact_fields = [
|
|
"company" => "company",
|
|
"firstname" => "firstName",
|
|
"lastname" => "lastName",
|
|
"phone" => "phone",
|
|
"email" => "email"
|
|
];
|
|
|
|
$update_data = [];
|
|
|
|
foreach($data as $field => $value) {
|
|
if(array_key_exists($field, $contact_fields)) {
|
|
$update_data[$contact_fields[$field]] = $value;
|
|
}
|
|
}
|
|
|
|
var_dump($update_data);
|
|
if(!count($update_data)) {
|
|
$log->debug(__METHOD__.": no valid update data");
|
|
return false;
|
|
}
|
|
|
|
$update_data["orderId"] = $rimo_id;
|
|
$update_data['apiKey'] = RIMO_API_JSON_APIKEY;
|
|
|
|
$ctx_opts = [
|
|
'http' => [
|
|
'method' => 'PUT',
|
|
'header' => 'accept: application/json'
|
|
]
|
|
];
|
|
|
|
$qs = http_build_query($update_data);
|
|
|
|
$updateWorkorderEp = RIMO_API_JSON_URL.RIMO_API_JSON_EP_UPDATE_WORKORDER;
|
|
$put_url = $updateWorkorderEp."?".$qs;
|
|
|
|
$ctx = stream_context_create($ctx_opts);
|
|
$log->debug(__METHOD__.": Updating Workorder Contact $rimo_id: $put_url");
|
|
$response = file_get_contents($put_url, false, $ctx);
|
|
|
|
if($response === false) {
|
|
$log->error("Fehler beim Updaten der Workorder $rimo_id in RIMO");
|
|
return false;
|
|
}
|
|
|
|
$resp_data = json_decode($response);
|
|
return $resp_data;
|
|
}
|
|
|
|
public static function getWorkorderAhReport($rimo_id) {
|
|
$log = mfLoghandler::singleton();
|
|
|
|
if(!$rimo_id) {
|
|
$log->debug(__METHOD__.": no workorder id");
|
|
return false;
|
|
}
|
|
|
|
$items = self::getFilenames($rimo_id);
|
|
|
|
if(!is_object($items)) {
|
|
return false;
|
|
}
|
|
|
|
if(!is_array($items->item) || !count($items->item)) {
|
|
return false;
|
|
}
|
|
|
|
foreach($items->item as $item) {
|
|
if(!$item->name) continue;
|
|
|
|
if(!preg_match('/_AHA.pdf$/i', $item->name)) continue;
|
|
|
|
$filename = $item->name;
|
|
}
|
|
|
|
if(!$filename) {
|
|
return false;
|
|
}
|
|
|
|
// fetch file
|
|
|
|
$params = [];
|
|
$params['apiKey'] = RIMO_API_JSON_APIKEY;
|
|
$params['objectId'] = $rimo_id;
|
|
$params['fileNames'] = $filename;
|
|
|
|
$ctx_opts = [
|
|
'http' => [
|
|
'method' => 'GET',
|
|
]
|
|
];
|
|
|
|
$qs = http_build_query($params);
|
|
|
|
$getFileEp = RIMO_API_JSON_URL.RIMO_API_JSON_EP_GET_FILES;
|
|
|
|
$get_url = $getFileEp."?".$qs;
|
|
$ctx = stream_context_create($ctx_opts);
|
|
$log->debug(__METHOD__.": Retrieving file from Rimo: $get_url");
|
|
$response = file_get_contents($get_url, false, $ctx);
|
|
|
|
if(!$response) return false;
|
|
|
|
/* remove boundary from rimo response
|
|
|
|
header:
|
|
|
|
--uuid:b0b72203-db4d-4a85-9d26-b01cd08338c1
|
|
Content-Type: application/octet-stream
|
|
Content-Transfer-Encoding: binary
|
|
Content-ID: <101DCY_AHA.pdf>
|
|
|
|
footer:
|
|
|
|
--uuid:b0b72203-db4d-4a85-9d26-b01cd08338c1--
|
|
*/
|
|
|
|
|
|
$finfo = new Finfo(FILEINFO_MIME);
|
|
$mimetype = $finfo->buffer($response);
|
|
|
|
var_dump($mimetype);exit;
|
|
|
|
if(!stripos($mimetype, "pdf")) {
|
|
return false;
|
|
}
|
|
|
|
return $response;
|
|
}
|
|
|
|
public static function getFilenames($rimo_id) {
|
|
if(!$rimo_id) return false;
|
|
|
|
$log = mfLoghandler::singleton();
|
|
|
|
$params = [];
|
|
$params['apiKey'] = RIMO_API_JSON_APIKEY;
|
|
$params['objectId'] = $rimo_id;
|
|
|
|
$ctx_opts = [
|
|
'http' => [
|
|
'method' => 'GET',
|
|
'header' => 'accept: application/json'
|
|
]
|
|
];
|
|
|
|
$qs = http_build_query($params);
|
|
|
|
$getFileEp = RIMO_API_JSON_URL.RIMO_API_JSON_EP_GET_FILENAMES;
|
|
|
|
$get_url = $getFileEp."?".$qs;
|
|
$ctx = stream_context_create($ctx_opts);
|
|
$log->debug(__METHOD__.": Getting Filenames from Rimo: $get_url");
|
|
$response = file_get_contents($get_url, false, $ctx);
|
|
|
|
if($response === false) {
|
|
$log->error("Error retrieving filenames from RIMO for $rimo_id");
|
|
return false;
|
|
}
|
|
|
|
$resp_data = json_decode($response);
|
|
return $resp_data;
|
|
}
|
|
|
|
|
|
} |