|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* OpenFireRestAPI is based entirely on official documentation of the REST API |
|
4
|
|
|
* Plugin and you can extend it by following the directives of the documentation |
|
5
|
|
|
* |
|
6
|
|
|
* For the full copyright and license information, please read the LICENSE |
|
7
|
|
|
* file that was distributed with this source code. For the full list of |
|
8
|
|
|
* contributors, visit https://github.com/gnello/PHPOpenFireRestAPI/contributors |
|
9
|
|
|
* |
|
10
|
|
|
* @author Luca Agnello <[email protected]> |
|
11
|
|
|
* @link https://www.igniterealtime.org/projects/openfire/plugins/restapi/readme.html |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Gnello\OpenFireRestAPI\Endpoints; |
|
15
|
|
|
|
|
16
|
|
|
use \Gnello\OpenFireRestAPI\Dispatcher\Method; |
|
17
|
|
|
use \Gnello\OpenFireRestAPI\Dispatcher\Dispatcher; |
|
18
|
|
|
use \Gnello\OpenFireRestAPI\Payloads; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Chat room related REST Endpoint |
|
22
|
|
|
* Class ChatRoomEndpoint |
|
23
|
|
|
* @package Gnello\OpenFireRestAPI\Endpoints |
|
24
|
|
|
* @link http://www.igniterealtime.org/projects/openfire/plugins/restapi/readme.html#chat-room-related-rest-endpoints |
|
25
|
|
|
*/ |
|
26
|
|
|
class ChatRoomEndpoint extends Dispatcher |
|
27
|
|
|
{ |
|
28
|
|
|
public static $endpoint = '/chatrooms'; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Endpoints to get all chat rooms |
|
32
|
|
|
* @return array with Chatrooms |
|
33
|
|
|
* @link http://www.igniterealtime.org/projects/openfire/plugins/restapi/readme.html#retrieve-all-chat-rooms |
|
34
|
|
|
*/ |
|
35
|
|
|
public static function retrieveAllChatRooms() |
|
36
|
|
|
{ |
|
37
|
|
|
return self::sendRequest(Method::GET, self::$endpoint); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Endpoints to get information over specific chat room |
|
42
|
|
|
* @param $roomName |
|
43
|
|
|
* @return array with Chatrooms |
|
44
|
|
|
* @link http://www.igniterealtime.org/projects/openfire/plugins/restapi/readme.html#retrieve-a-chat-room |
|
45
|
|
|
*/ |
|
46
|
|
|
public static function retrieveChatRoom($roomName) |
|
47
|
|
|
{ |
|
48
|
|
|
$endpoint = self::$endpoint . '/' . $roomName; |
|
49
|
|
|
return self::sendRequest(Method::GET, $endpoint); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Endpoints to get all participants with a role of specified room. |
|
54
|
|
|
* @param $roomName |
|
55
|
|
|
* @return array with Participants |
|
56
|
|
|
* @link http://www.igniterealtime.org/projects/openfire/plugins/restapi/readme.html#retrieve-chat-room-participants |
|
57
|
|
|
*/ |
|
58
|
|
|
public static function retrieveChatRoomParticipants($roomName) |
|
59
|
|
|
{ |
|
60
|
|
|
$endpoint = self::$endpoint . '/' . $roomName . '/participants'; |
|
61
|
|
|
return self::sendRequest(Method::GET, $endpoint); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Endpoints to get all occupants (all roles/affiliations) of a specified room. |
|
66
|
|
|
* @param $roomName |
|
67
|
|
|
* @return array with Occupants |
|
68
|
|
|
* @link http://www.igniterealtime.org/projects/openfire/plugins/restapi/readme.html#retrieve-chat-room-occupants |
|
69
|
|
|
*/ |
|
70
|
|
|
public static function retrieveChatRoomOccupants($roomName) |
|
71
|
|
|
{ |
|
72
|
|
|
$endpoint = self::$endpoint . '/' . $roomName . '/occupants'; |
|
73
|
|
|
return self::sendRequest(Method::GET, $endpoint); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Endpoints to create a new chat room. |
|
78
|
|
|
* @param Payloads\ChatRoomPayload $payload |
|
79
|
|
|
* @return array with HTTP status 201 (Created) |
|
80
|
|
|
*/ |
|
81
|
|
|
public static function createChatRoom(Payloads\ChatRoomPayload $payload) |
|
82
|
|
|
{ |
|
83
|
|
|
return self::sendRequest(Method::POST, self::$endpoint, $payload); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Endpoints to delete a chat room. |
|
88
|
|
|
* @param $roomName |
|
89
|
|
|
* @return array with HTTP status 200 (OK) |
|
90
|
|
|
* @link http://www.igniterealtime.org/projects/openfire/plugins/restapi/readme.html#delete-a-chat-room |
|
91
|
|
|
*/ |
|
92
|
|
|
public static function deleteChatRoom($roomName) |
|
93
|
|
|
{ |
|
94
|
|
|
$endpoint = self::$endpoint . '/' . $roomName; |
|
95
|
|
|
return self::sendRequest(Method::DELETE, $endpoint); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* TODO: not working.... |
|
100
|
|
|
* Endpoints to update a chat room. |
|
101
|
|
|
* @param $roomName |
|
102
|
|
|
* @param Payloads\ChatRoomPayload $payload |
|
103
|
|
|
* @return array with HTTP status 200 (OK) |
|
104
|
|
|
* @link http://www.igniterealtime.org/projects/openfire/plugins/restapi/readme.html#update-a-chat-room |
|
105
|
|
|
*/ |
|
106
|
|
|
public static function updateChatRoom($roomName, Payloads\ChatRoomPayload $payload) |
|
107
|
|
|
{ |
|
108
|
|
|
$endpoint = self::$endpoint . '/' . $roomName; |
|
109
|
|
|
return self::sendRequest(Method::PUT, $endpoint, $payload); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* TODO: add check roles |
|
114
|
|
|
* Endpoint to add a new user with role to a room. |
|
115
|
|
|
* @param $roomName |
|
116
|
|
|
* @param $roles (owners, admins, members, outcasts) |
|
117
|
|
|
* @param $name |
|
118
|
|
|
* @return array with HTTP status 201 (Created) |
|
119
|
|
|
* @link http://www.igniterealtime.org/projects/openfire/plugins/restapi/readme.html#add-user-with-role-to-chat-room |
|
120
|
|
|
*/ |
|
121
|
|
|
public static function addUserWithRoleToChatRoom($roomName, $roles, $name) |
|
122
|
|
|
{ |
|
123
|
|
|
$endpoint = self::$endpoint . '/' . $roomName . '/' . $roles . '/' . $name; |
|
124
|
|
|
return self::sendRequest(Method::POST, $endpoint); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* TODO: add check roles |
|
129
|
|
|
* Endpoint to add a new group with role to a room. |
|
130
|
|
|
* @param $roomName |
|
131
|
|
|
* @param $roles (owners, admins, members, outcasts) |
|
132
|
|
|
* @param $name |
|
133
|
|
|
* @return array with HTTP status 201 (Created) |
|
134
|
|
|
* @link http://www.igniterealtime.org/projects/openfire/plugins/restapi/readme.html#add-group-with-role-to-chat-room |
|
135
|
|
|
*/ |
|
136
|
|
|
public static function addGroupWithRoleToChatRoom($roomName, $roles, $name) |
|
137
|
|
|
{ |
|
138
|
|
|
$endpoint = self::$endpoint . '/' . $roomName . '/' . $roles . '/group/' . $name; |
|
139
|
|
|
return self::sendRequest(Method::POST, $endpoint); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* Endpoint to remove a room user role. |
|
144
|
|
|
* @param $roomName |
|
145
|
|
|
* @param $roles (owners, admins, members, outcasts) |
|
146
|
|
|
* @param $name |
|
147
|
|
|
* @return array with HTTP status 200 (OK) |
|
148
|
|
|
* @link http://www.igniterealtime.org/projects/openfire/plugins/restapi/readme.html#delete-a-user-from-a-chat-room |
|
149
|
|
|
*/ |
|
150
|
|
|
public static function deleteUserFromChatRoom($roomName, $roles, $name) |
|
151
|
|
|
{ |
|
152
|
|
|
$endpoint = self::$endpoint . '/' . $roomName . '/' . $roles . '/' . $name; |
|
153
|
|
|
return self::sendRequest(Method::DELETE, $endpoint); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* Endpoint to remove a room group role. |
|
158
|
|
|
* @param $roomName |
|
159
|
|
|
* @param $roles (owners, admins, members, outcasts) |
|
160
|
|
|
* @param $name |
|
161
|
|
|
* @return array with HTTP status 200 (OK) |
|
162
|
|
|
* @link http://www.igniterealtime.org/projects/openfire/plugins/restapi/readme.html#delete-a-group-from-a-chat-room |
|
163
|
|
|
*/ |
|
164
|
|
|
public static function deleteGroupFromChatRoom($roomName, $roles, $name) |
|
165
|
|
|
{ |
|
166
|
|
|
$endpoint = self::$endpoint . '/' . $roomName . '/' . $roles . '/group/' . $name; |
|
167
|
|
|
return self::sendRequest(Method::DELETE, $endpoint); |
|
168
|
|
|
} |
|
169
|
|
|
} |