diff --git a/src/CloudApi/Client.php b/src/CloudApi/Client.php index ff2fa9f1..e1bea11f 100644 --- a/src/CloudApi/Client.php +++ b/src/CloudApi/Client.php @@ -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; @@ -107,7 +108,7 @@ public function account() } /** - * Returns details about your account. + * Returns details about a notification. * * @return NotificationResponse */ @@ -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. * diff --git a/src/Response/NotificationResponse.php b/src/Response/NotificationResponse.php index 7c6d29f8..86e6eada 100644 --- a/src/Response/NotificationResponse.php +++ b/src/Response/NotificationResponse.php @@ -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; + } } } diff --git a/src/Response/NotificationsResponse.php b/src/Response/NotificationsResponse.php new file mode 100644 index 00000000..bde3cbee --- /dev/null +++ b/src/Response/NotificationsResponse.php @@ -0,0 +1,22 @@ +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); @@ -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); + } + } + } } diff --git a/tests/Fixtures/Endpoints/getNotifications.json b/tests/Fixtures/Endpoints/getNotifications.json new file mode 100644 index 00000000..024148d0 --- /dev/null +++ b/tests/Fixtures/Endpoints/getNotifications.json @@ -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" + ] + } + } + } + ] + } + } \ No newline at end of file