|
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_BadRequest; |
|
22
|
|
|
use phparia\Client\AriClientAware; |
|
23
|
|
|
use phparia\Resources\AsteriskInfo; |
|
24
|
|
|
use phparia\Resources\Variable; |
|
25
|
|
|
use phparia\Exception\InvalidParameterException; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Asterisk API |
|
29
|
|
|
* |
|
30
|
|
|
* @author Brian Smith <[email protected]> |
|
31
|
|
|
*/ |
|
32
|
|
|
class Asterisk extends AriClientAware |
|
33
|
|
|
{ |
|
34
|
|
|
const INFO_BUILD = 'build'; |
|
35
|
|
|
const INFO_SYSTEM = 'system'; |
|
36
|
|
|
const INFO_CONFIG = 'config'; |
|
37
|
|
|
const INFO_STATUS = 'status'; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Gets Asterisk system information. |
|
41
|
|
|
* |
|
42
|
|
|
* @param string $only Filter information returned. Allows comma separated values. Allowed values: build, system, config, status. |
|
43
|
|
|
* @return AsteriskInfo |
|
44
|
|
|
*/ |
|
45
|
2 |
|
public function getInfo($only = null) |
|
46
|
|
|
{ |
|
47
|
2 |
|
if (empty($only)) { |
|
48
|
1 |
|
$uri = '/asterisk/info'; |
|
49
|
1 |
|
} else { |
|
50
|
1 |
|
$uri = "/asterisk/info?only=$only"; |
|
51
|
|
|
} |
|
52
|
2 |
|
$result = $this->client->getEndpoint()->get($uri); |
|
53
|
|
|
|
|
54
|
|
|
return new AsteriskInfo($result); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Get the value of a global variable. |
|
59
|
|
|
* |
|
60
|
|
|
* @param string $variable (required) The variable to get |
|
61
|
|
|
* @return Variable |
|
62
|
|
|
* @throws InvalidParameterException |
|
63
|
|
|
*/ |
|
64
|
1 |
|
public function getVariable($variable) |
|
65
|
|
|
{ |
|
66
|
1 |
|
$uri = "/asterisk/variable?variable=$variable"; |
|
67
|
|
|
|
|
68
|
|
|
try { |
|
69
|
1 |
|
$response = $this->client->getEndpoint()->get($uri); |
|
70
|
1 |
|
} catch (Pest_BadRequest $e) { |
|
71
|
|
|
throw new InvalidParameterException($e); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
return new Variable($response); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Set the value of a global variable. |
|
79
|
|
|
* |
|
80
|
|
|
* @param string $variable (required) The variable to set |
|
81
|
|
|
* @param string $value The value to set the variable to |
|
82
|
|
|
* @throws InvalidParameterException |
|
83
|
|
|
*/ |
|
84
|
2 |
|
public function setVariable($variable, $value = null) |
|
85
|
|
|
{ |
|
86
|
2 |
|
$uri = '/asterisk/variable'; |
|
87
|
|
|
|
|
88
|
|
|
try { |
|
89
|
2 |
|
$this->client->getEndpoint()->post($uri, array( |
|
90
|
2 |
|
'variable' => $variable, |
|
91
|
|
|
'value' => $value |
|
92
|
2 |
|
)); |
|
93
|
2 |
|
} catch (Pest_BadRequest $e) { |
|
94
|
|
|
throw new InvalidParameterException($e); |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
} |
|
99
|
|
|
|