|
8 | 8 | use PayCrypto\Connector\CryptoConnector; |
9 | 9 | use PayCrypto\Resource\GetSpecificRate; |
10 | 10 | use PayCrypto\Resource\GetAllRate; |
| 11 | +use PayCrypto\Resource\GetAssets; |
11 | 12 | use ScriptFUSION\Porter\Specification\ImportSpecification; |
12 | 13 |
|
13 | 14 | // Get specific rate |
14 | 15 |
|
15 | | -$apiKey = '4E861687-19D6-4894-87B9-E785B1EE3900'; |
| 16 | +$apiKey = 'your-coin-api-key'; |
16 | 17 |
|
17 | 18 | $container = new Container; |
18 | 19 | $container->set(CryptoMonitor::class, new CryptoMonitor(new CryptoConnector($apiKey))); |
19 | 20 | $porter = new Porter($container); |
20 | | -$specificRate = new GetSpecificRate($apiKey); |
21 | | -$specificRate->base = 'BTC'; |
22 | | -$specificRate->quote = 'USD'; |
| 21 | +$specificRate = new GetSpecificRate($apiKey, 'BTC', 'USD'); |
23 | 22 |
|
24 | | -$rates = $porter->import(new ImportSpecification($specificRate)) |
25 | | - ->findFirstCollection(); |
| 23 | +$rates = $porter->importOne(new ImportSpecification($specificRate)); |
26 | 24 |
|
27 | | -$rateRecords = $rates->toAssociativeArray(); |
28 | | - |
29 | | -var_dump($rateRecords); |
| 25 | +var_dump($rates); |
30 | 26 |
|
31 | 27 | // Get all rates |
32 | 28 |
|
33 | 29 | $container = new Container; |
34 | 30 | $container->set(CryptoMonitor::class, new CryptoMonitor(new CryptoConnector($apiKey))); |
35 | 31 | $porter = new Porter($container); |
36 | | -$specificRate = new GetAllRate($apiKey); |
37 | | -$specificRate->base = 'BTC'; |
| 32 | +$specificRate = new GetAllRate($apiKey, 'BTC'); |
| 33 | + |
| 34 | +$rates = $porter->import(new ImportSpecification($specificRate)); |
| 35 | + |
| 36 | +foreach ($rates as $rateRecord) { |
| 37 | + echo $rateRecord['asset_id_quote'] . PHP_EOL; |
| 38 | + echo $rateRecord['rate'] . PHP_EOL; |
| 39 | + echo $rateRecord['time'] . PHP_EOL; |
| 40 | +} |
| 41 | + |
| 42 | +// Get the base id |
| 43 | + |
| 44 | +echo PHP_EOL; |
38 | 45 |
|
39 | | -$rates = $porter->import(new ImportSpecification($specificRate)) |
40 | | - ->findFirstCollection(); |
| 46 | +$rates = $rates->findFirstCollection(); |
| 47 | +echo $rates->getBase(); //BTC |
41 | 48 |
|
42 | | -$rateRecords = $rates->toAssociativeArray(); |
| 49 | +// Get Assets |
| 50 | + |
| 51 | +$container = new Container; |
| 52 | +$container->set(CryptoMonitor::class, new CryptoMonitor(new CryptoConnector($apiKey))); |
| 53 | +$porter = new Porter($container); |
| 54 | +$assets = new GetAssets($apiKey); |
43 | 55 |
|
44 | | -echo $rates->getBase() . PHP_EOL; |
| 56 | +$assets = $porter->import(new ImportSpecification($assets)); |
45 | 57 |
|
46 | | -var_dump($rateRecords); |
| 58 | +foreach ($assets as $assetRecord) { |
| 59 | + var_dump($assetRecord['asset_id']); |
| 60 | + var_dump($assetRecord['name']); |
| 61 | + var_dump($assetRecord['type_is_crypto']); |
| 62 | +} |
0 commit comments