Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PubNub Metrics BLOCK w/ Librato API
const xhr = require('xhr');
const auth = require('codec/auth');
const query = require('codec/query_string');
export default (request) => {
const username = 'YOUR_LIBRATO_EMAIL';
const password = 'YOUR_LIBRATO_APIKEY';
const apiUrl = 'https://metrics-api.librato.com/v1/metrics';
const httpOptions = {
method: 'post',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
Authorization: auth.basic(username, password)
},
body: query.stringify({
"gauges[sentiment][value]": request.message.sentiment,
"gauges[sentiment][source]": request.message.userid,
"gauges[sentiment][measure_time]": parseInt(new Date().getTime() / 1000)
})
};
return xhr.fetch(apiUrl, httpOptions)
.then((r) => {
request.message.metric_result = r;
return request.ok();
})
.catch((e) => {
console.error(e);
return request.ok();
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment