Created
December 20, 2016 19:04
-
-
Save sunnygleason/d4abe2a4a558db7478aa059c407fe75f to your computer and use it in GitHub Desktop.
PubNub Financial Data w/ Xignite BLOCK
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
export default request => { | |
let xhr = require('xhr'); | |
let query = require('codec/query_string'); | |
let clientToken = 'YOUR_XIGNITE_TOKEN'; | |
let apiUrl = 'http://globalcurrencies.xignite.com/xGlobalCurrencies.json/GetRealTimeRate'; | |
let currencyOrigin = request.message.currencyOrigin; | |
let currencyDestination = request.message.currencyDestination; | |
if (!currencyOrigin || !currencyDestination) { | |
return request.ok(); | |
} | |
let queryParams = { | |
_token: clientToken, | |
Symbol: currencyOrigin + currencyDestination | |
}; | |
let url = apiUrl + '?' + query.stringify(queryParams); | |
return xhr.fetch(url).then((r) => { | |
const body = JSON.parse(r.body) || r; | |
request.message.quote = body; | |
return request.ok(); | |
}) | |
.catch((err) => { | |
console.log('error happened for XHR.fetch', err); | |
return request; | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment