Skip to content

Instantly share code, notes, and snippets.

@sunnygleason
Last active December 30, 2016 16:24
Show Gist options
  • Save sunnygleason/8aa0d703a1a0baf8779b66dc1ebeaec2 to your computer and use it in GitHub Desktop.
Save sunnygleason/8aa0d703a1a0baf8779b66dc1ebeaec2 to your computer and use it in GitHub Desktop.
PubNub Content Analysis BLOCK w/ Diffbot
export default request => {
let xhr = require('xhr');
let query = require('codec/query_string');
let clientToken = 'YOUR_CLIENT_TOKEN';
let apiUrl = 'https://api.diffbot.com/v3/analyze';
let queryParams = {
token: clientToken,
url: request.message.url
};
let url = apiUrl + '?' + query.stringify(queryParams);
return xhr.fetch(url)
.then((response) => {
let json = JSON.parse(response.body);
request.message.diffbotResponse = json;
return request.ok();
})
.catch((err) => {
console.log('error happened for XHR.fetch', err);
return request.ok();
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment