Created
February 14, 2013 14:00
-
-
Save svasva/4953018 to your computer and use it in GitHub Desktop.
This file contains 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
superagent = require 'superagent' | |
async = require 'async' | |
_ = require 'underscore' | |
getCurrency = (currency, cb) -> | |
path = 'http://currency-api.appspot.com' + | |
'/api/USD/' + currency + '.json' + | |
'?key=880ab1d06e0c4453208104d7a52e321dfba70748' | |
agent = superagent.agent() | |
agent.get(path).end (err, res) -> | |
cb JSON.parse(res.text) | |
exports.index = (req, res) -> | |
currencies = ['AUD', 'CAD', 'CHF', 'DKK', 'EUR'] | |
results = [] | |
async.each currencies, ((curr, cb) -> | |
getCurrency curr, (data) -> | |
results.push data | |
cb() | |
), -> | |
ret = {} | |
_.each results, (r) -> ret[r.target] = r.rate | |
res.send JSON.stringify(ret) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment