Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
174 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace PayCrypto\Collection; | ||
|
||
use ScriptFUSION\Porter\Collection\CountableProviderRecords; | ||
use ScriptFUSION\Porter\Provider\Resource\ProviderResource; | ||
|
||
class AssetsRecord extends CountableProviderRecords | ||
{ | ||
public function __construct( | ||
\Iterator $providerRecords, | ||
int $count, | ||
ProviderResource $resource | ||
) { | ||
parent::__construct($providerRecords, $count, $resource); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace PayCrypto\Collection; | ||
|
||
use ScriptFUSION\Porter\Collection\CountableProviderRecords; | ||
use ScriptFUSION\Porter\Provider\Resource\ProviderResource; | ||
|
||
class ExchangesRecord extends CountableProviderRecords | ||
{ | ||
public function __construct( | ||
\Iterator $providerRecords, | ||
int $count, | ||
ProviderResource $resource | ||
) { | ||
parent::__construct($providerRecords, $count, $resource); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 PayCrypto\Collection\AssetsRecord; | ||
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 AssetsRecord($assets, count($assets), $this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 PayCrypto\Collection\ExchangesRecord; | ||
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 ExchangesRecord($exchanges, count($exchanges), $this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?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 | ||
{ | ||
/** @var $apiKey This is the Coin API Key for test environment*/ | ||
private $apiKey = '4E861687-19D6-4894-87B9-E785B1EE3900'; | ||
|
||
public function testGetAssets() | ||
{ | ||
/** @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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?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 | ||
{ | ||
/** @var $apiKey This is the Coin API Key for test environment*/ | ||
private $apiKey = '4E861687-19D6-4894-87B9-E785B1EE3900'; | ||
|
||
public function testGetExchanges() | ||
{ | ||
/** @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); | ||
} | ||
} | ||
} |