Completed
Push — master ( 903df6...64a9b8 )
by Alexander
18s queued 15s
created

AbstractHttpClient::request()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 9
rs 10
cc 3
nc 2
nop 2
1
<?php
2
3
namespace TelegramBot\Api\Http;
4
5
use TelegramBot\Api\Exception;
6
7
abstract class AbstractHttpClient implements HttpClientInterface
8
{
9
    public function request($url, array $data = null)
10
    {
11
        $response = $this->doRequest($url, $data);
12
13
        if (!isset($response['ok']) || !$response['ok']) {
14
            throw new Exception($response['description'], $response['error_code']);
15
        }
16
17
        return $response['result'];
18
    }
19
20
    public function download($url)
21
    {
22
        return $this->doDownload($url);
23
    }
24
25
    /**
26
     * @param string $url
27
     * @param array|null $data
28
     * @return array
29
     */
30
    abstract protected function doRequest($url, array $data = null);
31
32
    /**
33
     * @param string $url
34
     * @return string
35
     */
36
    abstract protected function doDownload($url);
37
}
38