Skip to content

[FEATURE] REST API endpoint for getting list details #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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