
/**
 * Module dependencies.
 */

var debug = require('debug')('wpcom:category');

/**
 * Category methods
 *
 * @param {String} [slug]
 * @param {String} sid site id
 * @param {WPCOM} wpcom
 * @api public
 */

function Category(slug, sid, wpcom){
  if (!sid) {
    throw new Error('`side id` is not correctly defined');
  }

  if (!(this instanceof Category)) return new Category(slug, sid, wpcom);

  this.wpcom = wpcom;
  this._sid = sid;
  this._slug = slug;
}

/**
 * Set category `slug`
 *
 * @param {String} slug
 * @api public
 */

Category.prototype.slug = function(slug){
  this._slug = slug;
};

/**
 * Get category
 *
 * @param {Object} [query]
 * @param {Function} fn
 * @api public
 */

Category.prototype.get = function(query, fn){
  var path = '/sites/' + this._sid + '/categories/slug:' + this._slug;
  return this.wpcom.sendRequest(path, query, null, fn);
};

/**
 * Add category
 *
 * @param {Object} body
 * @param {Function} fn
 * @api public
 */

Category.prototype.add = function(body, fn){
  var path = '/sites/' + this._sid + '/categories/new';
  return this.wpcom.sendRequest({ path: path, method: 'post' }, null, body, fn);
};

/**
 * Edit category
 *
 * @param {Object} body
 * @param {Function} fn
 * @api public
 */

Category.prototype.update = function(body, fn){
  var path = '/sites/' + this._sid + '/categories/slug:' + this._slug;
  return this.wpcom.sendRequest({ path: path, method: 'post' }, null, body, fn);
};

/**
 * Delete category
 *
 * @param {Function} fn
 * @api public
 */

Category.prototype['delete'] =
Category.prototype.del = function(fn){
  var path = '/sites/' + this._sid + '/categories/slug:' + this._slug + '/delete';
  return this.wpcom.sendRequest({ path: path, method: 'post' }, null, null, fn);
};

/**
 * Expose `Category` module
 */

module.exports = Category;

@@ -26,16 +26,56 @@
 es.%0A */%0A
+var request = require('./util/request');
 %0Avar deb
@@ -860,39 +860,46 @@
  return 
-this.wpcom.sendRequest(
+request.get(this.wpcom, null, 
 path, qu
@@ -902,22 +902,16 @@
 , query,
- null,
  fn);%0A%7D;
@@ -927,32 +927,59 @@
 Add category%0A *%0A
+ * @param %7BObject%7D %5Bquery%5D%0A
  * @param %7BObjec
@@ -1056,32 +1056,39 @@
 .add = function(
+query, 
 body, fn)%7B%0A  var
@@ -1151,67 +1151,50 @@
 urn 
-this.wpcom.sendRequest(%7B path: path, method: 'post' %7D, null
+request.post(this.wpcom, null, path, query
 , bo
@@ -1222,32 +1222,59 @@
 dit category%0A *%0A
+ * @param %7BObject%7D %5Bquery%5D%0A
  * @param %7BObjec
@@ -1362,16 +1362,23 @@
 unction(
+query, 
 body, fn
@@ -1464,67 +1464,49 @@
 urn 
-this.wpcom.sendRequest(%7B path: path, method: 'post' %7D, null
+request.put(this.wpcom, null, path, query
 , bo
@@ -1536,32 +1536,59 @@
 ete category%0A *%0A
+ * @param %7BObject%7D %5Bquery%5D%0A
  * @param %7BFunct
@@ -1680,16 +1680,23 @@
 unction(
+query, 
 fn)%7B%0A  v
@@ -1788,73 +1788,49 @@
 urn 
-this.wpcom.sendRequest(%7B path: path, method: 'post' %7D, null, null
+request.del(this.wpcom, null, path, query
 , fn

update methods using request module