Skip to content

Commit 9ae1948

Browse files
committed
Enhance example and add assets api
1 parent 1f0dd2d commit 9ae1948

File tree

1 file changed

+32
-16
lines changed

1 file changed

+32
-16
lines changed

example.php

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,55 @@
88
use PayCrypto\Connector\CryptoConnector;
99
use PayCrypto\Resource\GetSpecificRate;
1010
use PayCrypto\Resource\GetAllRate;
11+
use PayCrypto\Resource\GetAssets;
1112
use ScriptFUSION\Porter\Specification\ImportSpecification;
1213

1314
// Get specific rate
1415

15-
$apiKey = '4E861687-19D6-4894-87B9-E785B1EE3900';
16+
$apiKey = 'your-coin-api-key';
1617

1718
$container = new Container;
1819
$container->set(CryptoMonitor::class, new CryptoMonitor(new CryptoConnector($apiKey)));
1920
$porter = new Porter($container);
20-
$specificRate = new GetSpecificRate($apiKey);
21-
$specificRate->base = 'BTC';
22-
$specificRate->quote = 'USD';
21+
$specificRate = new GetSpecificRate($apiKey, 'BTC', 'USD');
2322

24-
$rates = $porter->import(new ImportSpecification($specificRate))
25-
->findFirstCollection();
23+
$rates = $porter->importOne(new ImportSpecification($specificRate));
2624

27-
$rateRecords = $rates->toAssociativeArray();
28-
29-
var_dump($rateRecords);
25+
var_dump($rates);
3026

3127
// Get all rates
3228

3329
$container = new Container;
3430
$container->set(CryptoMonitor::class, new CryptoMonitor(new CryptoConnector($apiKey)));
3531
$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;
3845

39-
$rates = $porter->import(new ImportSpecification($specificRate))
40-
->findFirstCollection();
46+
$rates = $rates->findFirstCollection();
47+
echo $rates->getBase(); //BTC
4148

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);
4355

44-
echo $rates->getBase() . PHP_EOL;
56+
$assets = $porter->import(new ImportSpecification($assets));
4557

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

Comments
 (0)