/*
** beelancer-api
** author: gordon hall
**
** acknowledgement endpoint
*/

var endpoint = require('../classes/endpoint.js');

module.exports = endpoint({
	method      : 'GET',
	path        : '/',
	handler     : acknowledge,
	params      : [],
	description : 'Sanity check endpoint. Returns API name and version.',
	response    : ''
});

function acknowledge(req, res) {

	var fs    = require('fs')
	  , async = require('async')
	  ;

	async.waterfall(
		[
			getPackage
		], 
		respond
	);

	// read the package file
	function getPackage(next) {
		fs.readFile(
			__dirname + '/../../package.json',
			'utf8',
			function(err, info) {
				if (err) return next(err);
				next(null, JSON.parse(info));
			}
		);
	};

	// respond to caller
	function respond(err, info) {
		if (err) return res.send(500, { error : err });
		res.send({
			name        : info.name,
			description : info.description,
			version     : info.version
		});
	};
};