|
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 GuzzleHttp\Exception\RequestException; |
|
22
|
|
|
use phparia\Client\AriClientAware; |
|
23
|
|
|
use phparia\Exception\ConflictException; |
|
24
|
|
|
use phparia\Exception\InvalidParameterException; |
|
25
|
|
|
use phparia\Exception\NotFoundException; |
|
26
|
|
|
use phparia\Resources\Playback; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Playbacks API |
|
30
|
|
|
* |
|
31
|
|
|
* @author Brian Smith <[email protected]> |
|
32
|
|
|
*/ |
|
33
|
|
|
class Playbacks extends AriClientAware |
|
34
|
|
|
{ |
|
35
|
|
|
const OPERATION_PAUSE = 'pause'; |
|
36
|
|
|
const OPERATION_UNPAUSE = 'unpause'; |
|
37
|
|
|
const OPERATION_REVERSE = 'reverse'; |
|
38
|
|
|
const OPERATION_FORWARD = 'forward'; |
|
39
|
|
|
const OPERATION_RESTART = 'restart'; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Get a playback's details. |
|
43
|
|
|
* |
|
44
|
|
|
* @param string $playbackId Playback's id |
|
45
|
|
|
* @return Playback |
|
46
|
|
|
* @throws NotFoundException |
|
47
|
|
|
*/ |
|
48
|
|
View Code Duplication |
public function getPlayback($playbackId) |
|
49
|
|
|
{ |
|
50
|
|
|
$uri = "playbacks/$playbackId"; |
|
51
|
|
|
try { |
|
52
|
|
|
$response = $this->client->getEndpoint()->get($uri); |
|
53
|
|
|
} catch (RequestException $e) { |
|
54
|
|
|
$this->processRequestException($e); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
return new Playback($this->client, \GuzzleHttp\json_decode($response->getBody())); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Stop a playback. |
|
62
|
|
|
* |
|
63
|
|
|
* @param string $playbackId Playback's id |
|
64
|
|
|
* @throws NotFoundException |
|
65
|
|
|
*/ |
|
66
|
|
|
public function stopPlayback($playbackId) |
|
67
|
|
|
{ |
|
68
|
|
|
$uri = "playbacks/$playbackId"; |
|
69
|
|
|
try { |
|
70
|
|
|
$this->client->getEndpoint()->delete($uri); |
|
71
|
|
|
} catch (RequestException $e) { |
|
72
|
|
|
$this->processRequestException($e); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Control a playback. |
|
78
|
|
|
* |
|
79
|
|
|
* @param string $playbackId Playback's id |
|
80
|
|
|
* @param string $operation (required) Operation to perform on the playback. Allowed values: restart, pause, unpause, reverse, forward. |
|
81
|
|
|
* @throws ConflictException |
|
82
|
|
|
* @throws InvalidParameterException |
|
83
|
|
|
* @throws NotFoundException |
|
84
|
|
|
*/ |
|
85
|
|
|
public function controlPlayback($playbackId, $operation) |
|
86
|
|
|
{ |
|
87
|
|
|
$uri = "playbacks/$playbackId/control"; |
|
88
|
|
|
try { |
|
89
|
|
|
$this->client->getEndpoint()->post($uri, [ |
|
90
|
|
|
'form_params' => [ |
|
91
|
|
|
'operation' => $operation, |
|
92
|
|
|
] |
|
93
|
|
|
]); |
|
94
|
|
|
} catch (RequestException $e) { |
|
95
|
|
|
$this->processRequestException($e); |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|