@@ -25,7 +25,9 @@ |
||
| 25 | 25 | { |
| 26 | 26 | $query = ''; |
| 27 | 27 | |
| 28 | - if(isset($opts['search'])) $query .= '?search='.$opts['search']; |
|
| 28 | + if(isset($opts['search'])) { |
|
| 29 | + $query .= '?search='.$opts['search']; |
|
| 30 | + } |
|
| 29 | 31 | |
| 30 | 32 | $endpoint = '/users'.$query; |
| 31 | 33 | return $this->doRequest('GET', $endpoint); |
@@ -119,7 +119,6 @@ discard block |
||
| 119 | 119 | * Add user to a group |
| 120 | 120 | * |
| 121 | 121 | * @param string $username Username |
| 122 | - * @param string $groups Groups to add user |
|
| 123 | 122 | * @return json|false Json with data or error, or False when something went fully wrong |
| 124 | 123 | */ |
| 125 | 124 | public function addToGroup($username, $groupName) |
@@ -133,7 +132,6 @@ discard block |
||
| 133 | 132 | * Delete user from a group |
| 134 | 133 | * |
| 135 | 134 | * @param string $username Username |
| 136 | - * @param string $groups Groups to add user |
|
| 137 | 135 | * @return json|false Json with data or error, or False when something went fully wrong |
| 138 | 136 | */ |
| 139 | 137 | public function deleteFromGroup($username, $groupName) |
@@ -277,7 +275,6 @@ discard block |
||
| 277 | 275 | /** |
| 278 | 276 | * Delete a chat room |
| 279 | 277 | * |
| 280 | - * @param string $name Name of the Group to delete |
|
| 281 | 278 | * @return json|false Json with data or error, or False when something went fully wrong |
| 282 | 279 | */ |
| 283 | 280 | public function deleteChatRoom($roomName) |
@@ -288,7 +285,6 @@ discard block |
||
| 288 | 285 | /** |
| 289 | 286 | * Get chat room participants |
| 290 | 287 | * |
| 291 | - * @param string $name Name of the chatroom |
|
| 292 | 288 | * @return json|false Json with data or error, or False when something went fully wrong |
| 293 | 289 | */ |
| 294 | 290 | public function getChatRoomParticipants($roomName) |
@@ -299,7 +295,6 @@ discard block |
||
| 299 | 295 | /** |
| 300 | 296 | * Get chat room occupants |
| 301 | 297 | * |
| 302 | - * @param string $name Name of the chatroom |
|
| 303 | 298 | * @return json|false Json with data or error, or False when something went fully wrong |
| 304 | 299 | */ |
| 305 | 300 | public function getChatRoomOccupants($roomName) |
@@ -356,7 +351,6 @@ discard block |
||
| 356 | 351 | /** |
| 357 | 352 | * Retrieve a system property |
| 358 | 353 | * |
| 359 | - * @param string $name Name of property |
|
| 360 | 354 | * @return json|false Json with data or error, or False when something went fully wrong |
| 361 | 355 | */ |
| 362 | 356 | public function getSystemProperty($propertyName) |
@@ -393,7 +387,6 @@ discard block |
||
| 393 | 387 | /** |
| 394 | 388 | * Delete a system property |
| 395 | 389 | * |
| 396 | - * @param array $data new property with value |
|
| 397 | 390 | * @return json|false Json with data or error, or False when something went fully wrong |
| 398 | 391 | */ |
| 399 | 392 | public function deleteSystemProperty($propertyName) |
@@ -514,7 +507,6 @@ discard block |
||
| 514 | 507 | /** |
| 515 | 508 | * Send a broadcast message to all online users |
| 516 | 509 | * |
| 517 | - * @param string $content message to send |
|
| 518 | 510 | * @return json|false Json with data or error, or False when something went fully wrong |
| 519 | 511 | */ |
| 520 | 512 | public function broadcastMessage($message = '') |
@@ -27,8 +27,8 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | if(isset($opts['search'])) $query .= '?search='.$opts['search']; |
| 29 | 29 | |
| 30 | - $endpoint = '/users'.$query; |
|
| 31 | - return $this->doRequest('GET', $endpoint); |
|
| 30 | + $endpoint = '/users'.$query; |
|
| 31 | + return $this->doRequest('GET', $endpoint); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | |
@@ -413,11 +413,11 @@ discard block |
||
| 413 | 413 | } |
| 414 | 414 | |
| 415 | 415 | |
| 416 | - /** |
|
| 417 | - * Get all groups |
|
| 418 | - * |
|
| 419 | - * @return json|false Json with data or error, or False when something went fully wrong |
|
| 420 | - */ |
|
| 416 | + /** |
|
| 417 | + * Get all groups |
|
| 418 | + * |
|
| 419 | + * @return json|false Json with data or error, or False when something went fully wrong |
|
| 420 | + */ |
|
| 421 | 421 | public function getGroups() |
| 422 | 422 | { |
| 423 | 423 | $endpoint = '/groups'; |
@@ -21,11 +21,11 @@ discard block |
||
| 21 | 21 | * |
| 22 | 22 | * @return json|false Json with data or error, or False when something went fully wrong |
| 23 | 23 | */ |
| 24 | - public function getUsers($opts = []) |
|
| 24 | + public function getUsers($opts = [ ]) |
|
| 25 | 25 | { |
| 26 | 26 | $query = ''; |
| 27 | 27 | |
| 28 | - if(isset($opts['search'])) $query .= '?search='.$opts['search']; |
|
| 28 | + if (isset($opts[ 'search' ])) $query .= '?search='.$opts[ 'search' ]; |
|
| 29 | 29 | |
| 30 | 30 | $endpoint = '/users'.$query; |
| 31 | 31 | return $this->doRequest('GET', $endpoint); |
@@ -54,10 +54,10 @@ discard block |
||
| 54 | 54 | * @param string[]|false $groups Groups (Optional) |
| 55 | 55 | * @return json|false Json with data or error, or False when something went fully wrong |
| 56 | 56 | */ |
| 57 | - public function addUser($username, $password, $name=false, $email=false, $groups=false) |
|
| 57 | + public function addUser($username, $password, $name = false, $email = false, $groups = false) |
|
| 58 | 58 | { |
| 59 | 59 | $endpoint = '/users'; |
| 60 | - return $this->doRequest('POST', $endpoint, compact('username', 'password','name','email', 'groups')); |
|
| 60 | + return $this->doRequest('POST', $endpoint, compact('username', 'password', 'name', 'email', 'groups')); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | |
@@ -83,10 +83,10 @@ discard block |
||
| 83 | 83 | * @param string[]|false $groups Groups (Optional) |
| 84 | 84 | * @return json|false Json with data or error, or False when something went fully wrong |
| 85 | 85 | */ |
| 86 | - public function updateUser($username, $password, $name=false, $email=false, $groups=false) |
|
| 86 | + public function updateUser($username, $password, $name = false, $email = false, $groups = false) |
|
| 87 | 87 | { |
| 88 | 88 | $endpoint = '/users/'.$username; |
| 89 | - return $this->doRequest('PUT', $endpoint, compact('username', 'password','name','email', 'groups')); |
|
| 89 | + return $this->doRequest('PUT', $endpoint, compact('username', 'password', 'name', 'email', 'groups')); |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | public function addToGroup($username, $groupName) |
| 126 | 126 | { |
| 127 | 127 | $endpoint = '/users/'.$username.'/groups/'.$groupName; |
| 128 | - return $this->doRequest('POST', $endpoint ); |
|
| 128 | + return $this->doRequest('POST', $endpoint); |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | public function deleteFromGroup($username, $groupName) |
| 140 | 140 | { |
| 141 | 141 | $endpoint = '/users/'.$username.'/groups/'.$groupName; |
| 142 | - return $this->doRequest('DELETE', $endpoint ); |
|
| 142 | + return $this->doRequest('DELETE', $endpoint); |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | public function userRosters($username) |
| 179 | 179 | { |
| 180 | 180 | $endpoint = '/users/'.$username.'/roster'; |
| 181 | - return $this->doRequest('GET', $endpoint, compact('jid','name','subscriptionType')); |
|
| 181 | + return $this->doRequest('GET', $endpoint, compact('jid', 'name', 'subscriptionType')); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | |
@@ -191,10 +191,10 @@ discard block |
||
| 191 | 191 | * @param int|false $subscriptionType Subscription (Optional) |
| 192 | 192 | * @return json|false Json with data or error, or False when something went fully wrong |
| 193 | 193 | */ |
| 194 | - public function addToRoster($username, $jid, $name=false, $subscriptionType=false) |
|
| 194 | + public function addToRoster($username, $jid, $name = false, $subscriptionType = false) |
|
| 195 | 195 | { |
| 196 | 196 | $endpoint = '/users/'.$username.'/roster'; |
| 197 | - return $this->doRequest('POST', $endpoint, compact('jid','name','subscriptionType')); |
|
| 197 | + return $this->doRequest('POST', $endpoint, compact('jid', 'name', 'subscriptionType')); |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | |
@@ -220,10 +220,10 @@ discard block |
||
| 220 | 220 | * @param int|false $subscriptionType Subscription (Optional) |
| 221 | 221 | * @return json|false Json with data or error, or False when something went fully wrong |
| 222 | 222 | */ |
| 223 | - public function updateRoster($username, $jid, $nickname=false, $subscriptionType=false) |
|
| 223 | + public function updateRoster($username, $jid, $nickname = false, $subscriptionType = false) |
|
| 224 | 224 | { |
| 225 | 225 | $endpoint = '/users/'.$username.'/roster/'.$jid; |
| 226 | - return $this->doRequest('PUT', $endpoint, $jid, compact('jid','username','subscriptionType')); |
|
| 226 | + return $this->doRequest('PUT', $endpoint, $jid, compact('jid', 'username', 'subscriptionType')); |
|
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | * @param string $params Params |
| 257 | 257 | * @return json|false Json with data or error, or False when something went fully wrong |
| 258 | 258 | */ |
| 259 | - public function createChatRoom($params = []) |
|
| 259 | + public function createChatRoom($params = [ ]) |
|
| 260 | 260 | { |
| 261 | 261 | return $this->doRequest('POST', '/chatrooms', $params); |
| 262 | 262 | } |
@@ -268,7 +268,7 @@ discard block |
||
| 268 | 268 | * @param string $params Params |
| 269 | 269 | * @return json|false Json with data or error, or False when something went fully wrong |
| 270 | 270 | */ |
| 271 | - public function updateChatRoom($roomName, $params = []) |
|
| 271 | + public function updateChatRoom($roomName, $params = [ ]) |
|
| 272 | 272 | { |
| 273 | 273 | return $this->doRequest('PUT', '/chatrooms/'.$roomName, $params); |
| 274 | 274 | } |
@@ -447,7 +447,7 @@ discard block |
||
| 447 | 447 | public function createGroup($name, $description = false) |
| 448 | 448 | { |
| 449 | 449 | $endpoint = '/groups/'; |
| 450 | - return $this->doRequest('POST', $endpoint, compact('name','description')); |
|
| 450 | + return $this->doRequest('POST', $endpoint, compact('name', 'description')); |
|
| 451 | 451 | } |
| 452 | 452 | |
| 453 | 453 | /** |
@@ -469,10 +469,10 @@ discard block |
||
| 469 | 469 | * @param string $description Some description of the group |
| 470 | 470 | * |
| 471 | 471 | */ |
| 472 | - public function updateGroup($name, $description) |
|
| 472 | + public function updateGroup($name, $description) |
|
| 473 | 473 | { |
| 474 | 474 | $endpoint = '/groups/'.$name; |
| 475 | - return $this->doRequest('PUT', $endpoint, compact('name','description')); |
|
| 475 | + return $this->doRequest('PUT', $endpoint, compact('name', 'description')); |
|
| 476 | 476 | } |
| 477 | 477 | |
| 478 | 478 | |
@@ -519,7 +519,7 @@ discard block |
||
| 519 | 519 | */ |
| 520 | 520 | public function broadcastMessage($message = '') |
| 521 | 521 | { |
| 522 | - $content =['body'=> $message]; |
|
| 522 | + $content = [ 'body'=> $message ]; |
|
| 523 | 523 | $endpoint = '/messages/users'; |
| 524 | 524 | return $this->doRequest('POST', $endpoint, $content); |
| 525 | 525 | } |
@@ -45,10 +45,11 @@ |
||
| 45 | 45 | $base = ($this->useSSL) ? "https" : "http"; |
| 46 | 46 | $url = $base . "://" . $this->host . ":" .$this->port.$this->plugin.$endpoint; |
| 47 | 47 | |
| 48 | - if ($this->useBasicAuth) |
|
| 49 | - $auth = 'Basic ' . base64_encode($this->basicUser . ':' . $this->basicPwd); |
|
| 50 | - else |
|
| 51 | - $auth = $this->secret; |
|
| 48 | + if ($this->useBasicAuth) { |
|
| 49 | + $auth = 'Basic ' . base64_encode($this->basicUser . ':' . $this->basicPwd); |
|
| 50 | + } else { |
|
| 51 | + $auth = $this->secret; |
|
| 52 | + } |
|
| 52 | 53 | |
| 53 | 54 | $headers = array( |
| 54 | 55 | 'Accept' => 'application/json', |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | */ |
| 9 | 9 | class RestClient |
| 10 | 10 | { |
| 11 | - public $host = 'localhost'; |
|
| 11 | + public $host = 'localhost'; |
|
| 12 | 12 | public $port = '9090'; |
| 13 | 13 | public $plugin = '/plugins/restapi/v1'; |
| 14 | 14 | public $secret = 'SuperSecret'; |
@@ -20,10 +20,10 @@ discard block |
||
| 20 | 20 | public $basicUser = 'admin'; |
| 21 | 21 | public $basicPwd = '1234'; |
| 22 | 22 | |
| 23 | - function __construct() |
|
| 24 | - { |
|
| 25 | - $this->client = new Client(); |
|
| 26 | - } |
|
| 23 | + function __construct() |
|
| 24 | + { |
|
| 25 | + $this->client = new Client(); |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | 29 | * Make the request and analyze the result |
@@ -33,28 +33,28 @@ discard block |
||
| 33 | 33 | * @param array $params Parameters |
| 34 | 34 | * @return array|false Array with data or error, or False when something went fully wrong |
| 35 | 35 | */ |
| 36 | - protected function doRequest($type, $endpoint, $params=[]) |
|
| 36 | + protected function doRequest($type, $endpoint, $params=[]) |
|
| 37 | 37 | { |
| 38 | - $base = ($this->useSSL) ? "https" : "http"; |
|
| 39 | - $url = $base . "://" . $this->host . ":" .$this->port.$this->plugin.$endpoint; |
|
| 38 | + $base = ($this->useSSL) ? "https" : "http"; |
|
| 39 | + $url = $base . "://" . $this->host . ":" .$this->port.$this->plugin.$endpoint; |
|
| 40 | 40 | |
| 41 | - if ($this->useBasicAuth) |
|
| 41 | + if ($this->useBasicAuth) |
|
| 42 | 42 | $auth = 'Basic ' . base64_encode($this->basicUser . ':' . $this->basicPwd); |
| 43 | 43 | else |
| 44 | 44 | $auth = $this->secret; |
| 45 | 45 | |
| 46 | - $headers = array( |
|
| 47 | - 'Accept' => 'application/json', |
|
| 48 | - 'Authorization' => $auth, |
|
| 46 | + $headers = array( |
|
| 47 | + 'Accept' => 'application/json', |
|
| 48 | + 'Authorization' => $auth, |
|
| 49 | 49 | 'Content-Type'=>'application/json' |
| 50 | - ); |
|
| 50 | + ); |
|
| 51 | 51 | |
| 52 | 52 | $body = json_encode($params); |
| 53 | 53 | |
| 54 | 54 | try { |
| 55 | - $result = $this->client->request($type, $url, compact('headers','body')); |
|
| 55 | + $result = $this->client->request($type, $url, compact('headers','body')); |
|
| 56 | 56 | } catch (\Exception $e) { |
| 57 | - return ['status'=>false, 'data'=>['message'=>$e->getMessage()]]; |
|
| 57 | + return ['status'=>false, 'data'=>['message'=>$e->getMessage()]]; |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | |
@@ -33,13 +33,13 @@ discard block |
||
| 33 | 33 | * @param array $params Parameters |
| 34 | 34 | * @return array|false Array with data or error, or False when something went fully wrong |
| 35 | 35 | */ |
| 36 | - protected function doRequest($type, $endpoint, $params=[]) |
|
| 36 | + protected function doRequest($type, $endpoint, $params = [ ]) |
|
| 37 | 37 | { |
| 38 | 38 | $base = ($this->useSSL) ? "https" : "http"; |
| 39 | - $url = $base . "://" . $this->host . ":" .$this->port.$this->plugin.$endpoint; |
|
| 39 | + $url = $base."://".$this->host.":".$this->port.$this->plugin.$endpoint; |
|
| 40 | 40 | |
| 41 | 41 | if ($this->useBasicAuth) |
| 42 | - $auth = 'Basic ' . base64_encode($this->basicUser . ':' . $this->basicPwd); |
|
| 42 | + $auth = 'Basic '.base64_encode($this->basicUser.':'.$this->basicPwd); |
|
| 43 | 43 | else |
| 44 | 44 | $auth = $this->secret; |
| 45 | 45 | |
@@ -52,9 +52,9 @@ discard block |
||
| 52 | 52 | $body = json_encode($params); |
| 53 | 53 | |
| 54 | 54 | try { |
| 55 | - $result = $this->client->request($type, $url, compact('headers','body')); |
|
| 55 | + $result = $this->client->request($type, $url, compact('headers', 'body')); |
|
| 56 | 56 | } catch (\Exception $e) { |
| 57 | - return ['status'=>false, 'data'=>['message'=>$e->getMessage()]]; |
|
| 57 | + return [ 'status'=>false, 'data'=>[ 'message'=>$e->getMessage() ] ]; |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | |