'use strict';
const timer = require('../../timer')
/**
 * @apiDescription Create a new time on the cluster
 * @apiGroup timer
 * @apiName create_timer
 * @api {post} /timer Create a new timer
 * @apiVersion 1.0.0 
 * @apiParam {Number} timeout the time in miliseconds before the timer executes
 * @apiParam {String} data a data payload to include with the timer when it executes
 * @apiParam {Object} callback
 * @apiParam {String} callback.transport The delivery transport to use when executing the timer
 * @apiParam {String} callback.method The method of delivery the tranport should use
 * @apiParam {String} callback.uri A full uri the transport should send data to
 * @apiExample {curl} curl:
 *  curl -XPOST -H "Content-Type: application/json" http://localhost:3000/timer  -d '{
 *  "timeout": 3000,
 *  "data": "{\"name\":\"Bill\"}",
 *  "callback": {
 *    "method": "post",
 *    "uri": "http://mydomain.name/timer/callback",
 *    "tranport:"http"
 *  }
 *  @apiExample {js} Node.js:
 *  const http = require('http')
 *  const options = {
 *     hostname: 'localhost',
 *     port: 3000,
 *     path: '/timer',
 *     method: 'POST',
 *     headers: {
 *       'Content-Type': 'application/json',
 *       'Content-Length': Buffer.byteLength(postData)
 *     }
 *   };
 *  const data = JSON.stringify({
 *    timeout: 5000,
 *    data: {foo: 'bar', bar: 'baz'},
 *    callback: {
 *      transport: 'http',
 *      method: 'post',
 *      uri: 'http://mydomain.name/timer/callback
 *    }
 *  })
 *  const req = http.request(options, (res) => {
 *    let data = '';
 *    res.on('data', (chunk) => {
 *      data += chunk;
 *    });
 *
 *    res.on('end', () => {
 *      // done
 *    });
 *  })
 *  req.write(data);
 *  req.end();
 **/
module.exports = {
  path: '/timer'
, method: 'POST'
, middleware: [require('./middleware/proxy')]
, handler: (req, res, node, cb) => {
		const id = req.$.headers['x-timer-id']
		timer.create(id, req.$.body, (err) => {
			if (err) return cb(err)
			res.$.set('location', `/timer/${id}`)
			cb()
		})
	}
}

@@ -43,16 +43,343 @@
 /timer')
+;%0Amodule.exports = %7B%0A  path: '/timer'%0A, method: 'POST'%0A, middleware: %5Brequire('./middleware/proxy')%5D%0A, handler: (req, res, node, cb) =%3E %7B%0A    const id = req.$.headers%5B'x-timer-id'%5D;%0A    timer.create(id, req.$.body, (err) =%3E %7B%0A      if (err) return cb(err);%0A      res.$.set('location', %60/timer/$%7Bid%7D%60);%0A      cb();%0A    %7D);%0A%09%7D%0A%7D%0A
 %0A/**%0A * 
@@ -2073,309 +2073,4 @@
 **/%0A
-module.exports = %7B%0A  path: '/timer'%0A, method: 'POST'%0A, middleware: %5Brequire('./middleware/proxy')%5D%0A, handler: (req, res, node, cb) =%3E %7B%0A%09%09const id = req.$.headers%5B'x-timer-id'%5D%0A%09%09timer.create(id, req.$.body, (err) =%3E %7B%0A%09%09%09if (err) return cb(err)%0A%09%09%09res.$.set('location', %60/timer/$%7Bid%7D%60)%0A%09%09%09cb()%0A%09%09%7D)%0A%09%7D%0A%7D%0A

move the api docs to the bottom of the file