concordapi
Advanced tools
Comparing version 1.0.3 to 1.0.4
138
index.js
@@ -1,78 +0,68 @@ | ||
const req = require("./node_modules/requestify"); | ||
const basePublicUrl = 'https://www.cxd.network/api/public/v1/'; | ||
var cachedPrices = [], //Temporary solution until i properly learn Promises/Callbacks! Please do a pull-request if you can fix this. <3 | ||
cachedProfiles = []; | ||
const req = require('./node_modules/requestify') | ||
const basePublicUrl = 'https://www.cxd.network/api/public/v1/' | ||
var cachedPrices = [] /* Temporary solution until i properly learn Promises/Callbacks! Please do a pull-request if you can fix this. <3 */ | ||
/* cachedProfiles = [] */ | ||
exports.price = function(coin) { | ||
if(coin && coin != null && typeof coin === 'string' && coin.length >= 2){ | ||
checkPrice(coin); | ||
}else{ | ||
console.warn('String variable missing, "'+typeof coin+' - '+coin+'" was recieved'); | ||
return; | ||
} | ||
if(cachedPrices.length >= 1){ | ||
for(var ii=0; ii<cachedPrices.length; ii++){ | ||
if(cachedPrices[ii].coin == coin.toLowerCase()){ | ||
if(cachedPrices[ii].price != undefined && cachedPrices[ii].price >= 0.00000001){ | ||
//console.log(cachedPrices[ii].price); | ||
return cachedPrices[ii].price; | ||
}else{ | ||
console.warn('API Response could not be parsed, Concord REST API may be down, or your input of "'+coin.toUpperCase()+'" is an incorrect Ticker'); | ||
} | ||
} | ||
} | ||
}else{ | ||
return console.log('Cache has not loaded correctly, please use the connect function to refresh cache'); | ||
} | ||
exports.price = function (coin) { | ||
if (coin && coin != null && typeof coin === 'string' && coin.length >= 2) { | ||
checkPrice(coin) | ||
} else { | ||
console.warn('String variable missing, "' + typeof coin + ' - ' + coin + '" was recieved') | ||
return | ||
} | ||
if (cachedPrices.length >= 1) { | ||
for (var ii = 0; ii < cachedPrices.length; ii++) { | ||
if (cachedPrices[ii].coin === coin.toLowerCase()) { | ||
if (cachedPrices[ii].price !== undefined && cachedPrices[ii].price >= 0.00000001) { | ||
/* console.log(cachedPrices[ii].price); */ | ||
return cachedPrices[ii].price | ||
} else { | ||
console.warn('API Response could not be parsed, Concord REST API may be down, or your input of "' + coin.toUpperCase() + '" is an incorrect Ticker') | ||
} | ||
} | ||
} | ||
} else { | ||
return console.log('Cache has not loaded correctly, please use the connect() function to refresh cache') | ||
} | ||
} | ||
exports.connect = function() { //This exists to help with starter-caching of CXD Service API data, as i am currently unable to correctly return data from this module to a dev's main script :( | ||
try{ | ||
req.get(basePublicUrl+'getprice?coin=ic').then(function(res) { | ||
var price = Number(res.body); | ||
if(price > 0 && price != undefined){ | ||
if(cachedPrices.length > 0){ | ||
var i, | ||
iLength = cachedPrices.length; | ||
for(i=0; i<iLength; i++){ | ||
if(cachedPrices[i].coin == coin.toLowerCase()){ | ||
cachedPrices[i].price = price; //If coin is already cached, update the cache! | ||
} | ||
} | ||
}else{ | ||
cachedPrices.push({coin:'ic', price: price}); //If coin isn't already cached, cache it! | ||
} | ||
console.log('CXDx Prices cached... Services are Ready'); | ||
} | ||
}); | ||
}catch(err){ | ||
console.warn('API Request failed, error: '+err); | ||
} | ||
exports.connect = function () { /* This exists to help with starter-caching of CXD Service API data, as i am currently unable to correctly return data from this module to a dev's main script :( */ | ||
try { | ||
req.get(basePublicUrl + 'getprice?coin=ic').then(function (res) { | ||
var price = Number(res.body) | ||
if (price > 0 && price !== undefined) { | ||
if (cachedPrices.length === 0) { | ||
cachedPrices.push({coin: 'ic', price: price}) /* If coin isn't already cached, cache it! */ | ||
} | ||
console.log('CXDx Prices cached... Services are Ready') | ||
} | ||
}) | ||
} catch (err) { | ||
console.warn('API Request failed, error: ' + err) | ||
} | ||
} | ||
//None-Sandboxed functions | ||
function checkPrice(coin){ | ||
try{ | ||
req.get(basePublicUrl+'getprice?coin='+coin.toLowerCase()).then(function(res) { | ||
var price = Number(res.body); | ||
if(price >= 0.00000001 && price != undefined){ | ||
if(cachedPrices.length > 0){ | ||
var i, | ||
iLength = cachedPrices.length; | ||
for(i=0; i<iLength; i++){ | ||
if(cachedPrices[i].coin == coin.toLowerCase()){ | ||
cachedPrices[i].price = price; //If coin is already cached, update the cache! | ||
} | ||
} | ||
}else{ | ||
cachedPrices.push({coin:'ic', price: price}); //If coin isn't already cached, cache it! | ||
} | ||
}else{ | ||
console.warn('API Response could not be parsed, Concord REST API may be down, or your input of "'+coin.toUpperCase()+'" is an incorrect Ticker'); | ||
} | ||
}); | ||
}catch(err){ | ||
console.warn('API Request failed, error: '+err); | ||
} | ||
} | ||
/* None-Sandboxed functions */ | ||
function checkPrice (coin) { | ||
try { | ||
req.get(basePublicUrl + 'getprice?coin=' + coin.toLowerCase()).then(function (res) { | ||
var price = Number(res.body) | ||
if (price >= 0.00000001 && price !== undefined) { | ||
if (cachedPrices.length > 0) { | ||
var i, /* eslint-disable-line */ | ||
iLength = cachedPrices.length | ||
for (i = 0; i < iLength; i++) { | ||
if (cachedPrices[i].coin === coin.toLowerCase()) { | ||
cachedPrices[i].price = price /* If coin is already cached, update the cache! */ | ||
} | ||
} | ||
} else { | ||
cachedPrices.push({coin: 'ic', price: price}) /* If coin isn't already cached, cache it! */ | ||
} | ||
} else { | ||
console.warn('API Response could not be parsed, Concord REST API may be down, or your input of "' + coin.toUpperCase() + '" is an incorrect Ticker') | ||
} | ||
}) | ||
} catch (err) { | ||
console.warn('API Request failed, error: ' + err) | ||
} | ||
} |
{ | ||
"name": "concordapi", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "The Official Concord REST API Package for Node.js", | ||
@@ -33,3 +33,11 @@ "main": "index.js", | ||
}, | ||
"homepage": "https://github.com/Eupharia113/Concord-API" | ||
"homepage": "https://github.com/Eupharia113/Concord-API", | ||
"devDependencies": { | ||
"eslint": "^5.4.0", | ||
"eslint-config-standard": "^11.0.0", | ||
"eslint-plugin-import": "^2.14.0", | ||
"eslint-plugin-node": "^7.0.1", | ||
"eslint-plugin-promise": "^4.0.0", | ||
"eslint-plugin-standard": "^3.1.0" | ||
} | ||
} |
@@ -1,4 +0,6 @@ | ||
# Concord-API | ||
Concord-API is intended to be a simple way of interacting with the Concord Services and it's REST API via Node.js | ||
# ConcordAPI | ||
ConcordAPI is intended to be a simple way of interacting with the Concord Services and it's REST API via Node.js. | ||
[![JavaScript Style Guide](https://cdn.rawgit.com/standard/standard/master/badge.svg)](https://github.com/standard/standard) | ||
**WARNING:** This module is in very early development, and has a few bugs which are known by me, you are free to create a Pull Request if any issues/bugs are fixed, please do not rely on this module solely. | ||
@@ -15,3 +17,3 @@ | ||
```js | ||
var concord = require("concordapi"); | ||
var concord = require("concordapi") | ||
``` | ||
@@ -27,3 +29,3 @@ | ||
```js | ||
concord.connect(); //Console should print "CXDx Prices cached... Services are Ready" | ||
concord.connect() //Console should print "CXDx Prices cached... Services are Ready" | ||
``` | ||
@@ -35,3 +37,3 @@ | ||
```js | ||
concord.price(string); | ||
concord.price(string) | ||
``` | ||
@@ -41,7 +43,7 @@ | ||
```js | ||
var coin = "IC"; | ||
setInterval(checkPrice, 5000); | ||
var coin = "IC" | ||
setInterval(checkPrice, 5000) | ||
function checkPrice(){ | ||
console.log('1 '+coin+' is '+concord.price(coin)+' CXD'); | ||
function checkPrice () { | ||
console.log('1 '+coin+' is '+concord.price(coin)+' CXD') | ||
} | ||
@@ -59,11 +61,11 @@ ``` | ||
```js | ||
var concord = require("concordapi"); | ||
concord.connect(); //Instantiate Concord Library and load cache. | ||
var concord = require("concordapi") | ||
concord.connect() //Instantiate Concord Library and load cache. | ||
var coin = "IC"; //Coin listed on CXDx to check price of, in CXD. | ||
setInterval(checkPrice, 5000); //Check coin-price every 5 seconds | ||
var coin = "IC" //Coin listed on CXDx to check price of, in CXD. | ||
setInterval(checkPrice, 5000) //Check coin-price every 5 seconds | ||
function checkPrice(){ | ||
console.log('1 '+coin+' is '+concord.price(coin)+' CXD'); // Prints the price of the CXDx Coin | ||
function checkPrice () { | ||
console.log('1 '+coin+' is '+concord.price(coin)+' CXD') // Prints the price of the CXDx Coin | ||
} | ||
``` |
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
7067
6
67
6
68