Skip to content

Commit ad2c358

Browse files
committed
Refactor endpoint properties and update API response handling for consistency
1 parent c7433fb commit ad2c358

6 files changed

Lines changed: 30 additions & 32 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ composer.lock
44
.phpunit.result.cache
55
composer.phar
66
.idea
7+
.env*

src/Voice/Controllers/APIController.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2552,7 +2552,7 @@ public function createEndpoint(
25522552
}
25532553
$this->validateResponse($_httpResponse, $_httpContext);
25542554
$mapper = $this->getJsonMapper();
2555-
$deserializedResponse = $mapper->mapClass($response->body, 'BandwidthLib\\Voice\\Models\\CreateEndpointResponse');
2555+
$deserializedResponse = $mapper->mapClass($response->body->data, 'BandwidthLib\\Voice\\Models\\CreateEndpointResponse');
25562556
return new ApiResponse($response->code, $response->headers, $deserializedResponse);
25572557
}
25582558

@@ -2594,7 +2594,7 @@ public function listEndpoints(
25942594
}
25952595
$this->validateResponse($_httpResponse, $_httpContext);
25962596
$mapper = $this->getJsonMapper();
2597-
$deserializedResponse = $mapper->mapClassArray($response->body, 'BandwidthLib\\Voice\\Models\\Endpoint');
2597+
$deserializedResponse = $mapper->mapClassArray($response->body->data, 'BandwidthLib\\Voice\\Models\\Endpoint');
25982598
return new ApiResponse($response->code, $response->headers, $deserializedResponse);
25992599
}
26002600

@@ -2634,7 +2634,7 @@ public function getEndpoint(
26342634
}
26352635
$this->validateResponse($_httpResponse, $_httpContext);
26362636
$mapper = $this->getJsonMapper();
2637-
$deserializedResponse = $mapper->mapClass($response->body, 'BandwidthLib\\Voice\\Models\\Endpoint');
2637+
$deserializedResponse = $mapper->mapClass($response->body->data, 'BandwidthLib\\Voice\\Models\\Endpoint');
26382638
return new ApiResponse($response->code, $response->headers, $deserializedResponse);
26392639
}
26402640

@@ -2657,7 +2657,8 @@ public function deleteEndpoint(
26572657
));
26582658
$_queryUrl = APIHelper::cleanUrl($this->config->getBaseUri(Servers::PHONENUMBERLOOKUPDEFAULT) . $_queryBuilder);
26592659
$_headers = array(
2660-
'user-agent' => BaseController::USER_AGENT
2660+
'user-agent' => BaseController::USER_AGENT,
2661+
'Content-Type' => '', // prevent curl from injecting Content-Type: application/x-www-form-urlencoded on empty DELETE body
26612662
);
26622663
$this->configureOAuth2Auth($_headers);
26632664
$_httpRequest = new HttpRequest(HttpMethod::DELETE, $_headers, $_queryUrl);

src/Voice/Models/CreateEndpointRequest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,12 @@ class CreateEndpointRequest {
2020
public $eventFallbackUrl;
2121
/** @var string|null */
2222
public $tag;
23-
/** @var array|null */
24-
public $connectionMetadata;
2523

26-
public function __construct($type, $direction = null, $eventCallbackUrl = null, $eventFallbackUrl = null, $tag = null, $connectionMetadata = null) {
24+
public function __construct($type, $direction = null, $eventCallbackUrl = null, $eventFallbackUrl = null, $tag = null) {
2725
$this->type = $type;
2826
$this->direction = $direction;
2927
$this->eventCallbackUrl = $eventCallbackUrl;
3028
$this->eventFallbackUrl = $eventFallbackUrl;
3129
$this->tag = $tag;
32-
$this->connectionMetadata = $connectionMetadata;
3330
}
3431
}

src/Voice/Models/CreateEndpointResponse.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,22 @@ class CreateEndpointResponse {
1717
/** @var string|null */
1818
public $status;
1919
/** @var string|null */
20-
public $createdTime;
20+
public $creationTimestamp;
2121
/** @var string|null */
22-
public $updatedTime;
22+
public $expirationTimestamp;
2323
/** @var string|null */
2424
public $tag;
2525
/** @var array|null */
2626
public $devices;
2727
/** @var string|null */
2828
public $token;
2929

30-
public function __construct($endpointId = null, $type = null, $status = null, $createdTime = null, $updatedTime = null, $tag = null, $devices = null, $token = null) {
30+
public function __construct($endpointId = null, $type = null, $status = null, $creationTimestamp = null, $expirationTimestamp = null, $tag = null, $devices = null, $token = null) {
3131
$this->endpointId = $endpointId;
3232
$this->type = $type;
3333
$this->status = $status;
34-
$this->createdTime = $createdTime;
35-
$this->updatedTime = $updatedTime;
34+
$this->creationTimestamp = $creationTimestamp;
35+
$this->expirationTimestamp = $expirationTimestamp;
3636
$this->tag = $tag;
3737
$this->devices = $devices;
3838
$this->token = $token;

src/Voice/Models/Endpoint.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
class Endpoint {
1313
/** @var string|null */
14-
public $id;
14+
public $endpointId;
1515
/** @var string|null */
1616
public $type;
1717
/** @var string|null */
@@ -27,20 +27,20 @@ class Endpoint {
2727
/** @var array|null */
2828
public $devices;
2929
/** @var string|null */
30-
public $createdTime;
30+
public $creationTimestamp;
3131
/** @var string|null */
32-
public $updatedTime;
32+
public $expirationTimestamp;
3333

34-
public function __construct($id = null, $type = null, $status = null, $direction = null, $eventCallbackUrl = null, $eventFallbackUrl = null, $tag = null, $devices = null, $createdTime = null, $updatedTime = null) {
35-
$this->id = $id;
34+
public function __construct($endpointId = null, $type = null, $status = null, $direction = null, $eventCallbackUrl = null, $eventFallbackUrl = null, $tag = null, $devices = null, $creationTimestamp = null, $expirationTimestamp = null) {
35+
$this->endpointId = $endpointId;
3636
$this->type = $type;
3737
$this->status = $status;
3838
$this->direction = $direction;
3939
$this->eventCallbackUrl = $eventCallbackUrl;
4040
$this->eventFallbackUrl = $eventFallbackUrl;
4141
$this->tag = $tag;
4242
$this->devices = $devices;
43-
$this->createdTime = $createdTime;
44-
$this->updatedTime = $updatedTime;
43+
$this->creationTimestamp = $creationTimestamp;
44+
$this->expirationTimestamp = $expirationTimestamp;
4545
}
4646
}

tests/ApiTest.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,7 @@ public function testCreateListGetDeleteEndpoint() {
261261
'INBOUND',
262262
getenv("BASE_CALLBACK_URL") . "/brtc/events",
263263
null,
264-
'php-sdk-test',
265-
["meta" => "data"]
264+
'php-sdk-test'
266265
);
267266
try {
268267
$createResp = $voiceClient->createEndpoint($accountId, $createReq)->getResult();
@@ -279,7 +278,7 @@ public function testCreateListGetDeleteEndpoint() {
279278
$this->fail("[{$e->getCode()}] {$e->getMessage()}");
280279
}
281280
$this->assertIsArray($endpoints);
282-
$ids = array_map(fn($ep) => $ep->id, $endpoints);
281+
$ids = array_map(fn($ep) => $ep->endpointId, $endpoints);
283282
$this->assertContains($createResp->endpointId, $ids, 'Created endpoint should be in list');
284283

285284
// Get endpoint
@@ -288,7 +287,7 @@ public function testCreateListGetDeleteEndpoint() {
288287
} catch (BandwidthLib\APIException $e) {
289288
$this->fail("[{$e->getCode()}] {$e->getMessage()}");
290289
}
291-
$this->assertEquals($createResp->endpointId, $endpoint->id);
290+
$this->assertEquals($createResp->endpointId, $endpoint->endpointId);
292291
$this->assertEquals('WEBRTC', $endpoint->type);
293292

294293
// Update endpoint BXML
@@ -326,8 +325,8 @@ public function testCreateEndpointResponseFields() {
326325
$this->assertIsString($createResp->endpointId);
327326
$this->assertEquals('WEBRTC', $createResp->type);
328327
$this->assertNotNull($createResp->status);
329-
$this->assertNotNull($createResp->createdTime);
330-
$this->assertNotNull($createResp->updatedTime);
328+
$this->assertNotNull($createResp->creationTimestamp);
329+
$this->assertNotNull($createResp->expirationTimestamp);
331330
$this->assertEquals('php-sdk-fields-test', $createResp->tag);
332331

333332
// Cleanup
@@ -361,12 +360,12 @@ public function testGetEndpointFields() {
361360
$this->fail("[{$e->getCode()}] {$e->getMessage()}");
362361
}
363362
$this->assertInstanceOf(BandwidthLib\Voice\Models\Endpoint::class, $endpoint);
364-
$this->assertEquals($endpointId, $endpoint->id);
363+
$this->assertEquals($endpointId, $endpoint->endpointId);
365364
$this->assertEquals('WEBRTC', $endpoint->type);
366365
$this->assertNotNull($endpoint->status);
367366
$this->assertNotNull($endpoint->direction);
368-
$this->assertNotNull($endpoint->createdTime);
369-
$this->assertNotNull($endpoint->updatedTime);
367+
$this->assertNotNull($endpoint->creationTimestamp);
368+
$this->assertNotNull($endpoint->expirationTimestamp);
370369
$this->assertEquals('php-sdk-get-test', $endpoint->tag);
371370

372371
// Cleanup
@@ -402,7 +401,7 @@ public function testListEndpointsContainsCreated() {
402401
$this->assertIsArray($endpoints);
403402
$this->assertNotEmpty($endpoints);
404403

405-
$ids = array_map(fn($ep) => $ep->id, $endpoints);
404+
$ids = array_map(fn($ep) => $ep->endpointId, $endpoints);
406405
$this->assertContains($endpointId, $ids, 'Newly created endpoint should appear in list');
407406

408407
// Cleanup
@@ -435,7 +434,7 @@ public function testListEndpointsEachItemIsEndpointInstance() {
435434
}
436435
foreach ($endpoints as $ep) {
437436
$this->assertInstanceOf(BandwidthLib\Voice\Models\Endpoint::class, $ep);
438-
$this->assertNotNull($ep->id);
437+
$this->assertNotNull($ep->endpointId);
439438
$this->assertNotNull($ep->type);
440439
$this->assertNotNull($ep->status);
441440
}
@@ -513,7 +512,7 @@ public function testDeleteEndpointRemovedFromList() {
513512
} catch (BandwidthLib\APIException $e) {
514513
$this->fail("[{$e->getCode()}] {$e->getMessage()}");
515514
}
516-
$ids = array_map(fn($ep) => $ep->id, $endpoints);
515+
$ids = array_map(fn($ep) => $ep->endpointId, $endpoints);
517516
$this->assertNotContains($endpointId, $ids, 'Deleted endpoint should not appear in list');
518517
}
519518
}

0 commit comments

Comments
 (0)