Created
December 19, 2016 14:00
-
-
Save sunnygleason/e272ab2a1717de51fd01e24535609b53 to your computer and use it in GitHub Desktop.
PubNub Metrics BLOCK w/ Librato API
This file contains 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