diff --git a/CHANGELOG.md b/CHANGELOG.md index 473423c..815494c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,10 +4,11 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/). -## 4.0.0 (unreleased) +## x.y.z (unreleased) ### Added - +- REST action for getting all subscribers for a list (#83) +- REST API endpoint for getting list details (#89) ### Changed diff --git a/Classes/Controller/ListController.php b/Classes/Controller/ListController.php index 70c7330..1fb276a 100644 --- a/Classes/Controller/ListController.php +++ b/Classes/Controller/ListController.php @@ -50,6 +50,21 @@ public function cgetAction(Request $request): View return View::create()->setData($this->subscriberListRepository->findAll()); } + /** + * Gets a subscriber list. + * + * @param Request $request + * @param SubscriberList $list + * + * @return View + */ + public function getAction(Request $request, SubscriberList $list): View + { + $this->requireAuthentication($request); + + return View::create()->setData($list); + } + /** * Gets a list of all subscribers (members) of a subscriber list. * diff --git a/Documentation/Api/RestApi.apib b/Documentation/Api/RestApi.apib index cc38e19..5fbfa81 100644 --- a/Documentation/Api/RestApi.apib +++ b/Documentation/Api/RestApi.apib @@ -127,6 +127,96 @@ provided as basic auth password. (The basic auth user name can be any string.) "message": "No valid session key was provided as basic auth password." } +## Single subscriber list [/lists/{list}] + +### Get the list data [GET] + ++ Request (application/json) + ++ Response 200 (application/json) + + + Body + + { + "name": "News", + "description": "News (and some fun stuff)", + "creation_date": "2016-06-22T15:01:17+00:00", + "list_position": 12, + "subject_prefix": "phpList", + "public": true, + "category": "news", + "id": 1 + } + ++ Response 403 (application/json) + + + Body + + { + "code": 403, + "message": "No valid session key was provided as basic auth password." + } + ++ Response 404 (application/json) + + + Body + + { + "code": 404, + "message": "There is no list with that ID." + } + +## Members of a subscriber list [/lists/{list}/members] + +### Retrieve all members of a subscriber list [GET] + ++ Request (application/json) + ++ Response 200 (application/json) + + + Body + + { + "creation_date" => "2016-07-22T15:01:17+00:00", + "email" => "oliver@example.com", + "confirmed" => true, + "blacklisted" => true, + "bounce_count" => 17, + "unique_id" => "95feb7fe7e06e6c11ca8d0c48cb46e89", + "html_email" => true, + "disabled" => true, + "id" => 1, + }, + { + "creation_date" => "2017-07-22T15:12:17+00:00", + "email" => "sam@example.com", + "confirmed" => true, + "blacklisted" => false, + "bounce_count" => 1, + "unique_id" => "95feb7fe7e06e6c11ca8d0c48cb4616d", + "html_email" => false, + "disabled" => false, + "id" => 2, + } + ++ Response 403 (application/json) + + + Body + + { + "code": 403, + "message": "No valid session key was provided as basic auth password." + } + ++ Response 404 (application/json) + + + Body + + { + "code": 404, + "message": "There is no list with that ID." + } + ## Members of a subscriber list [/lists/{list}/members] diff --git a/Tests/Integration/Controller/ListControllerTest.php b/Tests/Integration/Controller/ListControllerTest.php index 2a7463f..c57cb4a 100644 --- a/Tests/Integration/Controller/ListControllerTest.php +++ b/Tests/Integration/Controller/ListControllerTest.php @@ -111,6 +111,66 @@ public function getListsWithCurrentSessionKeyReturnsListData() ); } + /** + * @test + */ + public function getListWithoutSessionKeyForExistingListReturnsForbiddenStatus() + { + $this->getDataSet()->addTable(static::LISTS_TABLE_NAME, __DIR__ . '/Fixtures/SubscriberList.csv'); + $this->applyDatabaseChanges(); + + $this->client->request('get', '/api/v2/lists/1'); + + $this->assertHttpForbidden(); + } + + /** + * @test + */ + public function getListWithCurrentSessionKeyForExistingListReturnsOkayStatus() + { + $this->getDataSet()->addTable(static::LISTS_TABLE_NAME, __DIR__ . '/Fixtures/SubscriberList.csv'); + $this->applyDatabaseChanges(); + + $this->authenticatedJsonRequest('get', '/api/v2/lists/1'); + + $this->assertHttpOkay(); + } + + /** + * @test + */ + public function getListWithCurrentSessionKeyForInexistentListReturnsNotFoundStatus() + { + $this->authenticatedJsonRequest('get', '/api/v2/lists/999'); + + $this->assertHttpNotFound(); + } + + /** + * @test + */ + public function getListWithCurrentSessionKeyReturnsListData() + { + $this->getDataSet()->addTable(static::LISTS_TABLE_NAME, __DIR__ . '/Fixtures/SubscriberList.csv'); + $this->applyDatabaseChanges(); + + $this->authenticatedJsonRequest('get', '/api/v2/lists/1'); + + $this->assertJsonResponseContentEquals( + [ + 'name' => 'News', + 'description' => 'News (and some fun stuff)', + 'creation_date' => '2016-06-22T15:01:17+00:00', + 'list_position' => 12, + 'subject_prefix' => 'phpList', + 'public' => true, + 'category' => 'news', + 'id' => 1, + ] + ); + } + /** * @test */