Skip to content

Instantly share code, notes, and snippets.

@svasva
Created February 14, 2013 14:00
Show Gist options
  • Save svasva/4953018 to your computer and use it in GitHub Desktop.
Save svasva/4953018 to your computer and use it in GitHub Desktop.
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