
/**
 * Module dependencies
 */

var merge = require('extend');
var debug = require('debug')('wp-connect:endpoint');

/**
 * Default endpoint option
 */

var endpoint_options = {
  "http_envelope": false,
  "pretty": false
};

/**
 * endpoints object
 */

var endpoints = {
  "me": {
    "type": "GET",
    "path": "/me"
  },

  "site": {
    "type": "GET",
    "path": "/sites/%site%"
  },

  "posts": {
    "type": "GET",
    "path": "/sites/%site%/posts",
    "options": {
      "number": 20,
      "offset": 0,
      "page": 0,
      "order": "DESC",
      "order_by": "date",
      "status": "publish"
    }
  },

  "post": {
    "type": "GET",
    "path": "/sites/%site%/posts/%post_ID%"
  },

  "post_add": {
    "type": "POST",
    "path": "/sites/%site%/posts/new"
  }
};

/**
 * Expose module
 */

module.exports = endpoint;

/**
 * Return the endpoint object given the endpoint type
 *
 * @param {String} type
 * @return {Object}
 * @api public
 */

function endpoint(type){
  if (!type) {
    return new Error('`type` must be defined');
  }

  debug('getting endpoint for `%s`', type);
  var end = endpoints[type];

  if (!end) {
    return new Error(type + ' endpoint is not defined');
  }

  // re-build endpoint default options
  end.options = end.options || {};
  merge(end.options, endpoint_options);

  debug('endpoint found');
  return end;
}

@@ -689,24 +689,124 @@
 _ID%25%22%0A  %7D,%0A%0A
+  %22post_get_by_slug%22: %7B%0A    %22type%22: %22GET%22,%0A    %22path%22: %22/sites/%25site%25/posts/slug:%25post_slug%25%22%0A  %7D,%0A%0A
   %22post_add%22

add endpoint to get a post by slug