php: fetch: prices: new functionality / refactor
- Add support for multiple aggregator APIs - Refactor `prices` API implementation - Update documentation
This commit is contained in:
@@ -40,7 +40,7 @@ namespace docker_finance\prices
|
||||
*/
|
||||
final class Fetch extends API
|
||||
{
|
||||
private internal\prices\Crypto $api; //!< Internal API
|
||||
private mixed $api; //!< Internal API
|
||||
|
||||
public function __construct(utils\Env $env)
|
||||
{
|
||||
@@ -50,14 +50,17 @@ namespace docker_finance\prices
|
||||
//! @brief Fetch executor
|
||||
public function fetch(): void
|
||||
{
|
||||
$subtype = $this->get_env()->get_env('API_FETCH_SUBTYPE');
|
||||
switch ($subtype) {
|
||||
case 'crypto':
|
||||
$this->api = new internal\prices\Crypto($this->get_env());
|
||||
$upstream = $this->get_env()->get_env('API_PRICES_API');
|
||||
switch ($upstream) {
|
||||
case 'coingecko':
|
||||
$this->api = new internal\prices\CoinGecko($this->get_env());
|
||||
break;
|
||||
case 'mobula':
|
||||
$this->api = new internal\prices\Mobula($this->get_env());
|
||||
break;
|
||||
default:
|
||||
utils\CLI::throw_fatal(
|
||||
"unsupported subtype '$subtype' for interal API"
|
||||
"unsupported upstream API '{$upstream}' for interal API"
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user