Peter
目前在ITRI服務
後端開發者
3+ years PHP 後端程式開發
PHP 5.3 → PHP 7+
No framework→Slim→Laravel
2 years 開源專案貢獻者
"require": {
"php" : ">=7.1",
"scriptfusion/porter": "^4",
"connectors/http": "^2",
"joomla/di": "^1"
},
.....
composer require paycrypto/crypto-monitor
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Joomla\DI\Container;
use ScriptFUSION\Porter\Porter;
use PayCrypto\CryptoMonitor;
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 = 'your-coin-api-key';
$container = new Container;
$container->set(CryptoMonitor::class,
new CryptoMonitor(new CryptoConnector($apiKey)));
$porter = new Porter($container);
$specificRate = new GetSpecificRate($apiKey, 'BTC', 'USD');
$rates = $porter->importOne(
new ImportSpecification($specificRate));
var_dump($rates);
array(4) {
'time' =>
string(28) "2018-07-07T08:40:30.2799370Z"
'asset_id_base' =>
string(3) "BTC"
'asset_id_quote' =>
string(3) "USD"
'rate' =>
double(6579.7459800358)
}
// Get all rates
$container = new Container;
$container->set(CryptoMonitor::class,
new CryptoMonitor(
new CryptoConnector($apiKey)));
$porter = new Porter($container);
$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;
}
ENTER
134271480.5127
2018-07-07T09:07:05.1780475Z
EGOLD
1219512.195122
2018-07-07T09:07:05.1780475Z
$container = new Container;
$container->set(CryptoMonitor::class,
new CryptoMonitor(
new CryptoConnector($apiKey)));
$porter = new Porter($container);
$assets = new GetAssets($apiKey);
$assets = $porter->import(
new ImportSpecification($assets));
foreach ($assets as $assetRecord) {
var_dump($assetRecord['asset_id']);
var_dump($assetRecord['name']);
var_dump($assetRecord['type_is_crypto']);
}
/home/lee/crypto-monitor/example.php:59:
string(3) "ZDR"
/home/lee/crypto-monitor/example.php:60:
string(3) "ZDR"
/home/lee/crypto-monitor/example.php:61:
int(1)
/home/lee/crypto-monitor/example.php:59:
string(4) "ZEST"
/home/lee/crypto-monitor/example.php:60:
string(4) "ZEST"
/home/lee/crypto-monitor/example.php:61:
int(1)