
/**
 * Module dependencies.
 */

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

/**
 * Reblog methods
 *
 * @param {String} pid post id
 * @param {String} sid site id
 * @param {WPCOM} wpcom
 * @api public
 */

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

  if (!pid) {
    throw new Error('`post id` is not correctly defined');
  }

  if (!(this instanceof Reblog)) return new Reblog(pid, sid, wpcom);

  this.wpcom = wpcom;
  this._pid = pid;
  this._sid = sid;
}

/**
 * Get your reblog status for a Post
 *
 * @param {Object} [query]
 * @param {Function} fn
 * @api public
 */

Reblog.prototype.state =
Reblog.prototype.mine = function(query, fn){
  var path = '/sites/' + this._sid + '/posts/' + this._pid + '/reblogs/mine';
  return this.wpcom.sendRequest(path, query, null, fn);
};

/**
 * Reblog a post
 *
 * @param {Object} body
 * @param {Function} fn
 * @api public
 */

Reblog.prototype.add = function(body, fn){
  if (body && !body.destination_site_id) {
    return fn(new Error('destination_site_id is not defined'));
  }

  var path = '/sites/' + this._sid + '/posts/' + this._pid + '/reblogs/new';
  return this.wpcom.sendRequest({ path: path, method: 'post' }, null, body, fn);
};

/**
 * Reblog a post to
 * It's almost a alias of Reblogs#add()
 *
 * @param {Number} dest destination
 * @param {String} [note]
 * @param {Function} fn
 * @api public
 */

Reblog.prototype.to = function(dest, note, fn){
  if ('function' == typeof note) {
    fn = note;
    note = null;
  }

  this.add({ note: note, destination_site_id: dest }, fn);
};

/**
 * Expose `Reblog` module
 */

module.exports = Reblog;

@@ -27,16 +27,57 @@
 s.%0A */%0A%0A
+var request = require('./util/request');%0A
 var debu
@@ -114,16 +114,16 @@
 blog');%0A
-
 %0A/**%0A * 
@@ -278,16 +278,17 @@
 , wpcom)
+ 
 %7B%0A  if (
@@ -469,16 +469,22 @@
 Reblog))
+ %7B%0A   
  return 
@@ -511,16 +511,20 @@
  wpcom);
+%0A  %7D
 %0A%0A  this
@@ -752,16 +752,17 @@
 function
+ 
 (query, 
@@ -760,24 +760,25 @@
  (query, fn)
+ 
 %7B%0A  var path
@@ -854,39 +854,46 @@
  return 
-this.wpcom.sendRequest(
+request.get(this.wpcom, null, 
 path, qu
@@ -896,22 +896,16 @@
 , query,
- null,
  fn);%0A%7D;
@@ -926,24 +926,51 @@
 g a post%0A *%0A
+ * @param %7BObject%7D %5Bquery%5D%0A
  * @param %7BO
@@ -1056,17 +1056,25 @@
 function
-(
+ (query, 
 body, fn
@@ -1070,26 +1070,117 @@
 y, body, fn)
+ 
 %7B%0A
+  if ('function' === typeof body) %7B%0A    fn = body;%0A    body = query;%0A    query = %7B%7D;%0A  %7D%0A%0A
   if (body &
@@ -1369,67 +1369,50 @@
 urn 
-this.wpcom.sendRequest(%7B path: path, method: 'post' %7D, null
+request.post(this.wpcom, null, path, query
 , bo
@@ -1627,16 +1627,17 @@
 function
+ 
 (dest, n
@@ -1644,16 +1644,17 @@
 ote, fn)
+ 
 %7B%0A  if (
@@ -1666,16 +1666,17 @@
 tion' ==
+=
  typeof 
@@ -1818,16 +1818,16 @@
 le%0A */%0A%0A
+
 module.e
@@ -1842,9 +1842,8 @@
  Reblog;
-%0A

use `require` module