Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
EventsAPI
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
jards
EventsAPI
Commits
9be98972
Commit
9be98972
authored
7 years ago
by
Carsten Karbach
Browse files
Options
Downloads
Patches
Plain Diff
Allow to send events as Model objects
parent
a0802ea9
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/EventManagement.php
+22
-6
22 additions, 6 deletions
lib/EventManagement.php
tests/EventManagementTest.php
+16
-2
16 additions, 2 deletions
tests/EventManagementTest.php
with
38 additions
and
8 deletions
lib/EventManagement.php
+
22
−
6
View file @
9be98972
...
...
@@ -178,6 +178,27 @@ class EventManagement{
*/
public
function
sendEvent
(
$name
,
$description
,
$baseURL
=
'http://localhost/myapps/EventsAPI/rest/events'
,
$certFile
=
null
,
$certKey
=
null
,
$certPassphrase
=
null
){
$event
=
new
Event
();
$event
->
setName
(
$name
);
$event
->
setDescription
(
$description
);
$event
->
setDate
(
new
\DateTime
());
return
$this
->
sendEventObject
(
$event
,
$baseURL
,
$certFile
,
$certKey
,
$certPassphrase
);
}
/**
* 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
*
* @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
){
date_default_timezone_set
(
'Europe/Amsterdam'
);
$apiClient
=
new
\jards\eventsapiclient\Swagger\Client\ApiClient
();
$apiClient
->
getConfig
()
->
setHost
(
$baseURL
);
...
...
@@ -194,13 +215,8 @@ class EventManagement{
$eventsApi
=
new
EventsApi
(
$apiClient
);
$event
=
new
Event
();
$event
->
setName
(
$name
);
$event
->
setDescription
(
$description
);
$event
->
setDate
(
new
\DateTime
());
try
{
$eventsApi
->
eventsPost
(
$event
);
$eventsApi
->
eventsPost
(
$event
Object
);
}
catch
(
\jards\eventsapiclient\Swagger\Client\ApiException
$e
){
return
false
;
...
...
This diff is collapsed.
Click to expand it.
tests/EventManagementTest.php
+
16
−
2
View file @
9be98972
...
...
@@ -4,6 +4,7 @@ namespace jards\eventsapi\tests;
use
PHPUnit\Framework\TestCase
;
use
jards\eventsapi\EventManagement
;
use
jards\eventsapiclient\Swagger\Client\Model\Event
;
class
EventManagementTest
extends
TestCase
{
...
...
@@ -54,13 +55,26 @@ class EventManagementTest extends TestCase{
$url
=
file_get_contents
(
__DIR__
.
'/../configs/myurl.cnf'
);
$success
=
$eventManagement
->
sendEvent
(
'test event'
,
'This is only a test'
,
$url
);
$this
->
assertTrue
(
$success
,
"Event sending was not successful"
);
$newEventIDs
=
$this
->
getExistingEventIDs
();
$this
->
assertNotEquals
(
join
(
'|'
,
$oldEventIDs
),
join
(
'|'
,
$newEventIDs
),
"No event seems to be sent"
);
//Send event directly
$event
=
new
Event
();
$event
->
setName
(
'My event'
);
$event
->
setDescription
(
'Good event for testing'
);
$event
->
setNewState
(
'none'
);
$event
->
setDate
(
new
\DateTime
());
$success
=
$eventManagement
->
sendEventObject
(
$event
,
$url
);
$this
->
assertTrue
(
$success
,
"Event sending was not successful"
);
$newEventIDs2
=
$this
->
getExistingEventIDs
();
$this
->
assertNotEquals
(
join
(
'|'
,
$newEventIDs
),
join
(
'|'
,
$newEventIDs2
),
"No event seems to be sent when sending event object"
);
$newEventIDs
=
$newEventIDs2
;
foreach
(
$newEventIDs
as
$newID
){
if
(
!
in_array
(
$newID
,
$oldEventIDs
)){
$toDelete
=
__DIR__
.
'/../data/'
.
$newID
.
'.obj'
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment