Skip to content

Commit eb39a00

Browse files
smoghe-bwclaude
andcommitted
Fix models to match BRTC API spec: query params, Link, and ErrorObject
- listEndpoints: replace direction/pageToken/pageSize with afterCursor/limit per spec - Link model: add missing method field - ErrorObject model: add missing id, code, source fields - Add new ErrorSource model for error source details (parameter, field, header, reference) - Update unit and integration tests for new model fields Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 9682727 commit eb39a00

6 files changed

Lines changed: 123 additions & 23 deletions

File tree

src/BRTC/Controllers/APIController.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,19 +102,17 @@ public function createEndpoint(
102102
* @param string $accountId
103103
* @param string|null $type Filter by endpoint type
104104
* @param string|null $status Filter by endpoint status
105-
* @param string|null $direction Filter by endpoint direction
106-
* @param string|null $pageToken Pagination token
107-
* @param int|null $pageSize Number of results per page
105+
* @param string|null $afterCursor Pagination cursor from previous response
106+
* @param int|null $limit Maximum number of endpoints to return (1-1000, default 100)
108107
* @return ApiResponse response from the API call
109108
* @throws APIException Thrown if API call fails
110109
*/
111110
public function listEndpoints(
112111
string $accountId,
113112
?string $type = null,
114113
?string $status = null,
115-
?string $direction = null,
116-
?string $pageToken = null,
117-
?int $pageSize = null
114+
?string $afterCursor = null,
115+
?int $limit = null
118116
) {
119117
//prepare query string for API call
120118
$_queryBuilder = '/accounts/{accountId}/endpoints';
@@ -126,11 +124,10 @@ public function listEndpoints(
126124

127125
//process optional query parameters
128126
APIHelper::appendUrlWithQueryParameters($_queryBuilder, array(
129-
'type' => $type,
130-
'status' => $status,
131-
'direction' => $direction,
132-
'pageToken' => $pageToken,
133-
'pageSize' => $pageSize,
127+
'type' => $type,
128+
'status' => $status,
129+
'afterCursor' => $afterCursor,
130+
'limit' => $limit,
134131
));
135132

136133
//validate and preprocess url

src/BRTC/Models/ErrorObject.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,36 @@
1111

1212
class ErrorObject implements \JsonSerializable
1313
{
14+
/** @var string */
15+
public $id;
1416
/** @var string */
1517
public $type;
1618
/** @var string */
1719
public $description;
20+
/** @var string */
21+
public $code;
22+
/** @var ErrorSource|null */
23+
public $source;
1824

1925
public function __construct()
2026
{
21-
if (2 == func_num_args()) {
22-
$this->type = func_get_arg(0);
23-
$this->description = func_get_arg(1);
27+
if (5 == func_num_args()) {
28+
$this->id = func_get_arg(0);
29+
$this->type = func_get_arg(1);
30+
$this->description = func_get_arg(2);
31+
$this->code = func_get_arg(3);
32+
$this->source = func_get_arg(4);
2433
}
2534
}
2635

2736
public function jsonSerialize(): array
2837
{
2938
$json = array();
39+
$json['id'] = $this->id;
3040
$json['type'] = $this->type;
3141
$json['description'] = $this->description;
42+
$json['code'] = $this->code;
43+
$json['source'] = $this->source;
3244

3345
return array_filter($json);
3446
}

src/BRTC/Models/ErrorSource.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/**
3+
* ErrorSource.php
4+
*
5+
* Model representing the source of an error in API responses
6+
*
7+
* @copyright Bandwidth INC
8+
*/
9+
10+
namespace BandwidthLib\BRTC\Models;
11+
12+
class ErrorSource implements \JsonSerializable
13+
{
14+
/** @var string|null */
15+
public $parameter;
16+
/** @var string|null */
17+
public $field;
18+
/** @var string|null */
19+
public $header;
20+
/** @var string|null */
21+
public $reference;
22+
23+
public function __construct()
24+
{
25+
if (4 == func_num_args()) {
26+
$this->parameter = func_get_arg(0);
27+
$this->field = func_get_arg(1);
28+
$this->header = func_get_arg(2);
29+
$this->reference = func_get_arg(3);
30+
}
31+
}
32+
33+
public function jsonSerialize(): array
34+
{
35+
$json = array();
36+
$json['parameter'] = $this->parameter;
37+
$json['field'] = $this->field;
38+
$json['header'] = $this->header;
39+
$json['reference'] = $this->reference;
40+
41+
return array_filter($json);
42+
}
43+
}

src/BRTC/Models/Link.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,16 @@ class Link implements \JsonSerializable
1515
public $rel;
1616
/** @var string|null */
1717
public $href;
18+
/** @var string|null */
19+
public $method;
1820

1921
public function __construct()
2022
{
21-
if (2 == func_num_args()) {
23+
if (3 == func_num_args()) {
24+
$this->rel = func_get_arg(0);
25+
$this->href = func_get_arg(1);
26+
$this->method = func_get_arg(2);
27+
} elseif (2 == func_num_args()) {
2228
$this->rel = func_get_arg(0);
2329
$this->href = func_get_arg(1);
2430
}
@@ -27,8 +33,9 @@ public function __construct()
2733
public function jsonSerialize(): array
2834
{
2935
$json = array();
30-
$json['rel'] = $this->rel;
31-
$json['href'] = $this->href;
36+
$json['rel'] = $this->rel;
37+
$json['href'] = $this->href;
38+
$json['method'] = $this->method;
3239

3340
return array_filter($json);
3441
}

tests/ApiTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ public function testCreateListGetDeleteEndpoint() {
270270
$this->assertInstanceOf(BandwidthLib\BRTC\Models\Link::class, $createResp->links[0]);
271271
$this->assertIsString($createResp->links[0]->rel);
272272
$this->assertIsString($createResp->links[0]->href);
273+
$this->assertIsString($createResp->links[0]->method);
273274
$this->assertNotNull($createResp->data);
274275
$this->assertInstanceOf(BandwidthLib\BRTC\Models\CreateEndpointResponseData::class, $createResp->data);
275276
$this->assertNotNull($createResp->data->endpointId);
@@ -294,6 +295,7 @@ public function testCreateListGetDeleteEndpoint() {
294295
$this->assertInstanceOf(BandwidthLib\BRTC\Models\Link::class, $listResp->links[0]);
295296
$this->assertIsString($listResp->links[0]->rel);
296297
$this->assertIsString($listResp->links[0]->href);
298+
$this->assertIsString($listResp->links[0]->method);
297299
$this->assertNotNull($listResp->page);
298300
$this->assertInstanceOf(BandwidthLib\BRTC\Models\Page::class, $listResp->page);
299301
$this->assertIsArray($listResp->data);
@@ -317,6 +319,7 @@ public function testCreateListGetDeleteEndpoint() {
317319
$this->assertInstanceOf(BandwidthLib\BRTC\Models\Link::class, $getResp->links[0]);
318320
$this->assertIsString($getResp->links[0]->rel);
319321
$this->assertIsString($getResp->links[0]->href);
322+
$this->assertIsString($getResp->links[0]->method);
320323
$this->assertNotNull($getResp->data);
321324
$this->assertInstanceOf(BandwidthLib\BRTC\Models\Endpoint::class, $getResp->data);
322325
$this->assertEquals($endpointId, $getResp->data->endpointId);

tests/BrtcModelTest.php

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,24 +97,62 @@ public function testPageModelDefaults() {
9797
}
9898

9999
public function testLinkModel() {
100-
$link = new BandwidthLib\BRTC\Models\Link('self', 'https://api.bandwidth.com/endpoints');
100+
$link = new BandwidthLib\BRTC\Models\Link('self', 'https://api.bandwidth.com/endpoints', 'GET');
101101

102102
$this->assertEquals('self', $link->rel);
103103
$this->assertEquals('https://api.bandwidth.com/endpoints', $link->href);
104+
$this->assertEquals('GET', $link->method);
104105

105106
$json = $link->jsonSerialize();
106107
$this->assertEquals('self', $json['rel']);
107108
$this->assertEquals('https://api.bandwidth.com/endpoints', $json['href']);
109+
$this->assertEquals('GET', $json['method']);
110+
}
111+
112+
public function testLinkModelWithoutMethod() {
113+
$link = new BandwidthLib\BRTC\Models\Link('self', 'https://api.bandwidth.com/endpoints');
114+
115+
$this->assertEquals('self', $link->rel);
116+
$this->assertEquals('https://api.bandwidth.com/endpoints', $link->href);
117+
$this->assertNull($link->method);
108118
}
109119

110120
public function testErrorObjectModel() {
111-
$error = new BandwidthLib\BRTC\Models\ErrorObject('VALIDATION_ERROR', 'Field is required');
121+
$source = new BandwidthLib\BRTC\Models\ErrorSource('accountId', null, null, null);
122+
$error = new BandwidthLib\BRTC\Models\ErrorObject(
123+
'59512d87-7a92-4040-8e4a-78fb772019b9',
124+
'invalid_parameter',
125+
'accountId must not contain any characters other than numbers.',
126+
'400',
127+
$source
128+
);
112129

113-
$this->assertEquals('VALIDATION_ERROR', $error->type);
114-
$this->assertEquals('Field is required', $error->description);
130+
$this->assertEquals('59512d87-7a92-4040-8e4a-78fb772019b9', $error->id);
131+
$this->assertEquals('invalid_parameter', $error->type);
132+
$this->assertEquals('accountId must not contain any characters other than numbers.', $error->description);
133+
$this->assertEquals('400', $error->code);
134+
$this->assertInstanceOf(BandwidthLib\BRTC\Models\ErrorSource::class, $error->source);
135+
$this->assertEquals('accountId', $error->source->parameter);
115136

116137
$json = $error->jsonSerialize();
117-
$this->assertEquals('VALIDATION_ERROR', $json['type']);
118-
$this->assertEquals('Field is required', $json['description']);
138+
$this->assertEquals('59512d87-7a92-4040-8e4a-78fb772019b9', $json['id']);
139+
$this->assertEquals('invalid_parameter', $json['type']);
140+
$this->assertEquals('accountId must not contain any characters other than numbers.', $json['description']);
141+
$this->assertEquals('400', $json['code']);
142+
}
143+
144+
public function testErrorSourceModel() {
145+
$source = new BandwidthLib\BRTC\Models\ErrorSource('accountId', 'name', 'Authorization', 'e-123');
146+
147+
$this->assertEquals('accountId', $source->parameter);
148+
$this->assertEquals('name', $source->field);
149+
$this->assertEquals('Authorization', $source->header);
150+
$this->assertEquals('e-123', $source->reference);
151+
152+
$json = $source->jsonSerialize();
153+
$this->assertEquals('accountId', $json['parameter']);
154+
$this->assertEquals('name', $json['field']);
155+
$this->assertEquals('Authorization', $json['header']);
156+
$this->assertEquals('e-123', $json['reference']);
119157
}
120158
}

0 commit comments

Comments
 (0)