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
|
|
|
|
34
|
|
|
/** @var ResponseInterface|null */ |
35
|
|
|
protected $lastResponse; |
36
|
|
|
|
37
|
51 |
|
public function __construct(?Client $client = null) |
38
|
|
|
{ |
39
|
51 |
|
$this->httpClient = $client ?: new Client(['base_uri' => self::BASE_URI]); |
40
|
51 |
|
} |
41
|
|
|
|
42
|
38 |
|
public function getHttpClient(): Client |
43
|
|
|
{ |
44
|
38 |
|
return $this->httpClient; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @return array |
49
|
|
|
* @throws Exception |
50
|
|
|
*/ |
51
|
1 |
|
public function ping(): array |
52
|
|
|
{ |
53
|
1 |
|
return (new Ping($this))->ping(); |
54
|
|
|
} |
55
|
|
|
|
56
|
1 |
|
public function simple(): Simple |
57
|
|
|
{ |
58
|
1 |
|
return new Simple($this); |
59
|
|
|
} |
60
|
|
|
|
61
|
1 |
|
public function coins(): Coins |
62
|
|
|
{ |
63
|
1 |
|
return new Coins($this); |
64
|
|
|
} |
65
|
|
|
|
66
|
1 |
|
public function contract(): Contract |
67
|
|
|
{ |
68
|
1 |
|
return new Contract($this); |
69
|
|
|
} |
70
|
|
|
|
71
|
1 |
|
public function exchanges(): Exchanges |
72
|
|
|
{ |
73
|
1 |
|
return new Exchanges($this); |
74
|
|
|
} |
75
|
|
|
|
76
|
1 |
|
public function finance(): Finance |
77
|
|
|
{ |
78
|
1 |
|
return new Finance($this); |
79
|
|
|
} |
80
|
|
|
|
81
|
1 |
|
public function indexes(): Indexes |
82
|
|
|
{ |
83
|
1 |
|
return new Indexes($this); |
84
|
|
|
} |
85
|
|
|
|
86
|
1 |
|
public function derivatives(): Derivatives |
87
|
|
|
{ |
88
|
1 |
|
return new Derivatives($this); |
89
|
|
|
} |
90
|
|
|
|
91
|
1 |
|
public function statusUpdates(): StatusUpdates |
92
|
|
|
{ |
93
|
1 |
|
return new StatusUpdates($this); |
94
|
|
|
} |
95
|
|
|
|
96
|
1 |
|
public function events(): Events |
97
|
|
|
{ |
98
|
1 |
|
return new Events($this); |
99
|
|
|
} |
100
|
|
|
|
101
|
1 |
|
public function exchangeRates(): ExchangeRates |
102
|
|
|
{ |
103
|
1 |
|
return new ExchangeRates($this); |
104
|
|
|
} |
105
|
|
|
|
106
|
1 |
|
public function globals(): Globals |
107
|
|
|
{ |
108
|
1 |
|
return new Globals($this); |
109
|
|
|
} |
110
|
|
|
|
111
|
38 |
|
public function setLastResponse(ResponseInterface $response) |
112
|
|
|
{ |
113
|
38 |
|
return $this->lastResponse = $response; |
114
|
|
|
} |
115
|
|
|
|
116
|
2 |
|
public function getLastResponse(): ?ResponseInterface |
117
|
|
|
{ |
118
|
2 |
|
return $this->lastResponse; |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|