/**
* https://www.reddit.com/r/javascript/comments/91m0cn/-/e2zje8w/
*
* USAGE:
* https://badgen.net/runkit/amio/satisfaction/102909/employee
* https://badgen.net/runkit/amio/satisfaction/102909/people
* https://badgen.net/runkit/amio/satisfaction/102909/topic
*/
const url = require('url')
const qs = require('querystring')
const axios = require('axios')
const { send } = require('micro')
exports.endpoint = async function (req, res) {
const { args } = qs.parse(url.parse(req.url).query)
const [cid, key] = args.split('/')
const endpoint = `http://api.getsatisfaction.com/companies/${cid}.json`
const {
approximate_employee_count,
approximate_people_count,
approximate_topic_count
} = await axios(endpoint).then(res => res.data)
switch (key) {
case 'employee':
return send(res, 200, {
subject: 'employee',
status: approximate_employee_count,
color: 'green'
})
case 'people':
return send(res, 200, {
subject: 'community',
status: approximate_people_count + ' members',
color: 'green'
})
case 'topic':
return send(res, 200, {
subject: 'topic',
status: approximate_topic_count,
color: 'green'
})
default:
return send(res, 200, {
subject: 'getsatisfaction',
status: 'unknown',
color: 'grey'
})
}
}