Skip to content

Instantly share code, notes, and snippets.

@sunnygleason
Created December 19, 2016 14:00
Show Gist options
  • Save sunnygleason/e272ab2a1717de51fd01e24535609b53 to your computer and use it in GitHub Desktop.
Save sunnygleason/e272ab2a1717de51fd01e24535609b53 to your computer and use it in GitHub Desktop.
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