|
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
|
|
|
* Group related REST Endpoint |
|
22
|
|
|
* Class GroupEndpoint |
|
23
|
|
|
* @package Gnello\OpenFireRestAPI\Endpoints |
|
24
|
|
|
* @link https://www.igniterealtime.org/projects/openfire/plugins/restapi/readme.html#group-related-rest-endpoints |
|
25
|
|
|
*/ |
|
26
|
|
|
class GroupEndpoint extends Dispatcher |
|
27
|
|
|
{ |
|
28
|
|
|
public static $endpoint = '/groups'; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Get all groups |
|
32
|
|
|
* @return array with Groups |
|
33
|
|
|
* @link http://www.igniterealtime.org/projects/openfire/plugins/restapi/readme.html#retrieve-all-groups |
|
34
|
|
|
*/ |
|
35
|
|
|
public static function retrieveAllGroups() |
|
36
|
|
|
{ |
|
37
|
|
|
return self::sendRequest(Method::GET, self::$endpoint); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Get information over specific group |
|
42
|
|
|
* @param string $groupName |
|
43
|
|
|
* @return array with Group |
|
44
|
|
|
* @link http://www.igniterealtime.org/projects/openfire/plugins/restapi/readme.html#retrieve-a-group |
|
45
|
|
|
*/ |
|
46
|
|
|
public static function retrieveGroup($groupName) |
|
47
|
|
|
{ |
|
48
|
|
|
$endpoint = self::$endpoint . '/' . $groupName; |
|
49
|
|
|
return self::sendRequest(Method::GET, $endpoint); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Create a new group |
|
54
|
|
|
* @param $name |
|
55
|
|
|
* @param $description |
|
56
|
|
|
* @return array with HTTP status 201 (Created) |
|
57
|
|
|
* @link http://www.igniterealtime.org/projects/openfire/plugins/restapi/readme.html#create-a-group |
|
58
|
|
|
*/ |
|
59
|
|
|
public static function createGroup($name, $description) |
|
60
|
|
|
{ |
|
61
|
|
|
$payload = new Payloads\GroupPayload(compact('name', 'description')); |
|
62
|
|
|
return self::sendRequest(Method::POST, self::$endpoint, $payload); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Delete a group |
|
67
|
|
|
* @param $groupName |
|
68
|
|
|
* @return array with HTTP status 200 (OK) |
|
69
|
|
|
* @link http://www.igniterealtime.org/projects/openfire/plugins/restapi/readme.html#delete-a-group |
|
70
|
|
|
*/ |
|
71
|
|
|
public static function deleteGroup($groupName) |
|
72
|
|
|
{ |
|
73
|
|
|
$endpoint = self::$endpoint . '/' . $groupName; |
|
74
|
|
|
return self::sendRequest(Method::DELETE, $endpoint); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Update/overwrite a group |
|
79
|
|
|
* @param $groupName |
|
80
|
|
|
* @param $name |
|
81
|
|
|
* @param $description |
|
82
|
|
|
* @return array with HTTP status 200 (OK) |
|
83
|
|
|
* @link http://www.igniterealtime.org/projects/openfire/plugins/restapi/readme.html#update-a-group |
|
84
|
|
|
*/ |
|
85
|
|
|
public static function updateGroup($groupName, $name, $description) |
|
86
|
|
|
{ |
|
87
|
|
|
$payload = new Payloads\GroupPayload(compact('name', 'description')); |
|
88
|
|
|
$endpoint = self::$endpoint . '/' . $groupName; |
|
89
|
|
|
return self::sendRequest(Method::PUT, $endpoint, $payload); |
|
90
|
|
|
} |
|
91
|
|
|
} |