Skip to content

Commit

Permalink
[FEATURE] REST API endpoint for getting list details
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Klee committed Feb 9, 2018
1 parent 189acdc commit 481109e
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 2 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 15 additions & 0 deletions Classes/Controller/ListController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
90 changes: 90 additions & 0 deletions Documentation/Api/RestApi.apib
Original file line number Diff line number Diff line change
Expand Up @@ -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" => "[email protected]",
"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" => "[email protected]",
"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]

Expand Down
60 changes: 60 additions & 0 deletions Tests/Integration/Controller/ListControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 481109e

Please sign in to comment.