Skip to content

Commit

Permalink
Add assets, and exchanges API (#7)
Browse files Browse the repository at this point in the history
Add assets, and exchanges API
  • Loading branch information
peter279k authored Jun 11, 2018
1 parent 5dad284 commit 5fb4492
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ php:
- 7.2

env:
global:
- secure: sMyHj0bjZvSEWhfg1WGQ7Bi1LOJhpxlKsDiai62X6VxcLJUjZS60sfenWF+vlVY9/TdAr3Cqt79QBYYDPVewsEe6yFaSOD00UayOcRtKDjc3HAfNNG9unTA4bCtR65oaY44lRSm1e4NQNyJ5Grsi8vtoC+6fSXt7HMBHzfhC8qaWHl8nmUn2TD2QNFPYp65Q0M25GTlnl5K77n/7Z4v3y9hujLi7qB5M2FjlXel9zqsXdcnkqkodpj5TZKC2GZtm6h/xWLetWi9rLcVT7KHA4jlCisx6BHjsaSaz7McQFZRlGfgPItRyNx9WBZ9N3ZcuR0OMZQf/xSAACI0YBwbfNOpTpVTe8R3ACXhceXR62HixTEHhXorbFW8DOeC/qaBikDt1O0kDM/mQSZ9fWieTi2Dt9V/iPKDjEgi/BVBMWixtPrDibQV/wQy6/QQj2o+JlYKjpOHNYHttE5pPxp3XLdQxwyUTfUt5tYos7KFRUu6eBzPfiC9sBCoh+ucz7XGDlEJDK+8h1X8xVUAhSlybwprYKTH7/SvpveJFXRhF/uCokHskRCiId1rJElBMLwQ+tg5AZQps9OAr9SOcGHttFHZdFlv1aQOCSVSM7TNR3/OMIjHPxRC9gMwQure0sWGyu1s4EZVXY4Wc+w2ztiEaXrpP+nT7oLKVuf42Jlkj5q4=
matrix:
-
- DEPENDENCIES=--prefer-lowest

matrix:
Expand Down
42 changes: 42 additions & 0 deletions src/Resource/GetAssets.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
declare(strict_types=1);

namespace PayCrypto\Resource;

use PayCrypto\CryptoMonitor;
use ScriptFUSION\Porter\Collection\CountableProviderRecords;
use ScriptFUSION\Porter\Connector\ImportConnector;
use ScriptFUSION\Porter\Provider\Patreon\Collection\PledgeRecords;
use ScriptFUSION\Porter\Provider\Patreon\PatreonProvider;
use ScriptFUSION\Porter\Provider\Resource\ProviderResource;

class GetAssets implements ProviderResource
{
private $apiKey;

public function __construct(string $apiKey)
{
$this->apiKey = $apiKey;
}

public function getProviderClassName(): string
{
return CryptoMonitor::class;
}

public function fetch(ImportConnector $connector): \Iterator
{
$response = \json_decode(
(string) $connector->fetch(
CryptoMonitor::buildExchangeApiUrl(
'v1/assets'
)
),
true
);

$assets = new \ArrayIterator($response);

return new CountableProviderRecords($assets, count($assets), $this);
}
}
42 changes: 42 additions & 0 deletions src/Resource/GetExchanges.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
declare(strict_types=1);

namespace PayCrypto\Resource;

use PayCrypto\CryptoMonitor;
use ScriptFUSION\Porter\Collection\CountableProviderRecords;
use ScriptFUSION\Porter\Connector\ImportConnector;
use ScriptFUSION\Porter\Provider\Patreon\Collection\PledgeRecords;
use ScriptFUSION\Porter\Provider\Patreon\PatreonProvider;
use ScriptFUSION\Porter\Provider\Resource\ProviderResource;

class GetExchanges implements ProviderResource
{
private $apiKey;

public function __construct(string $apiKey)
{
$this->apiKey = $apiKey;
}

public function getProviderClassName(): string
{
return CryptoMonitor::class;
}

public function fetch(ImportConnector $connector): \Iterator
{
$response = \json_decode(
(string) $connector->fetch(
CryptoMonitor::buildExchangeApiUrl(
'v1/exchanges'
)
),
true
);

$exchanges = new \ArrayIterator($response);

return new CountableProviderRecords($exchanges, count($exchanges), $this);
}
}
28 changes: 28 additions & 0 deletions tests/Functional/GetAssetsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
declare(strict_types=1);

namespace PayCrypto\Tests;

use PHPUnit\Framework\TestCase;
use PayCrypto\Resource\GetAssets;
use PayCrypto\Collection\AssetsRecord;
use ScriptFUSION\Porter\Specification\ImportSpecification;

final class GetAssetsTest extends TestCase
{
private $apiKey = '';

public function testGetAssets()
{
$this->apiKey = getenv('COIN_API_KEY');

/** @var AssetsRecord */
$assets = FixtureFactory::createPorter()->import(new ImportSpecification(new GetAssets($this->apiKey)));

foreach ($assets as $assetRecord) {
$this->assertArrayHasKey('asset_id', $assetRecord);
$this->assertArrayHasKey('name', $assetRecord);
$this->assertArrayHasKey('type_is_crypto', $assetRecord);
}
}
}
28 changes: 28 additions & 0 deletions tests/Functional/GetExchangesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
declare(strict_types=1);

namespace PayCrypto\Tests;

use PHPUnit\Framework\TestCase;
use PayCrypto\Resource\GetExchanges;
use PayCrypto\Collection\ExchangesRecord;
use ScriptFUSION\Porter\Specification\ImportSpecification;

final class GetExchangesTest extends TestCase
{
private $apiKey = '';

public function testGetExchanges()
{
$this->apiKey = getenv('COIN_API_KEY');

/** @var ExchangesRecord */
$exchanges = FixtureFactory::createPorter()->import(new ImportSpecification(new GetExchanges($this->apiKey)));

foreach ($exchanges as $exchangeRecord) {
$this->assertArrayHasKey('exchange_id', $exchangeRecord);
$this->assertArrayHasKey('website', $exchangeRecord);
$this->assertArrayHasKey('name', $exchangeRecord);
}
}
}
5 changes: 3 additions & 2 deletions tests/Functional/GetRateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@

final class GetRateTest extends TestCase
{
/** @var $apiKey This is the Coin API Key for test environment*/
private $apiKey = '4E861687-19D6-4894-87B9-E785B1EE3900';
private $apiKey = '';

public function testGetSpecificRateRecords()
{
$this->apiKey = getenv('COIN_API_KEY');

$rate = FixtureFactory::createPorter()->importOne(new ImportSpecification(new GetSpecificRate($this->apiKey)));

$this->assertArrayHasKey('asset_id_base', $rate);
Expand Down

0 comments on commit 5fb4492

Please sign in to comment.