Completed
Push — master ( b0f401...90606c )
by Mikhail
01:11
created

Api::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace R3bers\BittrexApi\Api;
6
7
use GuzzleHttp\Client;
8
use GuzzleHttp\Exception\GuzzleException;
9
use R3bers\BittrexApi\Exception\TransformResponseException;
10
use R3bers\BittrexApi\Message\ResponseTransformer;
11
12
/**
13
 * Class Api
14
 * @package R3bers\BittrexApi\Api
15
 */
16
class Api
17
{
18
    /** @var Client */
19
    protected $client;
20
    /** @var ResponseTransformer */
21
    protected $transformer;
22
    /** @var string */
23
    private $version = 'v3';
24
    private $endpoint = '/';
25
26
    /**
27
     * Api constructor.
28
     * @param Client $client
29
     */
30 29
    public function __construct(Client $client)
31
    {
32 29
        $this->client = $client;
33 29
        $this->transformer = new ResponseTransformer();
34 29
    }
35
36
    /**
37
     * @param string $method
38
     * @param string $uri
39
     * @param array $options
40
     * @param bool|null $needSequence
41
     * @return array
42
     * @throws GuzzleException
43
     * @throws TransformResponseException
44
     */
45 26
    public function rest(string $method, string $uri, array $options = [], ?bool $needSequence = null): array
46
    {
47 26
        $response = $this->client->request($method, $this->endpoint . $this->version . $uri, $options);
48 26
        if ($method === 'HEAD')
49 2
            return $this->transformer->transformHeader($response);
50
        else
51 24
            return $this->transformer->transform($response, $needSequence);
52
    }
53
}