Last active
August 29, 2015 14:23
-
-
Save Marak/f3b8b2804cb43676c172 to your computer and use it in GitHub Desktop.
hook.io microservice for getting crypto-coin price data from coinmarketcap.com
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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