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\Exception\UnprocessableEntityException; |
27
|
|
|
use phparia\Resources\Application; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Applications API |
31
|
|
|
* |
32
|
|
|
* @author Brian Smith <[email protected]> |
33
|
|
|
*/ |
34
|
|
|
class Applications extends AriClientAware |
35
|
|
|
{ |
36
|
|
|
/** |
37
|
|
|
* List all getApplications. |
38
|
|
|
* |
39
|
|
|
* @return Application[] |
40
|
|
|
*/ |
41
|
|
View Code Duplication |
public function getApplications() |
42
|
|
|
{ |
43
|
|
|
$uri = 'applications'; |
44
|
|
|
$response = $this->client->getEndpoint()->get($uri); |
45
|
|
|
|
46
|
|
|
$applications = []; |
47
|
|
|
foreach (\GuzzleHttp\json_decode($response->getBody()) as $application) { |
48
|
|
|
$applications[] = new Application($this->client, $application); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
return $applications; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Get details of an application. |
56
|
|
|
* |
57
|
|
|
* @param $applicationName |
58
|
|
|
* @return Application |
59
|
|
|
* @throws NotFoundException |
60
|
|
|
*/ |
61
|
|
View Code Duplication |
public function getApplication($applicationName) |
62
|
|
|
{ |
63
|
|
|
$uri = "applications/$applicationName"; |
64
|
|
|
try { |
65
|
|
|
$response = $this->client->getEndpoint()->get($uri); |
66
|
|
|
} catch (RequestException $e) { |
67
|
|
|
$this->processRequestException($e); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
return new Application($this->client, \GuzzleHttp\json_decode($response->getBody())); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Subscribe an application to a event source. Returns the state of the application after the subscriptions have changed |
75
|
|
|
* |
76
|
|
|
* @param string $applicationName Application's name |
77
|
|
|
* @param string $eventSource (required) URI for event source (channel:{channelId}, bridge:{bridgeId}, endpoint:{tech}[/{resource}], deviceState:{deviceName}. Allows comma separated values. |
78
|
|
|
* @return Application |
79
|
|
|
* @throws InvalidParameterException |
80
|
|
|
* @throws NotFoundException |
81
|
|
|
* @throws UnprocessableEntityException Event source does not exist. |
82
|
|
|
*/ |
83
|
|
|
public function subscribe($applicationName, $eventSource) |
84
|
|
|
{ |
85
|
|
|
$uri = "applications/$applicationName/subscription"; |
86
|
|
|
try { |
87
|
|
|
$response = $this->client->getEndpoint()->post($uri, [ |
88
|
|
|
'form_params' => [ |
89
|
|
|
'eventSource' => $eventSource, |
90
|
|
|
] |
91
|
|
|
]); |
92
|
|
|
} catch (RequestException $e) { |
93
|
|
|
$this->processRequestException($e); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
return new Application($this->client, \GuzzleHttp\json_decode($response->getBody())); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Unsubscribe an application from an event source. Returns the state of the application after the subscriptions have changed |
101
|
|
|
* |
102
|
|
|
* @param string $applicationName Application's name |
103
|
|
|
* @param string $eventSource (required) URI for event source (channel:{channelId}, bridge:{bridgeId}, endpoint:{tech}[/{resource}], deviceState:{deviceName} Allows comma separated values. |
104
|
|
|
* @return Application |
105
|
|
|
* @throws ConflictException |
106
|
|
|
* @throws InvalidParameterException |
107
|
|
|
* @throws NotFoundException |
108
|
|
|
* @throws UnprocessableEntityException |
109
|
|
|
*/ |
110
|
|
View Code Duplication |
public function unsubscribe($applicationName, $eventSource) |
111
|
|
|
{ |
112
|
|
|
$uri = "applications/$applicationName/subscription?eventSource=".\GuzzleHttp\json_encode($eventSource); |
113
|
|
|
try { |
114
|
|
|
$response = $this->client->getEndpoint()->delete($uri); |
115
|
|
|
} catch (RequestException $e) { |
116
|
|
|
$this->processRequestException($e); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
return new Application($this->client, \GuzzleHttp\json_decode($response->getBody())); |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|