1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* Copyright 2014 Brian Smith <[email protected]>. |
5
|
|
|
* |
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
7
|
|
|
* you may not use this file except in compliance with the License. |
8
|
|
|
* You may obtain a copy of the License at |
9
|
|
|
* |
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
11
|
|
|
* |
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15
|
|
|
* See the License for the specific language governing permissions and |
16
|
|
|
* limitations under the License. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace phparia\Api; |
20
|
|
|
|
21
|
|
|
use Pest_Conflict; |
22
|
|
|
use Pest_NotFound; |
23
|
|
|
use phparia\Client\AriClientAware; |
24
|
|
|
use phparia\Exception\ConflictException; |
25
|
|
|
use phparia\Exception\NotFoundException; |
26
|
|
|
use phparia\Resources\LiveRecording; |
27
|
|
|
use phparia\Resources\StoredRecording; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Recordings API |
31
|
|
|
* |
32
|
|
|
* @author Brian Smith <[email protected]> |
33
|
|
|
*/ |
34
|
|
|
class Recordings extends AriClientAware |
35
|
|
|
{ |
36
|
|
|
/** |
37
|
|
|
* List recordings that are complete. |
38
|
|
|
* |
39
|
|
|
* @return StoredRecording[] |
40
|
|
|
*/ |
41
|
1 |
|
public function getRecordings() |
42
|
|
|
{ |
43
|
1 |
|
$uri = '/recordings/stored'; |
44
|
1 |
|
$response = $this->client->getEndpoint()->get($uri); |
45
|
|
|
|
46
|
|
|
$recordings = []; |
47
|
|
|
foreach ((array)$response as $recording) { |
48
|
|
|
$recordings[] = new StoredRecording($recording); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
return $recordings; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Get a stored recording's details. |
56
|
|
|
* |
57
|
|
|
* @param string $recordingName The name of the recording |
58
|
|
|
* @return StoredRecording |
59
|
|
|
* @throws NotFoundException |
60
|
|
|
*/ |
61
|
1 |
|
public function getRecording($recordingName) |
62
|
|
|
{ |
63
|
1 |
|
$uri = "/recordings/stored/$recordingName"; |
64
|
|
|
try { |
65
|
1 |
|
$response = $this->client->getEndpoint()->get($uri); |
66
|
1 |
|
} catch (Pest_NotFound $e) { // Playback not found |
67
|
1 |
|
throw new NotFoundException($e); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
return new StoredRecording($response); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Delete a stored recording. |
75
|
|
|
* |
76
|
|
|
* @param string $recordingName The name of the recording |
77
|
|
|
* @return StoredRecording |
78
|
|
|
* @throws NotFoundException |
79
|
|
|
*/ |
80
|
1 |
View Code Duplication |
public function deleteRecording($recordingName) |
|
|
|
|
81
|
|
|
{ |
82
|
1 |
|
$uri = "/recordings/stored/$recordingName"; |
83
|
|
|
try { |
84
|
1 |
|
$this->client->getEndpoint()->delete($uri); |
85
|
1 |
|
} catch (Pest_NotFound $e) { // Playback not found |
86
|
1 |
|
throw new NotFoundException($e); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Copy a stored recording. |
92
|
|
|
* |
93
|
|
|
* @param string $recordingName The name of the recording to copy |
94
|
|
|
* @param string $destinationRecordingName (required) The destination name of the recording |
95
|
|
|
* @return StoredRecording |
96
|
|
|
* @throws ConflictException |
97
|
|
|
* @throws NotFoundException |
98
|
|
|
*/ |
99
|
1 |
View Code Duplication |
public function copyRecording($recordingName, $destinationRecordingName) |
|
|
|
|
100
|
|
|
{ |
101
|
1 |
|
$uri = "/recordings/stored/$recordingName/copy"; |
102
|
|
|
try { |
103
|
1 |
|
$response = $this->client->getEndpoint()->post($uri, array( |
104
|
1 |
|
'destinationRecordingName' => $destinationRecordingName, |
105
|
1 |
|
)); |
106
|
1 |
|
} catch (Pest_NotFound $e) { |
107
|
1 |
|
throw new NotFoundException($e); |
108
|
|
|
} catch (Pest_Conflict $e) { |
109
|
|
|
throw new ConflictException($e); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
return new StoredRecording($response); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Get live recording |
117
|
|
|
* |
118
|
|
|
* @param string $recordingName The name of the recording |
119
|
|
|
* @return LiveRecording |
120
|
|
|
* @throws NotFoundException |
121
|
|
|
*/ |
122
|
|
|
public function getLiveRecording($recordingName) |
123
|
|
|
{ |
124
|
|
|
$uri = "/recordings/live/$recordingName"; |
125
|
|
|
try { |
126
|
|
|
$response = $this->client->getEndpoint()->get($uri); |
127
|
|
|
} catch (Pest_NotFound $e) { // Playback not found |
128
|
|
|
throw new NotFoundException($e); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
return new LiveRecording($this->client, $response); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Stop a live recording and discard it. |
136
|
|
|
* |
137
|
|
|
* @param string $recordingName The name of the recording |
138
|
|
|
* @throws NotFoundException |
139
|
|
|
*/ |
140
|
|
View Code Duplication |
public function deleteLiveRecording($recordingName) |
|
|
|
|
141
|
|
|
{ |
142
|
|
|
$uri = "/recordings/live/$recordingName"; |
143
|
|
|
try { |
144
|
|
|
$this->client->getEndpoint()->delete($uri); |
145
|
|
|
} catch (Pest_NotFound $e) { // Playback not found |
146
|
|
|
throw new NotFoundException($e); |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* Stop a live recording and store it. |
152
|
|
|
* |
153
|
|
|
* @param string $recordingName The name of the recording |
154
|
|
|
* @throws NotFoundException |
155
|
|
|
*/ |
156
|
|
View Code Duplication |
public function stopLiveRecording($recordingName) |
|
|
|
|
157
|
|
|
{ |
158
|
|
|
$uri = "/recordings/live/$recordingName/stop"; |
159
|
|
|
try { |
160
|
|
|
$this->client->getEndpoint()->post($uri, array()); |
161
|
|
|
} catch (Pest_NotFound $e) { // Playback not found |
162
|
|
|
throw new NotFoundException($e); |
163
|
|
|
} |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* Pause a live recording. Pausing a recording suspends silence detection, which will be restarted |
168
|
|
|
* when the recording is unpaused. Paused time is not included in the accounting for |
169
|
|
|
* maxDurationSeconds. |
170
|
|
|
* |
171
|
|
|
* @param string $recordingName The name of the recording |
172
|
|
|
* @throws ConflictException |
173
|
|
|
* @throws NotFoundException |
174
|
|
|
*/ |
175
|
|
View Code Duplication |
public function pauseLiveRecording($recordingName) |
|
|
|
|
176
|
|
|
{ |
177
|
|
|
$uri = "/recordings/live/$recordingName/pause"; |
178
|
|
|
try { |
179
|
|
|
$this->client->getEndpoint()->post($uri, array()); |
180
|
|
|
} catch (Pest_NotFound $e) { |
181
|
|
|
throw new NotFoundException($e); |
182
|
|
|
} catch (Pest_Conflict $e) { |
183
|
|
|
throw new ConflictException($e); |
184
|
|
|
} |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* Unause a live recording. |
189
|
|
|
* |
190
|
|
|
* @param string $recordingName The name of the recording |
191
|
|
|
* @throws ConflictException |
192
|
|
|
* @throws NotFoundException |
193
|
|
|
*/ |
194
|
|
View Code Duplication |
public function unpauseLiveRecording($recordingName) |
|
|
|
|
195
|
|
|
{ |
196
|
|
|
$uri = "/recordings/live/$recordingName/pause"; |
197
|
|
|
try { |
198
|
|
|
$this->client->getEndpoint()->delete($uri); |
199
|
|
|
} catch (Pest_NotFound $e) { |
200
|
|
|
throw new NotFoundException($e); |
201
|
|
|
} catch (Pest_Conflict $e) { |
202
|
|
|
throw new ConflictException($e); |
203
|
|
|
} |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* Mute a live recording. Muting a recording suspends silence detection, which will be restarted when the recording is unmuted. |
208
|
|
|
* |
209
|
|
|
* @param string $recordingName The name of the recording |
210
|
|
|
* @throws ConflictException |
211
|
|
|
* @throws NotFoundException |
212
|
|
|
*/ |
213
|
|
View Code Duplication |
public function muteLiveRecording($recordingName) |
|
|
|
|
214
|
|
|
{ |
215
|
|
|
$uri = "/recordings/live/$recordingName/mute"; |
216
|
|
|
try { |
217
|
|
|
$this->client->getEndpoint()->post($uri, array()); |
218
|
|
|
} catch (Pest_NotFound $e) { |
219
|
|
|
throw new NotFoundException($e); |
220
|
|
|
} catch (Pest_Conflict $e) { |
221
|
|
|
throw new ConflictException($e); |
222
|
|
|
} |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* Unmute a live recording. |
227
|
|
|
* |
228
|
|
|
* @param string $recordingName The name of the recording |
229
|
|
|
* @throws ConflictException |
230
|
|
|
* @throws NotFoundException |
231
|
|
|
*/ |
232
|
|
View Code Duplication |
public function unmuteLiveRecording($recordingName) |
|
|
|
|
233
|
|
|
{ |
234
|
|
|
$uri = "/recordings/live/$recordingName/mute"; |
235
|
|
|
try { |
236
|
|
|
$this->client->getEndpoint()->delete($uri); |
237
|
|
|
} catch (Pest_NotFound $e) { |
238
|
|
|
throw new NotFoundException($e); |
239
|
|
|
} catch (Pest_Conflict $e) { |
240
|
|
|
throw new ConflictException($e); |
241
|
|
|
} |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
} |
245
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.