From 779c14429940cf9a57dd22d1cce52cf7126136fd Mon Sep 17 00:00:00 2001 From: Praesidiarius Date: Mon, 12 Apr 2021 05:38:39 +0200 Subject: [PATCH] cmc fetch added --- CHANGELOG.md | 7 +++- composer.json | 2 +- src/Controller/BatchController.php | 64 ++++++++++++++++++++++++++++-- src/Module.php | 2 +- 4 files changed, 69 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a2f674f..fa0173d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,12 @@ All notable changes to oneplace-faucet-batch will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [1.0.0] - +## [1.0.1] - 2021-04-12 + +### Added +- CMC Fetch for Coin Price Update + +## [1.0.0] - 2021-04-12 ### Added - Hall of Fame Stats diff --git a/composer.json b/composer.json index 17685ef..0ea33f6 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "onePlace Faucet Batch Module", "type": "oneplace-module", "license": "BSD-3-Clause", - "version": "1.0.0", + "version": "1.0.1", "keywords": [ "laminas", "mvc", diff --git a/src/Controller/BatchController.php b/src/Controller/BatchController.php index 81b09cb..79be825 100644 --- a/src/Controller/BatchController.php +++ b/src/Controller/BatchController.php @@ -90,7 +90,7 @@ public function halloffameAction() if(!isset($_REQUEST['authkey'])) { $bCheck = false; } else { - if($_REQUEST['authkey'] != 'SERVERBATCH') { + if($_REQUEST['authkey'] != CoreEntityController::$aGlobalSettings['batch-serverkey']) { $bCheck = false; } } @@ -226,7 +226,7 @@ public function getminerbalancesAction() if(!isset($_REQUEST['authkey'])) { $bCheck = false; } else { - if($_REQUEST['authkey'] != 'SERVERBATCH') { + if($_REQUEST['authkey'] != CoreEntityController::$aGlobalSettings['batch-serverkey']) { $bCheck = false; } } @@ -320,7 +320,7 @@ public function getminerbalancesAction() public function statsAction() { if (isset($_REQUEST['authkey'])) { - if (strip_tags($_REQUEST['authkey']) == 'server01batch') { + if (strip_tags($_REQUEST['authkey']) == CoreEntityController::$aGlobalSettings['batch-serverkey']) { $this->layout('layout/json'); $oUserTbl = new TableGateway('user', CoreEntityController::$oDbAdapter); @@ -400,4 +400,62 @@ public function statsAction() return $this->redirect()->toRoute('home'); } + + public function fetchcmcdataAction() + { + if (isset($_REQUEST['authkey'])) { + if (strip_tags($_REQUEST['authkey']) == CoreEntityController::$aGlobalSettings['batch-serverkey']) { + $this->layout('layout/json'); + + $url = 'https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest'; + $parameters = [ + 'slug' => 'bitcoin,ethereum,ethereum-classic,ravencoin,groestlcoin,bitcoin-cash,dogecoin,binance-coin,litecoin', + ]; + + $headers = [ + 'Accepts: application/json', + 'X-CMC_PRO_API_KEY: '.CoreEntityController::$aGlobalSettings['cmc-api-key'], + ]; + $qs = http_build_query($parameters); // query string encode the parameters + $request = "{$url}?{$qs}"; // create the request URL + + $curl = curl_init(); // Get cURL resource + // Set cURL options + curl_setopt_array($curl, array( + CURLOPT_URL => $request, // set the request URL + CURLOPT_HTTPHEADER => $headers, // set the headers + CURLOPT_RETURNTRANSFER => 1 // ask for raw response instead of bool + )); + + $response = curl_exec($curl); // Send the request, save the response + //print_r(json_decode($response)); // print json decoded response + curl_close($curl); // Close request + + $oJson = json_decode($response); + if ($oJson->status->error_code == 0) { + $oWallTbl = $this->getCustomTable('faucet_wallet'); + + foreach ($oJson->data as $oCoin) { + $sName = $oCoin->name; + $fCurrentPrice = $oCoin->quote->USD->price; + $fChange24h = $oCoin->quote->USD->percent_change_24h; + + if (is_numeric($fCurrentPrice) && $fCurrentPrice != '') { + $oWallTbl->update([ + 'dollar_val' => (float)$fCurrentPrice, + 'change_24h' => (float)$fChange24h, + 'last_update' => date('Y-m-d H:i:s', time()), + ], ['coin_sign' => $oCoin->symbol]); + } + } + + echo 'price update done'; + } else { + echo 'got error: ' . $oJson->status->error_code; + } + + return false; + } + } + } } diff --git a/src/Module.php b/src/Module.php index 9268aba..fa8de01 100644 --- a/src/Module.php +++ b/src/Module.php @@ -29,7 +29,7 @@ class Module { * * @since 1.0.0 */ - const VERSION = '1.0.0'; + const VERSION = '1.0.1'; /** * Load module config file