PubNub Financial Data w/ Xignite BLOCK
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