Skip to content

Commit 71bce72

Browse files
author
Oliver Klee
committed
[FEATURE] REST API endpoint for getting list details
1 parent 189acdc commit 71bce72

File tree

3 files changed

+165
-0
lines changed

3 files changed

+165
-0
lines changed

Classes/Controller/ListController.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,21 @@ public function cgetAction(Request $request): View
5050
return View::create()->setData($this->subscriberListRepository->findAll());
5151
}
5252

53+
/**
54+
* Gets a subscriber list.
55+
*
56+
* @param Request $request
57+
* @param SubscriberList $list
58+
*
59+
* @return View
60+
*/
61+
public function getAction(Request $request, SubscriberList $list): View
62+
{
63+
$this->requireAuthentication($request);
64+
65+
return View::create()->setData($list);
66+
}
67+
5368
/**
5469
* Gets a list of all subscribers (members) of a subscriber list.
5570
*

Documentation/Api/RestApi.apib

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,96 @@ provided as basic auth password. (The basic auth user name can be any string.)
127127
"message": "No valid session key was provided as basic auth password."
128128
}
129129

130+
## Single subscriber list [/lists/{list}]
131+
132+
### Get the list data [GET]
133+
134+
+ Request (application/json)
135+
136+
+ Response 200 (application/json)
137+
138+
+ Body
139+
140+
{
141+
"name": "News",
142+
"description": "News (and some fun stuff)",
143+
"creation_date": "2016-06-22T15:01:17+00:00",
144+
"list_position": 12,
145+
"subject_prefix": "phpList",
146+
"public": true,
147+
"category": "news",
148+
"id": 1
149+
}
150+
151+
+ Response 403 (application/json)
152+
153+
+ Body
154+
155+
{
156+
"code": 403,
157+
"message": "No valid session key was provided as basic auth password."
158+
}
159+
160+
+ Response 404 (application/json)
161+
162+
+ Body
163+
164+
{
165+
"code": 404,
166+
"message": "There is no list with that ID."
167+
}
168+
169+
## Members of a subscriber list [/lists/{list}/members]
170+
171+
### Retrieve all members of a subscriber list [GET]
172+
173+
+ Request (application/json)
174+
175+
+ Response 200 (application/json)
176+
177+
+ Body
178+
179+
{
180+
"creation_date" => "2016-07-22T15:01:17+00:00",
181+
"email" => "[email protected]",
182+
"confirmed" => true,
183+
"blacklisted" => true,
184+
"bounce_count" => 17,
185+
"unique_id" => "95feb7fe7e06e6c11ca8d0c48cb46e89",
186+
"html_email" => true,
187+
"disabled" => true,
188+
"id" => 1,
189+
},
190+
{
191+
"creation_date" => "2017-07-22T15:12:17+00:00",
192+
"email" => "[email protected]",
193+
"confirmed" => true,
194+
"blacklisted" => false,
195+
"bounce_count" => 1,
196+
"unique_id" => "95feb7fe7e06e6c11ca8d0c48cb4616d",
197+
"html_email" => false,
198+
"disabled" => false,
199+
"id" => 2,
200+
}
201+
202+
+ Response 403 (application/json)
203+
204+
+ Body
205+
206+
{
207+
"code": 403,
208+
"message": "No valid session key was provided as basic auth password."
209+
}
210+
211+
+ Response 404 (application/json)
212+
213+
+ Body
214+
215+
{
216+
"code": 404,
217+
"message": "There is no list with that ID."
218+
}
219+
130220

131221
## Members of a subscriber list [/lists/{list}/members]
132222

Tests/Integration/Controller/ListControllerTest.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,66 @@ public function getListsWithCurrentSessionKeyReturnsListData()
111111
);
112112
}
113113

114+
/**
115+
* @test
116+
*/
117+
public function getListWithoutSessionKeyForExistingListReturnsForbiddenStatus()
118+
{
119+
$this->getDataSet()->addTable(static::LISTS_TABLE_NAME, __DIR__ . '/Fixtures/SubscriberList.csv');
120+
$this->applyDatabaseChanges();
121+
122+
$this->client->request('get', '/api/v2/lists/1');
123+
124+
$this->assertHttpForbidden();
125+
}
126+
127+
/**
128+
* @test
129+
*/
130+
public function getListWithCurrentSessionKeyForExistingListReturnsOkayStatus()
131+
{
132+
$this->getDataSet()->addTable(static::LISTS_TABLE_NAME, __DIR__ . '/Fixtures/SubscriberList.csv');
133+
$this->applyDatabaseChanges();
134+
135+
$this->authenticatedJsonRequest('get', '/api/v2/lists/1');
136+
137+
$this->assertHttpOkay();
138+
}
139+
140+
/**
141+
* @test
142+
*/
143+
public function getListWithCurrentSessionKeyForInexistentListReturnsNotFoundStatus()
144+
{
145+
$this->authenticatedJsonRequest('get', '/api/v2/lists/999');
146+
147+
$this->assertHttpNotFound();
148+
}
149+
150+
/**
151+
* @test
152+
*/
153+
public function getListWithCurrentSessionKeyReturnsListData()
154+
{
155+
$this->getDataSet()->addTable(static::LISTS_TABLE_NAME, __DIR__ . '/Fixtures/SubscriberList.csv');
156+
$this->applyDatabaseChanges();
157+
158+
$this->authenticatedJsonRequest('get', '/api/v2/lists/1');
159+
160+
$this->assertJsonResponseContentEquals(
161+
[
162+
'name' => 'News',
163+
'description' => 'News (and some fun stuff)',
164+
'creation_date' => '2016-06-22T15:01:17+00:00',
165+
'list_position' => 12,
166+
'subject_prefix' => 'phpList',
167+
'public' => true,
168+
'category' => 'news',
169+
'id' => 1,
170+
]
171+
);
172+
}
173+
114174
/**
115175
* @test
116176
*/

0 commit comments

Comments
 (0)