Skip to content

Instantly share code, notes, and snippets.

@sunnygleason
Created December 20, 2016 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sunnygleason/d4abe2a4a558db7478aa059c407fe75f to your computer and use it in GitHub Desktop.
Save sunnygleason/d4abe2a4a558db7478aa059c407fe75f to your computer and use it in GitHub Desktop.
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