Skip to content

Commit b88a1fe

Browse files
authored
Meetings API logic changes (#419)
* logic for creating long term room * backwards compatibility shim
1 parent 2664ea6 commit b88a1fe

File tree

5 files changed

+122
-35
lines changed

5 files changed

+122
-35
lines changed

src/Meetings/Client.php

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66

77
use GuzzleHttp\Psr7\MultipartStream;
88
use Laminas\Diactoros\Request;
9+
use Psr\Http\Client\ClientExceptionInterface;
910
use Vonage\Client\APIClient;
1011
use Vonage\Client\APIResource;
12+
use Vonage\Client\Exception\Exception;
1113
use Vonage\Client\Exception\NotFound;
1214
use Vonage\Entity\Filter\KeyValueFilter;
1315
use Vonage\Entity\Hydrator\ArrayHydrator;
@@ -36,13 +38,32 @@ public function getRoom(string $id): Room
3638
return $room;
3739
}
3840

39-
public function createRoom(string $displayName): Room
41+
/**
42+
*
43+
* Creates a room. Originally this was a string with the display name
44+
* So there is backwards compatibility cases to cover
45+
*
46+
* @param $room string|Room
47+
*
48+
* @return Room
49+
* @throws ClientExceptionInterface
50+
* @throws Exception
51+
*/
52+
public function createRoom(Room|string $room): Room
4053
{
54+
if (is_string($room)) {
55+
trigger_error(
56+
'Passing a display name string to createRoom is deprecated, please use a Room object',
57+
E_USER_DEPRECATED
58+
);
59+
$roomEntity = new Room();
60+
$roomEntity->fromArray(['display_name' => $room]);
61+
$room = $roomEntity;
62+
}
63+
4164
$this->api->setBaseUri('/rooms');
4265

43-
$response = $this->api->create([
44-
'display_name' => $displayName
45-
]);
66+
$response = $this->api->create($room->toArray());
4667

4768
$room = new Room();
4869
$room->fromArray($response);

src/Meetings/Room.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,28 @@
66

77
class Room implements ArrayHydrateInterface
88
{
9-
private array $data;
9+
protected array $data;
1010

11-
public function fromArray(array $data): void
11+
public function fromArray(array $data): static
1212
{
13+
if (!isset($data['display_name'])) {
14+
throw new \InvalidArgumentException('A room object must contain a display_name');
15+
}
16+
1317
$this->data = $data;
18+
19+
return $this;
1420
}
1521

1622
public function toArray(): array
1723
{
18-
return $this->data;
24+
return array_filter($this->data, static function ($value) {
25+
return $value !== '';
26+
});
1927
}
2028

21-
public function __get($name)
29+
public function __get($value)
2230
{
23-
return $this->data[$name];
31+
return $this->data[$value];
2432
}
2533
}

test/Meetings/ClientTest.php

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,17 @@ public function testWillCreateRoom(): void
117117
return true;
118118
}))->willReturn($this->getResponse('create-room-success', 201));
119119

120-
$response = $this->meetingsClient->createRoom('test-room');
120+
$room = new Room();
121+
$room->fromArray(['display_name' => 'test-room']);
122+
123+
$response = $this->meetingsClient->createRoom($room);
121124
$this->assertInstanceOf(Room::class, $response);
122125

123126
$this->assertEquals('test-room', $response->display_name);
127+
$this->assertEquals('instant', $response->type);
124128
}
125129

126-
public function testClientWillHandleUnauthorizedRequests(): void
130+
public function testWillCreateLongTermRoom(): void
127131
{
128132
$this->vonageClient->send(Argument::that(function (RequestInterface $request) {
129133
$this->assertEquals('POST', $request->getMethod());
@@ -134,11 +138,42 @@ public function testClientWillHandleUnauthorizedRequests(): void
134138

135139
$this->assertRequestJsonBodyContains('display_name', 'test-room', $request);
136140
return true;
141+
}))->willReturn($this->getResponse('create-long-term-room-success', 201));
142+
143+
$room = new Room();
144+
$room->fromArray([
145+
'display_name' => 'test-room',
146+
'type' => 'long_term',
147+
'expires_at' => '2023-01-30T00:47:04+0000'
148+
]);
149+
150+
$response = $this->meetingsClient->createRoom($room);
151+
$this->assertInstanceOf(Room::class, $response);
152+
153+
$this->assertEquals('test-room', $response->display_name);
154+
$this->assertEquals('long_term', $response->type);
155+
}
156+
157+
public function testClientWillHandleUnauthorizedRequests(): void
158+
{
159+
$this->vonageClient->send(Argument::that(function (RequestInterface $request) {
160+
$this->assertEquals('POST', $request->getMethod());
161+
162+
$uri = $request->getUri();
163+
$uriString = $uri->__toString();
164+
$this->assertEquals('https://api-eu.vonage.com/meetings/rooms', $uriString);
165+
166+
$this->assertRequestJsonBodyContains('display_name', 'something', $request);
167+
return true;
137168
}))->willReturn($this->getResponse('empty', 403));
138169

139170
$this->expectException(Client\Exception\Credentials::class);
140171
$this->expectExceptionMessage('You are not authorised to perform this request');
141-
$response = $this->meetingsClient->createRoom('test-room');
172+
173+
$room = new Room();
174+
$room->fromArray(['display_name' => 'something']);
175+
176+
$response = $this->meetingsClient->createRoom($room);
142177
}
143178

144179
public function testClientWillHandleNotFoundResponse(): void
@@ -173,7 +208,10 @@ public function testClientWillHandleValidationError(): void
173208
$this->expectException(Validation::class);
174209
$this->expectExceptionMessage('The request data was invalid');
175210

176-
$response = $this->meetingsClient->createRoom('test-room');
211+
$room = new Room();
212+
$room->fromArray(['display_name' => 'test-room']);
213+
214+
$response = $this->meetingsClient->createRoom($room);
177215
}
178216

179217
public function testWillGetRoomDetails(): void
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"display_name": "test-room",
3+
"metadata": "Welcome to my custom room",
4+
"type": "long_term",
5+
"recording_options": {
6+
"auto_record": false,
7+
"record_only_owner": false
8+
},
9+
"theme_id": "ef2b46f3-8ebb-437e-a671-272e4990fbc8",
10+
"join_approval_level": "none",
11+
"initial_join_options": {
12+
"microphone_state": "on"
13+
},
14+
"callback_urls": {
15+
"rooms_callback_url": "https://example.com/rooms",
16+
"sessions_callback_url": "https://example.com/sessions",
17+
"recordings_callback_url": "https://example.com/recordings"
18+
},
19+
"available_features": {
20+
"is_recording_available": true,
21+
"is_chat_available": true,
22+
"is_whiteboard_available": true,
23+
"is_locale_switcher_available": true,
24+
"is_captions_available": false
25+
},
26+
"ui_settings": {
27+
"language": "es"
28+
}
29+
}
Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,29 @@
11
{
2-
"id": "abc123",
32
"display_name": "test-room",
4-
"metadata": "abc123",
5-
"type": "abc123",
3+
"metadata": "Welcome to my custom room",
4+
"type": "instant",
65
"recording_options": {
76
"auto_record": false,
87
"record_only_owner": false
98
},
10-
"meeting_code": "123456789",
11-
"is_available": false,
12-
"theme_id": "abc123",
13-
"created_at": "abc123",
14-
"expires_at": "abc123",
15-
"expire_after_use": false,
16-
"join_approval_level": "abc123",
9+
"theme_id": "ef2b46f3-8ebb-437e-a671-272e4990fbc8",
10+
"join_approval_level": "none",
1711
"initial_join_options": {
18-
"microphone_state": "default"
12+
"microphone_state": "on"
1913
},
2014
"callback_urls": {
21-
"rooms_callback_url": "https://example.com",
22-
"sessions_callback_url": "https://example.com",
23-
"recordings_callback_url": "https://example.com"
15+
"rooms_callback_url": "https://example.com/rooms",
16+
"sessions_callback_url": "https://example.com/sessions",
17+
"recordings_callback_url": "https://example.com/recordings"
2418
},
2519
"available_features": {
2620
"is_recording_available": true,
2721
"is_chat_available": true,
28-
"is_whiteboard_available": true
22+
"is_whiteboard_available": true,
23+
"is_locale_switcher_available": true,
24+
"is_captions_available": false
2925
},
30-
"_links": {
31-
"guest_url": {
32-
"href": "https://meetings.vonage.com/123456789"
33-
},
34-
"host_url": {
35-
"href": "https://meetings.vonage.com/123456789?participant_token=xyz"
36-
}
26+
"ui_settings": {
27+
"language": "es"
3728
}
3829
}

0 commit comments

Comments
 (0)