Skip to content

Instantly share code, notes, and snippets.

@Marak
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save Marak/f3b8b2804cb43676c172 to your computer and use it in GitHub Desktop.
Save Marak/f3b8b2804cb43676c172 to your computer and use it in GitHub Desktop.
hook.io microservice for getting crypto-coin price data from coinmarketcap.com
module['exports'] = function getCoin (hook) {
var request = require('request');
var url = 'http://coinmarketcap-nexuist.rhcloud.com/api/' + hook.params.coin;
request(url, { json: true }, function (err, response, body) {
if (hook.params.currency !== 'all') {
// if a specific currency is selected, filter the results
return hook.res.end(body['price'][hook.params.currency]);
} else {
// else, send all coin data back
hook.res.end(JSON.stringify(body));
}
});
};
module['exports'].schema = {
"coin": {
"type": "string",
"format": "select",
"default": "btc",
"enum": ["btc", "ltc", "doge", "ppc"]
},
"currency": {
"type": "string",
"format": "select",
"default": "all",
"enum": ["all", "usd", "eur", "cny", "cad", "rub", "btc"]
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment