Created
December 19, 2016 14:00
PubNub Metrics BLOCK w/ Librato API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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