
/**
 * Module dependencies
 */

var debug = require('debug')('wpcom:send-request');

/**
 * Request to WordPress REST API
 *
 * @param {String|Object} params
 * @param {Object} [query]
 * @param {Object} [body]
 * @param {Function} fn
 * @api private
 */

module.exports = function (params, query, body, fn) {
  // `params` can be just the path (String)  
  params = 'string' === typeof params ? { path : params } : params;

  debug('sendRequest(%o)', params.path);

  // set `method` request param
  params.method = (params.method || 'get').toUpperCase();

  // `query` is optional
  if ('function' === typeof query) {
    fn = query;
    query = null;
  }

  // `body` is optional
  if ('function' === typeof body) {
    fn = body;
    body = null;
  }

  // pass `query` and/or `body` to request params
  if (query) {
    params.query = query;

    // Handle special query parameters
    // - `apiVersion`
    if (query.apiVersion) {
      params.apiVersion = query.apiVersion;
      delete query.apiVersion;
    } else {
      params.apiVersion = this.apiVersion;
    }
  }

  if (body) {
    params.body = body;
  }

  // callback `fn` function is optional
  if (!fn) {
    fn = function (err) { if (err) { throw err; } };
  }

  // request method
  return this.request(params, fn);
};
@@ -638,28 +638,26 @@
     query = 
-null
+%7B%7D
 ;%0A  %7D%0A%0A  // 
@@ -802,25 +802,8 @@
 ams%0A
-  if (query) %7B%0A  
   pa
@@ -823,18 +823,16 @@
 query;%0A%0A
-  
   // Han
@@ -860,18 +860,16 @@
 ameters%0A
-  
   // - %60
@@ -880,18 +880,16 @@
 ersion%60%0A
-  
   if (qu
@@ -906,26 +906,24 @@
 sion) %7B%0A    
- 
- 
 params.apiVe
@@ -952,18 +952,16 @@
 on;%0A    
-  
 delete q
@@ -979,18 +979,16 @@
 sion;%0A  
- 
- 
 %7D else %7B
@@ -988,18 +988,16 @@
  else %7B%0A
-  
     para
@@ -1033,14 +1033,8 @@
 on;%0A
-    %7D%0A
   %7D%0A
@@ -1184,24 +1184,55 @@
 ; %7D %7D;%0A  %7D%0A%0A
+  debug('params: %25o', params);%0A
   // request

default value for `query` is {}