old-silvrgit/lib/btc.min.js
2015-08-04 15:07:01 +01:00

3 lines
648 B
JavaScript

var http=require("http"),btcCache={};exports.doBTC=function(e,o){function n(e,o){var n={host:"api.coindesk.com",path:"/v1/bpi/currentprice.json",headers:{}};http.request(n).on("response",function(n){var r="";n.on("data",function(e){r+=e}),n.on("end",function(){e(JSON.parse(r),o)})}).end()}console.log("Bitcoin request");var r=new Date;r-GLOBAL.lastcheck>59e3?n(function(e){console.log(e),btcCache=e,GLOBAL.lastcheck=r,o.setHeader("Content-Type","application/json"),o.end(JSON.stringify(btcCache))},o):(console.log("Using cache"),o.setHeader("Content-Type","application/json"),o.end(JSON.stringify(btcCache)))};
//# sourceMappingURL=btc.min.js.map