| @@ 27-63 (lines=37) @@ | ||
| 24 | * @param boolean $test |
|
| 25 | * @return Auth |
|
| 26 | */ |
|
| 27 | public function revoke($token = NULL, $test = FALSE) { |
|
| 28 | ||
| 29 | // Check if the type of the variables is valid. |
|
| 30 | if (($token != NULL) && !is_string($token)) { |
|
| 31 | throw new InvalidArgumentException("The type of the token variable is not valid."); |
|
| 32 | } |
|
| 33 | if (!is_bool($test)) { |
|
| 34 | throw new InvalidArgumentException("The type of the test variable is not valid."); |
|
| 35 | } |
|
| 36 | ||
| 37 | // Set the arguments of the request |
|
| 38 | $arguments = array( |
|
| 39 | "test" => $test |
|
| 40 | ); |
|
| 41 | ||
| 42 | if($token != NULL) { |
|
| 43 | $arguments["token"] = $token; |
|
| 44 | } |
|
| 45 | ||
| 46 | $this->setUrl("auth.revoke", $arguments); |
|
| 47 | ||
| 48 | // Send the request |
|
| 49 | try { |
|
| 50 | $client = new \GuzzleHttp\Client(); |
|
| 51 | $json_response = $client->request('GET', $this->getUrl(), []); |
|
| 52 | $response = json_decode( $json_response->getBody() ); |
|
| 53 | } |
|
| 54 | catch (RequestException $e) { |
|
| 55 | throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e); |
|
| 56 | } |
|
| 57 | ||
| 58 | if($response->{'ok'} === FALSE) { |
|
| 59 | throw new RuntimeException('The request to the API failed: '.$response->{'error'}."."); |
|
| 60 | } |
|
| 61 | ||
| 62 | return $this; |
|
| 63 | } |
|
| 64 | ||
| 65 | ||
| 66 | /** |
|
| @@ 96-132 (lines=37) @@ | ||
| 93 | * @param bool $include_count |
|
| 94 | * @return string |
|
| 95 | */ |
|
| 96 | public function disable($usergroup, $include_count = NULL) { |
|
| 97 | ||
| 98 | // Check if the type of the variables is valid. |
|
| 99 | if (!is_string($usergroup) || ($usergroup != NULL)) { |
|
| 100 | throw new InvalidArgumentException("The type of the usergroup variable is not valid."); |
|
| 101 | } |
|
| 102 | if (!is_bool($include_count) && ($include_count != NULL)) { |
|
| 103 | throw new InvalidArgumentException("The type of the include_count variable is not valid."); |
|
| 104 | } |
|
| 105 | ||
| 106 | // Set the arguments of the request |
|
| 107 | $arguments = array( |
|
| 108 | "usergroup" => $usergroup |
|
| 109 | ); |
|
| 110 | ||
| 111 | if ($include_count != NULL) { |
|
| 112 | $arguments["include_count"] = $include_count; |
|
| 113 | } |
|
| 114 | ||
| 115 | $this->setUrl("usergroups.disable", $arguments); |
|
| 116 | ||
| 117 | // Send the request |
|
| 118 | try { |
|
| 119 | $client = new \GuzzleHttp\Client(); |
|
| 120 | $json_response = $client->request('GET', $this->getUrl(), []); |
|
| 121 | $response = json_decode( $json_response->getBody() ); |
|
| 122 | } |
|
| 123 | catch (RequestException $e) { |
|
| 124 | throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e); |
|
| 125 | } |
|
| 126 | ||
| 127 | if($response->{'ok'} === FALSE) { |
|
| 128 | throw new RuntimeException('The request to the API failed: '.$response->{'error'}."."); |
|
| 129 | } |
|
| 130 | ||
| 131 | return $json_response->getBody(); |
|
| 132 | } |
|
| 133 | ||
| 134 | ||
| 135 | ||
| @@ 144-180 (lines=37) @@ | ||
| 141 | * @param bool $include_count |
|
| 142 | * @return string |
|
| 143 | */ |
|
| 144 | public function enable($usergroup, $include_count = NULL) { |
|
| 145 | ||
| 146 | // Check if the type of the variables is valid. |
|
| 147 | if (!is_string($usergroup) || ($usergroup != NULL)) { |
|
| 148 | throw new InvalidArgumentException("The type of the usergroup variable is not valid."); |
|
| 149 | } |
|
| 150 | if (!is_bool($include_count) && ($include_count != NULL)) { |
|
| 151 | throw new InvalidArgumentException("The type of the include_count variable is not valid."); |
|
| 152 | } |
|
| 153 | ||
| 154 | // Set the arguments of the request |
|
| 155 | $arguments = array( |
|
| 156 | "usergroup" => $usergroup |
|
| 157 | ); |
|
| 158 | ||
| 159 | if ($include_count != NULL) { |
|
| 160 | $arguments["include_count"] = $include_count; |
|
| 161 | } |
|
| 162 | ||
| 163 | $this->setUrl("usergroups.enable", $arguments); |
|
| 164 | ||
| 165 | // Send the request |
|
| 166 | try { |
|
| 167 | $client = new \GuzzleHttp\Client(); |
|
| 168 | $json_response = $client->request('GET', $this->getUrl(), []); |
|
| 169 | $response = json_decode( $json_response->getBody() ); |
|
| 170 | } |
|
| 171 | catch (RequestException $e) { |
|
| 172 | throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e); |
|
| 173 | } |
|
| 174 | ||
| 175 | if($response->{'ok'} === FALSE) { |
|
| 176 | throw new RuntimeException('The request to the API failed: '.$response->{'error'}."."); |
|
| 177 | } |
|
| 178 | ||
| 179 | return $json_response->getBody(); |
|
| 180 | } |
|
| 181 | ||
| 182 | ||
| 183 | ||
| @@ 325-361 (lines=37) @@ | ||
| 322 | * @param bool $include_disabled |
|
| 323 | * @return string |
|
| 324 | */ |
|
| 325 | public function usersList($usergroup, $include_disabled = NULL) { |
|
| 326 | ||
| 327 | // Check if the type of the variables is valid. |
|
| 328 | if (!is_string($usergroup) || ($usergroup == NULL)) { |
|
| 329 | throw new InvalidArgumentException("The type of the usergroup variable is not valid."); |
|
| 330 | } |
|
| 331 | if (!is_bool($include_disabled) && ($include_disabled != NULL)) { |
|
| 332 | throw new InvalidArgumentException("The type of the include_disabled variable is not valid."); |
|
| 333 | } |
|
| 334 | ||
| 335 | // Set the arguments of the request |
|
| 336 | $arguments = array( |
|
| 337 | "usergroup" => $usergroup |
|
| 338 | ); |
|
| 339 | ||
| 340 | if ($include_disabled != NULL) { |
|
| 341 | $arguments["include_disabled"] = $include_disabled; |
|
| 342 | } |
|
| 343 | ||
| 344 | $this->setUrl("usergroups.users.list", $arguments); |
|
| 345 | ||
| 346 | // Send the request |
|
| 347 | try { |
|
| 348 | $client = new \GuzzleHttp\Client(); |
|
| 349 | $json_response = $client->request('GET', $this->getUrl(), []); |
|
| 350 | $response = json_decode( $json_response->getBody() ); |
|
| 351 | } |
|
| 352 | catch (RequestException $e) { |
|
| 353 | throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e); |
|
| 354 | } |
|
| 355 | ||
| 356 | if($response->{'ok'} === FALSE) { |
|
| 357 | throw new RuntimeException('The request to the API failed: '.$response->{'error'}."."); |
|
| 358 | } |
|
| 359 | ||
| 360 | return $json_response->getBody(); |
|
| 361 | } |
|
| 362 | ||
| 363 | ||
| 364 | ||