| @@ 30-84 (lines=55) @@ | ||
| 27 | * @param float $timestamp |
|
| 28 | * @return Reactions |
|
| 29 | */ |
|
| 30 | public function add($name, $file = NULL, $file_comment = NULL, $channel = NULL, $timestamp = NULL) { |
|
| 31 | ||
| 32 | // Check if the type of the variables is valid. |
|
| 33 | if (!is_string($name)) { |
|
| 34 | throw new InvalidArgumentException("The type of the name variable is not valid."); |
|
| 35 | } |
|
| 36 | if (($file != NULL) && !is_string($file)) { |
|
| 37 | throw new InvalidArgumentException("The type of the file variable is not valid."); |
|
| 38 | } |
|
| 39 | if (($file_comment != NULL) && !is_string($file_comment)) { |
|
| 40 | throw new InvalidArgumentException("The type of the file_comment variable is not valid."); |
|
| 41 | } |
|
| 42 | if (($channel != NULL) && !is_string($channel)) { |
|
| 43 | throw new InvalidArgumentException("The type of the channel variable is not valid."); |
|
| 44 | } |
|
| 45 | if (($timestamp != NULL) && !is_float($timestamp)) { |
|
| 46 | throw new InvalidArgumentException("The type of the timestamp variable is not valid."); |
|
| 47 | } |
|
| 48 | ||
| 49 | // Set the arguments of the request |
|
| 50 | $arguments = array( |
|
| 51 | "name" => $name |
|
| 52 | ); |
|
| 53 | ||
| 54 | if ($file != NULL) { |
|
| 55 | $arguments["file"] = $file; |
|
| 56 | } |
|
| 57 | if ($file_comment != NULL) { |
|
| 58 | $arguments["file_comment"] = $file_comment; |
|
| 59 | } |
|
| 60 | if ($channel != NULL) { |
|
| 61 | $arguments["channel"] = $channel; |
|
| 62 | } |
|
| 63 | if ($timestamp != NULL) { |
|
| 64 | $arguments["timestamp"] = (float)$timestamp; |
|
| 65 | } |
|
| 66 | ||
| 67 | $this->setUrl("reactions.add", $arguments); |
|
| 68 | ||
| 69 | // Send the request |
|
| 70 | try { |
|
| 71 | $client = new \GuzzleHttp\Client(); |
|
| 72 | $json_response = $client->request('GET', $this->getUrl(), []); |
|
| 73 | $response = json_decode( $json_response->getBody() ); |
|
| 74 | } |
|
| 75 | catch (RequestException $e) { |
|
| 76 | throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e); |
|
| 77 | } |
|
| 78 | ||
| 79 | if($response->{'ok'} === FALSE) { |
|
| 80 | throw new RuntimeException('The request to the API failed: '.$response->{'error'}."."); |
|
| 81 | } |
|
| 82 | ||
| 83 | return $this; |
|
| 84 | } |
|
| 85 | ||
| 86 | ||
| 87 | ||
| @@ 229-283 (lines=55) @@ | ||
| 226 | * @param float $timestamp |
|
| 227 | * @return Reactions |
|
| 228 | */ |
|
| 229 | public function remove($name, $file = NULL, $file_comment = NULL, $channel = NULL, $timestamp = NULL) { |
|
| 230 | ||
| 231 | // Check if the type of the variables is valid. |
|
| 232 | if (!is_string($name)) { |
|
| 233 | throw new InvalidArgumentException("The type of the name variable is not valid."); |
|
| 234 | } |
|
| 235 | if (($file != NULL) && !is_string($file)) { |
|
| 236 | throw new InvalidArgumentException("The type of the file variable is not valid."); |
|
| 237 | } |
|
| 238 | if (($file_comment != NULL) && !is_string($file_comment)) { |
|
| 239 | throw new InvalidArgumentException("The type of the file_comment variable is not valid."); |
|
| 240 | } |
|
| 241 | if (($channel != NULL) && !is_string($channel)) { |
|
| 242 | throw new InvalidArgumentException("The type of the channel variable is not valid."); |
|
| 243 | } |
|
| 244 | if (($timestamp != NULL) && !is_float($timestamp)) { |
|
| 245 | throw new InvalidArgumentException("The type of the timestamp variable is not valid."); |
|
| 246 | } |
|
| 247 | ||
| 248 | // Set the arguments of the request |
|
| 249 | $arguments = array( |
|
| 250 | "name" => $name |
|
| 251 | ); |
|
| 252 | ||
| 253 | if ($file != NULL) { |
|
| 254 | $arguments["file"] = $file; |
|
| 255 | } |
|
| 256 | if ($file_comment != NULL) { |
|
| 257 | $arguments["file_comment"] = $file_comment; |
|
| 258 | } |
|
| 259 | if ($channel != NULL) { |
|
| 260 | $arguments["channel"] = $channel; |
|
| 261 | } |
|
| 262 | if ($timestamp != NULL) { |
|
| 263 | $arguments["timestamp"] = (string)$timestamp; |
|
| 264 | } |
|
| 265 | ||
| 266 | $this->setUrl("reactions.remove", $arguments); |
|
| 267 | ||
| 268 | // Send the request |
|
| 269 | try { |
|
| 270 | $client = new \GuzzleHttp\Client(); |
|
| 271 | $json_response = $client->request('GET', $this->getUrl(), []); |
|
| 272 | $response = json_decode( $json_response->getBody() ); |
|
| 273 | } |
|
| 274 | catch (RequestException $e) { |
|
| 275 | throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e); |
|
| 276 | } |
|
| 277 | ||
| 278 | if($response->{'ok'} === FALSE) { |
|
| 279 | throw new RuntimeException('The request to the API failed: '.$response->{'error'}."."); |
|
| 280 | } |
|
| 281 | ||
| 282 | return $this; |
|
| 283 | } |
|
| 284 | } |
|
| 285 | ||