Conditions | 4 |
Paths | 6 |
Total Lines | 30 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
26 | public function info($bot = NULL) { |
||
27 | |||
28 | // Check if the type of the variables is valid. |
||
29 | if (!is_string($bot)) { |
||
30 | throw new InvalidArgumentException("The type of the bot variable is not valid."); |
||
31 | } |
||
32 | |||
33 | // Set the arguments of the request |
||
34 | $arguments = array( |
||
35 | "bot" => $bot |
||
36 | ); |
||
37 | |||
38 | $this->setUrl("bots.info", $arguments); |
||
39 | |||
40 | // Send the request |
||
41 | try { |
||
42 | $client = new \GuzzleHttp\Client(); |
||
43 | $json_response = $client->request('GET', $this->getUrl(), []); |
||
44 | $response = json_decode( $json_response->getBody() ); |
||
45 | } |
||
46 | catch (RequestException $e) { |
||
47 | throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e); |
||
48 | } |
||
49 | |||
50 | if($response->{'ok'} === FALSE) { |
||
51 | throw new RuntimeException('The request to the API failed: '.$response->{'error'}."."); |
||
52 | } |
||
53 | |||
54 | return $json_response->getBody(); |
||
55 | } |
||
56 | } |
||
57 |