Created
September 7, 2016 14:01
-
-
Save mariusv/ac4181c88fc5f9b3a5cf04869706a6e6 to your computer and use it in GitHub Desktop.
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
const request = require('request'); | |
module.exports = function(context, callback) { | |
var url = 'https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22rax%22)%0A%09%09&format=json&diagnostics=true&env=http%3A%2F%2Fdatatables.org%2Falltables.env&callback='; | |
var aux = {}; | |
request(url, function (error, response, body) { | |
if (!error && response.statusCode == 200) { | |
var info = JSON.parse(body); | |
if(context.data.company) { | |
aux = info.query.results.quote.filter(function(item) { | |
return item.symbol === context.data.company; | |
}); | |
aux = aux.length ? aux : 'No results found using: ' + context.data.company; | |
} else { | |
aux = info.query.results.quote; | |
} | |
callback(null, aux); | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment