Skip to content
Snippets Groups Projects
Commit 23220595 authored by Mahmoud Wardeh's avatar Mahmoud Wardeh
Browse files

moved sendEvent and sendEventObject to EventsAPIClient

parent a5ebf7bb
No related branches found
No related tags found
1 merge request!5split event mangement eventsapi
...@@ -173,74 +173,6 @@ class EventManagement{ ...@@ -173,74 +173,6 @@ class EventManagement{
return new Response("Successfully handled event $newID: $name."); return new Response("Successfully handled event $newID: $name.");
} }
/**
* Send an event to a event receiver.
* @param string $name name of the event
* @param string $description description of the event
* @param string $baseURL the root URL of the event receiver REST API
* @param string $certFile path to certificate file to use or null to call URL without certificate
* @param string $certKey path to certificate key file, null to avoid usage of key
* @param string $certPassphrase path to passphrase file for key file, null for no passphrase
* @param int $timeout time out in seconds until curl call is aborted
* @param \jards\eventsapiclient\Swagger\Client\ApiException $exception output parameter, if exception occurs
*
* @return boolean true on success, false on error
*/
public function sendEvent($name, $description, $baseURL='http://localhost/myapps/EventsAPI/rest/events', $certFile = null, $certKey = null, $certPassphrase = null, $timeout = null, &$exception=null){
$event = new Event();
$event->setName($name);
$event->setDescription($description);
$event->setDate(new \DateTime());
return $this->sendEventObject($event, $baseURL, $certFile, $certKey, $certPassphrase, $timeout, $exception);
}
/**
* Send an event according to swagger API model.
* Prepare any event you like, then send it with this function.
*
* @param Event $eventObject the event object you would like to send
* @param string $baseURL the root URL of the event receiver REST API
* @param string $certFile path to certificate file to use or null to call URL without certificate
* @param string $certKey path to certificate key file, null to avoid usage of key
* @param string $certPassphrase path to passphrase file for key file, null for no passphrase
* @param int $timeout time out in seconds until curl call is aborted
* @param \jards\eventsapiclient\Swagger\Client\ApiException $exception output parameter, if exception occurs
*
* @return boolean true on success, false on error
*/
public function sendEventObject($eventObject, $baseURL='http://localhost/myapps/EventsAPI/rest/events', $certFile = null, $certKey = null, $certPassphrase = null, $timeout = null, &$exception=null){
date_default_timezone_set ( 'Europe/Amsterdam' );
$apiClient = new \jards\eventsapiclient\Swagger\Client\ApiClient ();
$apiClient->getConfig ()->setHost ( $baseURL );
if(! empty($certFile)){
$apiClient->getConfig ()->setCertificate($certFile);
}
if(! empty($certKey)){
$apiClient->getConfig ()->setCertificateKey($certKey);
}
if(! empty($certPassphrase)){
$apiClient->getConfig ()->setCertificatePassphrase($certPassphrase);
}
if(! empty($timeout)){
$apiClient->getConfig()->setCurlConnectTimeout($timeout);
}
$eventsApi = new EventsApi($apiClient);
try{
$eventsApi->eventsPost($eventObject);
}
catch(\jards\eventsapiclient\Swagger\Client\ApiException $e){
$exception = $e;
return false;
}
return true;
}
} }
?> ?>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment