Skip to content

Commit

Permalink
cmc fetch added
Browse files Browse the repository at this point in the history
  • Loading branch information
Praesidiarius committed Apr 12, 2021
1 parent 566b05b commit 779c144
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 6 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
64 changes: 61 additions & 3 deletions src/Controller/BatchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
}
}
}
2 changes: 1 addition & 1 deletion src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Module {
*
* @since 1.0.0
*/
const VERSION = '1.0.0';
const VERSION = '1.0.1';

/**
* Load module config file
Expand Down

0 comments on commit 779c144

Please sign in to comment.