Skip to content

Commit

Permalink
Add Notification class for getting information about a Notification
Browse files Browse the repository at this point in the history
  • Loading branch information
eporama authored and typhonius committed Dec 19, 2019
1 parent ac5bce7 commit 9d308f4
Show file tree
Hide file tree
Showing 5 changed files with 171 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/CloudApi/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use AcquiaCloudApi\Response\InvitationsResponse;
use AcquiaCloudApi\Response\LogstreamResponse;
use AcquiaCloudApi\Response\MembersResponse;
use AcquiaCloudApi\Response\NotificationResponse;
use AcquiaCloudApi\Response\OperationResponse;
use AcquiaCloudApi\Response\OrganizationsResponse;
use AcquiaCloudApi\Response\PermissionsResponse;
Expand Down Expand Up @@ -105,6 +106,22 @@ public function account()
return new AccountResponse($this->connector->request('get', '/account', $this->query));
}

/**
* Returns details about your account.
*
* @return NotificationResponse
*/
public function notification($notificationUuid)
{
return new NotificationResponse(
$this->connector->request(
'get',
"/notifications/${notificationUuid}",
$this->query
)
);
}

/**
* Shows all applications.
*
Expand Down
10 changes: 10 additions & 0 deletions src/CloudApi/ClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use AcquiaCloudApi\Response\InvitationsResponse;
use AcquiaCloudApi\Response\LogstreamResponse;
use AcquiaCloudApi\Response\MembersResponse;
use AcquiaCloudApi\Response\NotificationResponse;
use AcquiaCloudApi\Response\OperationResponse;
use AcquiaCloudApi\Response\OrganizationsResponse;
use AcquiaCloudApi\Response\PermissionsResponse;
Expand Down Expand Up @@ -68,6 +69,15 @@ public function account();
*/
public function applications();


/**
* Returns details about a notification.
*
* @param string $notificationUuid
* @return NotificationResponse
*/
public function notification($notificationUuid);

/**
* Shows information about an application.
*
Expand Down
40 changes: 40 additions & 0 deletions src/Response/NotificationResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace AcquiaCloudApi\Response;

/**
* Class NotificationResponse
* @package AcquiaCloudApi\Response
*/
class NotificationResponse
{
public $uuid;
public $event;
public $label;
public $description;
public $created_at;
public $completed_at;
public $status;
public $progress;
public $context;
public $links;


/**
* MemberResponse constructor.
* @param object $notification
*/
public function __construct($notification)
{
$this->uuid = $notification->uuid;
$this->event = $notification->event;
$this->label = $notification->label;
$this->description = $notification->description;
$this->created_at = $notification->created_at;
$this->completed_at = $notification->completed_at;
$this->status = $notification->status;
$this->progress = $notification->progress;
$this->context = $notification->context;
$this->links = $notification->_links;
}
}
35 changes: 35 additions & 0 deletions tests/Endpoints/NotificationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

use AcquiaCloudApi\CloudApi\Client;

class NotificationTest extends CloudApiTestCase
{

protected $properties = [
'uuid',
'event',
'label',
'description',
'created_at',
'completed_at',
'status',
'progress',
'context',
'links'
];

public function testGetNotification()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getNotification.json');
$client = $this->getMockClient($response);

/** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */
$result = $client->notification('f4b37e3c-1g96-4ed4-ad20-3081fe0f9545');

$this->assertInstanceOf('\AcquiaCloudApi\Response\NotificationResponse', $result);

foreach ($this->properties as $property) {
$this->assertObjectHasAttribute($property, $result);
}
}
}
69 changes: 69 additions & 0 deletions tests/Fixtures/Endpoints/getNotification.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"uuid": "f4b37e3c-1g96-4ed4-ad20-3081fe0f9545",
"event": "DatabaseBackupCreated",
"label": "Database backup created",
"description": "A \"sample_db\" database backup has been created for \"Dev\".",
"created_at": "2019-09-23T15:59:39+00:00",
"completed_at": "2019-09-23T16:01:16+00:00",
"status": "completed",
"progress": 100,
"context": {
"database": {
"names": [
"sample_db"
]
},
"environment": {
"ids": [
"5333-3580d1ec-cf2b-1624-5d85-0d11ecd9a69a"
]
},
"application": {
"uuids": [
"3580d1ec-cfgb-1624-5d85-0d28g2d9n69a"
]
},
"team": {
"uuids": [
"3cb395d2-7cba-1fh4-b588-22000b04072f",
"a31ba519-4ec3-47c9-9dd1-b509g3fb618f"
]
},
"organization": {
"uuids": [
"26416235-7cba-11e4-b567-200200b04072f"
]
},
"subscription": {
"uuids": [
"863aa975-b9b9-4c55-9b1f-90e31293ad30"
]
},
"author": {
"uuid": "a58b046c-dd0c-102e-8305-1231f10f2cc1",
"actual_uuid": "a58b046c-dd0c-102e-8305-1231f10f2cc1"
},
"user": {
"uuids": [
"a58b046c-dd0c-102e-8305-1231f10f2cc1"
]
}
},
"_links": {
"self": {
"href": "https:\/\/cloud.acquia.com\/api\/notifications\/f4b37e3c-1g96-4ed4-ad20-3081fe0f9545"
}
},
"_embedded": {
"author": {
"uuid": "a58b046c-dd0c-102e-8305-1231f10f2cc1",
"first_name": "Jane",
"last_name": "Doe",
"last_login_at": "2019-09-22T12:20:20+00:00",
"created_at": "2017-03-28T13:07:54-0500",
"email": "jane.doe@example.com",
"picture_url": "https:\/\/accounts.acquia.com\/images\/users\/a58b046c-dd0c-102e-8305-1231f10f2cc1\/style\/avatar",
"username": "jane.doe"
}
}
}

0 comments on commit 9d308f4

Please sign in to comment.