-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTwelveData.php
75 lines (64 loc) · 2.25 KB
/
TwelveData.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?PHP
namespace Brtdv\TwelveData;
use Brtdv\TwelveData\Api\CoreData;
use Brtdv\TwelveData\Api\ReferenceData;
use Brtdv\TwelveData\HttpClient\HttpClientConfigurator;
use Brtdv\TwelveData\HttpClient\RequestBuilder;
use Brtdv\TwelveData\Hydrator\Hydrator;
use Brtdv\TwelveData\Hydrator\ModelHydrator;
use Psr\Http\Client\ClientInterface;
/**
* Unofficial TwelveData PHP SDK
* For more information, see: https://twelvedata.com & https://twelvedata.com/docs#getting-started
*
* @author Bert Devriese <[email protected]>
*/
class TwelveData
{
private HttpClientConfigurator $clientConfigurator;
private ClientInterface $httpClient;
private RequestBuilder $requestBuilder;
private Hydrator $hydrator;
public function __construct(HttpClientConfigurator $clientConfigurator, ?RequestBuilder $requestBuilder = null, ?Hydrator $hydrator = null)
{
$this->clientConfigurator = $clientConfigurator;
$this->requestBuilder = $requestBuilder ?? new RequestBuilder();
$this->hydrator = $hydrator ?? new ModelHydrator();
$this->httpClient = $clientConfigurator->createConfiguredClient();
}
public static function create(string $apiKey, string $endpoint = 'https://api.twelvedata.com'): self
{
$httpClientConfigurator = (new HttpClientConfigurator())
->setApiKey($apiKey)
->setEndpoint($endpoint);
return new self($httpClientConfigurator);
}
public function getHttpClientConfigurator(): HttpClientConfigurator
{
return $this->clientConfigurator;
}
public function getHttpClient(): ClientInterface
{
return $this->httpClient;
}
/**
* All "Reference Data" related API calls
* See also: https://twelvedata.com/docs#reference-data
*
* @return ReferenceData
*/
public function referenceData(): ReferenceData
{
return new ReferenceData($this->httpClient, $this->requestBuilder, $this->hydrator);
}
/**
* All "Core Data" related API calls
* See also: https://twelvedata.com/docs#core-data
*
* @return CoreData
*/
public function coreData(): CoreData
{
return new CoreData($this->httpClient, $this->requestBuilder, $this->hydrator);
}
}