@@ -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) |
@@ -27,8 +27,8 @@ |
||
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 |
@@ -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 | /** |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | public function createGroup($name, $description = false) |
261 | 261 | { |
262 | 262 | $endpoint = '/groups/'; |
263 | - return $this->doRequest('POST', $endpoint, compact('name','description')); |
|
263 | + return $this->doRequest('POST', $endpoint, compact('name', 'description')); |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | /** |
@@ -282,10 +282,10 @@ discard block |
||
282 | 282 | * @param string $description Some description of the group |
283 | 283 | * |
284 | 284 | */ |
285 | - public function updateGroup($name, $description) |
|
285 | + public function updateGroup($name, $description) |
|
286 | 286 | { |
287 | 287 | $endpoint = '/groups/'.$name; |
288 | - return $this->doRequest('PUT', $endpoint, compact('name','description')); |
|
288 | + return $this->doRequest('PUT', $endpoint, compact('name', 'description')); |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | /** |
@@ -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); |
@@ -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,15 +20,15 @@ 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 | - public function geti() |
|
29 | - { |
|
30 | - return $this->host. ' '. $this->secret; |
|
31 | - } |
|
28 | + public function geti() |
|
29 | + { |
|
30 | + return $this->host. ' '. $this->secret; |
|
31 | + } |
|
32 | 32 | |
33 | 33 | |
34 | 34 | |
@@ -40,29 +40,29 @@ discard block |
||
40 | 40 | * @param array $params Parameters |
41 | 41 | * @return array|false Array with data or error, or False when something went fully wrong |
42 | 42 | */ |
43 | - protected function doRequest($type, $endpoint, $params=[]) |
|
43 | + protected function doRequest($type, $endpoint, $params=[]) |
|
44 | 44 | { |
45 | - $base = ($this->useSSL) ? "https" : "http"; |
|
46 | - $url = $base . "://" . $this->host . ":" .$this->port.$this->plugin.$endpoint; |
|
45 | + $base = ($this->useSSL) ? "https" : "http"; |
|
46 | + $url = $base . "://" . $this->host . ":" .$this->port.$this->plugin.$endpoint; |
|
47 | 47 | |
48 | - if ($this->useBasicAuth) |
|
48 | + if ($this->useBasicAuth) |
|
49 | 49 | $auth = 'Basic ' . base64_encode($this->basicUser . ':' . $this->basicPwd); |
50 | 50 | else |
51 | 51 | $auth = $this->secret; |
52 | 52 | |
53 | - $headers = array( |
|
54 | - 'Accept' => 'application/json', |
|
55 | - 'Authorization' => $auth |
|
56 | - ); |
|
53 | + $headers = array( |
|
54 | + 'Accept' => 'application/json', |
|
55 | + 'Authorization' => $auth |
|
56 | + ); |
|
57 | 57 | |
58 | 58 | $body = json_encode($params); |
59 | 59 | // $headers += ['Content-Type'=>'application/json']; |
60 | 60 | |
61 | 61 | |
62 | 62 | try { |
63 | - $result = $this->client->request($type, $url, compact('headers','body')); |
|
63 | + $result = $this->client->request($type, $url, compact('headers','body')); |
|
64 | 64 | } catch (Exception $e) { |
65 | - $result = $e->message; |
|
65 | + $result = $e->message; |
|
66 | 66 | } |
67 | 67 | |
68 | 68 |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | |
28 | 28 | public function geti() |
29 | 29 | { |
30 | - return $this->host. ' '. $this->secret; |
|
30 | + return $this->host.' '.$this->secret; |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | |
@@ -40,13 +40,13 @@ discard block |
||
40 | 40 | * @param array $params Parameters |
41 | 41 | * @return array|false Array with data or error, or False when something went fully wrong |
42 | 42 | */ |
43 | - protected function doRequest($type, $endpoint, $params=[]) |
|
43 | + protected function doRequest($type, $endpoint, $params = [ ]) |
|
44 | 44 | { |
45 | 45 | $base = ($this->useSSL) ? "https" : "http"; |
46 | - $url = $base . "://" . $this->host . ":" .$this->port.$this->plugin.$endpoint; |
|
46 | + $url = $base."://".$this->host.":".$this->port.$this->plugin.$endpoint; |
|
47 | 47 | |
48 | 48 | if ($this->useBasicAuth) |
49 | - $auth = 'Basic ' . base64_encode($this->basicUser . ':' . $this->basicPwd); |
|
49 | + $auth = 'Basic '.base64_encode($this->basicUser.':'.$this->basicPwd); |
|
50 | 50 | else |
51 | 51 | $auth = $this->secret; |
52 | 52 | |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | |
61 | 61 | |
62 | 62 | try { |
63 | - $result = $this->client->request($type, $url, compact('headers','body')); |
|
63 | + $result = $this->client->request($type, $url, compact('headers', 'body')); |
|
64 | 64 | } catch (Exception $e) { |
65 | 65 | $result = $e->message; |
66 | 66 | } |
@@ -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', |