Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance example and add assets api #8

Merged
merged 1 commit into from
Jun 14, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 32 additions & 16 deletions example.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,55 @@
use PayCrypto\Connector\CryptoConnector;
use PayCrypto\Resource\GetSpecificRate;
use PayCrypto\Resource\GetAllRate;
use PayCrypto\Resource\GetAssets;
use ScriptFUSION\Porter\Specification\ImportSpecification;

// Get specific rate

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

$container = new Container;
$container->set(CryptoMonitor::class, new CryptoMonitor(new CryptoConnector($apiKey)));
$porter = new Porter($container);
$specificRate = new GetSpecificRate($apiKey);
$specificRate->base = 'BTC';
$specificRate->quote = 'USD';
$specificRate = new GetSpecificRate($apiKey, 'BTC', 'USD');

$rates = $porter->import(new ImportSpecification($specificRate))
->findFirstCollection();
$rates = $porter->importOne(new ImportSpecification($specificRate));

$rateRecords = $rates->toAssociativeArray();

var_dump($rateRecords);
var_dump($rates);

// Get all rates

$container = new Container;
$container->set(CryptoMonitor::class, new CryptoMonitor(new CryptoConnector($apiKey)));
$porter = new Porter($container);
$specificRate = new GetAllRate($apiKey);
$specificRate->base = 'BTC';
$specificRate = new GetAllRate($apiKey, 'BTC');

$rates = $porter->import(new ImportSpecification($specificRate));

foreach ($rates as $rateRecord) {
echo $rateRecord['asset_id_quote'] . PHP_EOL;
echo $rateRecord['rate'] . PHP_EOL;
echo $rateRecord['time'] . PHP_EOL;
}

// Get the base id

echo PHP_EOL;

$rates = $porter->import(new ImportSpecification($specificRate))
->findFirstCollection();
$rates = $rates->findFirstCollection();
echo $rates->getBase(); //BTC

$rateRecords = $rates->toAssociativeArray();
// Get Assets

$container = new Container;
$container->set(CryptoMonitor::class, new CryptoMonitor(new CryptoConnector($apiKey)));
$porter = new Porter($container);
$assets = new GetAssets($apiKey);

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

var_dump($rateRecords);
foreach ($assets as $assetRecord) {
var_dump($assetRecord['asset_id']);
var_dump($assetRecord['name']);
var_dump($assetRecord['type_is_crypto']);
}