Created
October 20, 2015 16:17
-
-
Save samuelhei/624f63fb08897c6e035a 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
//Required library request (npm i request --save) | |
var getUSDBRL = function(callback) { | |
var request = require('request'); | |
var url = 'http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.xchange%20where%20pair%3D%22USDBRL%22&format=json&diagnostics=false&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys'; | |
request(url, function (error, response, body) { | |
if (!error && response.statusCode == 200) { | |
var usdbrl = JSON.parse(body).query.results.rate.Rate; | |
callback(usdbrl); | |
} else { | |
console.log("Got an error: ", error, ", status code: ", response.statusCode); | |
} | |
}); | |
}; | |
getUSDBRL(function(usdbrl){ | |
console.log(usdbrl); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment