Total Complexity | 3 |
Total Lines | 43 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
8 | trait Request |
||
9 | { |
||
10 | |||
11 | /** |
||
12 | * @param array $data |
||
13 | * @return array |
||
14 | */ |
||
15 | protected function sendRequest(array $data = []) |
||
16 | { |
||
17 | |||
18 | $ch = curl_init(TelegramBot::getEndpoint() . TelegramBot::getToken() . '/' . $this->method); |
||
19 | |||
20 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); |
||
21 | curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); |
||
22 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
||
23 | curl_setopt($ch, CURLOPT_HTTPHEADER, array( |
||
24 | 'Accept: application/json', 'Content-Type: application/json' |
||
25 | )); |
||
26 | |||
27 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); |
||
28 | curl_setopt($ch, CURLOPT_VERBOSE, false); |
||
29 | |||
30 | $response = curl_exec($ch); |
||
31 | |||
32 | curl_close($ch); |
||
33 | |||
34 | return self::validateResponse($response); |
||
35 | |||
36 | } |
||
37 | |||
38 | /** |
||
39 | * @param $response |
||
40 | * @return array |
||
41 | */ |
||
42 | private static function validateResponse($response) |
||
51 | } |
||
52 | |||
53 | } |