Skip to content

Commit

Permalink
Adds in a method for getting all notifications.
Browse files Browse the repository at this point in the history
  • Loading branch information
typhonius committed Dec 19, 2019
1 parent 9d308f4 commit e8b4c87
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 3 deletions.
21 changes: 20 additions & 1 deletion src/CloudApi/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use AcquiaCloudApi\Response\LogstreamResponse;
use AcquiaCloudApi\Response\MembersResponse;
use AcquiaCloudApi\Response\NotificationResponse;
use AcquiaCloudApi\Response\NotificationsResponse;
use AcquiaCloudApi\Response\OperationResponse;
use AcquiaCloudApi\Response\OrganizationsResponse;
use AcquiaCloudApi\Response\PermissionsResponse;
Expand Down Expand Up @@ -107,7 +108,7 @@ public function account()
}

/**
* Returns details about your account.
* Returns details about a notification.
*
* @return NotificationResponse
*/
Expand All @@ -122,6 +123,24 @@ public function notification($notificationUuid)
);
}

/**
* Returns a list of notifications.
*
* @param string $applicationUuid
*
* @return NotificationsResponse
*/
public function notifications($applicationUuid)
{
return new NotificationsResponse(
$this->connector->request(
'get',
"/applications/${applicationUuid}/notifications",
$this->query
)
);
}

/**
* Shows all applications.
*
Expand Down
4 changes: 3 additions & 1 deletion src/Response/NotificationResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public function __construct($notification)
$this->status = $notification->status;
$this->progress = $notification->progress;
$this->context = $notification->context;
$this->links = $notification->_links;
if (property_exists($notification, '_links')) {
$this->links = $notification->_links;
}
}
}
22 changes: 22 additions & 0 deletions src/Response/NotificationsResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace AcquiaCloudApi\Response;

/**
* Class NotificationsResponse
* @package AcquiaCloudApi\Response
*/
class NotificationsResponse extends \ArrayObject
{

/**
* MembersResponse constructor.
* @param array $notifications
*/
public function __construct($notifications)
{
parent::__construct(array_map(function ($notification) {
return new NotificationResponse($notification);
}, $notifications), self::ARRAY_AS_PROPS);
}
}
23 changes: 22 additions & 1 deletion tests/Endpoints/NotificationTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use AcquiaCloudApi\CloudApi\Client;
use AcquiaCloudApi\Tests\CloudApiTestCase;

class NotificationTest extends CloudApiTestCase
{
Expand All @@ -23,7 +24,7 @@ public function testGetNotification()
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getNotification.json');
$client = $this->getMockClient($response);

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

$this->assertInstanceOf('\AcquiaCloudApi\Response\NotificationResponse', $result);
Expand All @@ -32,4 +33,24 @@ public function testGetNotification()
$this->assertObjectHasAttribute($property, $result);
}
}

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

/** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */
$result = $client->notifications('f027502b-ed6c-448e-97e8-4a0def7d25e1');

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

foreach ($result as $record) {
$this->assertInstanceOf('\AcquiaCloudApi\Response\NotificationResponse', $record);

foreach ($this->properties as $property) {
$this->assertObjectHasAttribute($property, $record);
}
}
}
}
62 changes: 62 additions & 0 deletions tests/Fixtures/Endpoints/getNotifications.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"total": 1,
"pagination": {
"total": 1,
"limit": 1,
"offset": 0
},
"_links": {
"self": {
"href": "https://cloud.acquia.dev/api/applications/f027502b-ed6c-448e-97e8-4a0def7d25e1/notifications"
},
"parent": {
"href": "https://cloud.acquia.dev/api/applications/f027502b-ed6c-448e-97e8-4a0def7d25e1"
},
"limit": {
"href": "https://cloud.acquia.dev/api/applications/f027502b-ed6c-448e-97e8-4a0def7d25e1/notifications{?limit}",
"templated": true
},
"offset": {
"href": "https://cloud.acquia.dev/api/applications/f027502b-ed6c-448e-97e8-4a0def7d25e1/notifications{?offset}",
"templated": true
},
"sort": {
"href": "https://cloud.acquia.dev/api/applications/f027502b-ed6c-448e-97e8-4a0def7d25e1/notifications{?sort}",
"templated": true
},
"filter": {
"href": "https://cloud.acquia.dev/api/applications/f027502b-ed6c-448e-97e8-4a0def7d25e1/notifications{?filter}",
"templated": true
}
},
"_embedded": {
"items": [
{
"uuid": "1bd3487e-71d1-4fca-a2d9-5f969b3d35c1",
"event": "ApplicationAddedToRecents",
"label": "Application added to recents list",
"description": "\"Canary QA 11 - ACE\" was added to your recent applications list.",
"created_at": "2019-07-29T20:47:13+00:00",
"completed_at": "2019-07-29T20:47:13+00:00",
"status": "completed",
"progress": 100,
"context": {
"author": {
"uuid": "5391a8a9-d273-4f88-8114-7f884bbfe08b",
"actual_uuid": "5391a8a9-d273-4f88-8114-7f884bbfe08b"
},
"user": {
"uuids": [
"5391a8a9-d273-4f88-8114-7f884bbfe08b"
]
},
"application": {
"uuids": [
"f027502b-ed6c-448e-97e8-4a0def7d25e1"
]
}
}
}
]
}
}

0 comments on commit e8b4c87

Please sign in to comment.