Completed
Push — master ( 3b83d3...7d899b )
by Vladymyr
08:00
created

CoinGeckoClient::setLastResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Codenixsv\CoinGeckoApi;
6
7
use Codenixsv\CoinGeckoApi\Api\Coins;
8
use Codenixsv\CoinGeckoApi\Api\Contract;
9
use Codenixsv\CoinGeckoApi\Api\Derivatives;
10
use Codenixsv\CoinGeckoApi\Api\Events;
11
use Codenixsv\CoinGeckoApi\Api\ExchangeRates;
12
use Codenixsv\CoinGeckoApi\Api\Exchanges;
13
use Codenixsv\CoinGeckoApi\Api\Finance;
14
use Codenixsv\CoinGeckoApi\Api\Globals;
15
use Codenixsv\CoinGeckoApi\Api\Indexes;
16
use Codenixsv\CoinGeckoApi\Api\Ping;
17
use Codenixsv\CoinGeckoApi\Api\Simple;
18
use Codenixsv\CoinGeckoApi\Api\StatusUpdates;
19
use Exception;
20
use GuzzleHttp\Client;
21
use Psr\Http\Message\ResponseInterface;
22
23
/**
24
 * Class CoinGeckoClient
25
 * @package Codenixsv\CoinGeckoApi
26
 */
27
class CoinGeckoClient
28
{
29
    protected const BASE_URI = 'https://api.coingecko.com';
30
31
    /** @var Client */
32
    private $httpClient;
33 49
34
    /** @var ResponseInterface|null */
35 49
    protected $lastResponse;
36 49
37
    public function __construct(?Client $client = null)
38 38
    {
39
        $this->httpClient = $client ?: new Client(['base_uri' => self::BASE_URI]);
40 38
    }
41
42
    public function getHttpClient(): Client
43
    {
44
        return $this->httpClient;
45
    }
46
47 1
    /**
48
     * @return array
49 1
     * @throws Exception
50
     */
51
    public function ping(): array
52 1
    {
53
        return (new Ping($this))->ping();
54 1
    }
55
56
    public function simple(): Simple
57 1
    {
58
        return new Simple($this);
59 1
    }
60
61
    public function coins(): Coins
62 1
    {
63
        return new Coins($this);
64 1
    }
65
66
    public function contract(): Contract
67 1
    {
68
        return new Contract($this);
69 1
    }
70
71
    public function exchanges(): Exchanges
72 1
    {
73
        return new Exchanges($this);
74 1
    }
75
76
    public function finance(): Finance
77 1
    {
78
        return new Finance($this);
79 1
    }
80
81
    public function indexes(): Indexes
82 1
    {
83
        return new Indexes($this);
84 1
    }
85
86
    public function derivatives(): Derivatives
87 1
    {
88
        return new Derivatives($this);
89 1
    }
90
91
    public function statusUpdates(): StatusUpdates
92 1
    {
93
        return new StatusUpdates($this);
94 1
    }
95
96
    public function events(): Events
97 1
    {
98
        return new Events($this);
99 1
    }
100
101
    public function exchangeRates(): ExchangeRates
102 1
    {
103
        return new ExchangeRates($this);
104 1
    }
105
106
    public function globals(): Globals
107
    {
108
        return new Globals($this);
109
    }
110
111
    public function setLastResponse(ResponseInterface $response)
112
    {
113
        return $this->lastResponse = $response;
114
    }
115
116
    public function getLastResponse(): ?ResponseInterface
117
    {
118
        return $this->lastResponse;
119
    }
120
}
121