
/**
 * Module dependencies.
 */

var Post = require('./post');
var debug = require('debug')('wpcom:site');

/**
 * Create a Sites instance
 *
 * @param {WPCOM} wpcom
 * @api public
 */

function Sites(id, wpcom){
  if (!(this instanceof Sites)) return new Sites(id, wpcom);
  this.wpcom = wpcom;

  debug('set `%s` site id', id);
  this._id = id;
}

/**
 * Require site information
 *
 * @param {Object} [params]
 * @param {Function} fn
 * @api public
 */

Sites.prototype.get = function(params, fn){
  if (!this._id) {
    return fn(new Error('site `id` is not defined'));
  }

  this.wpcom.req.send('sites.get', { site: this._id }, params, fn);
};

/**
 * Require posts site
 *
 * @param {Object} [params]
 * @param {Function} fn
 * @api public
 */

Sites.prototype.posts = function(params, fn){
  if (!this._id) {
    return fn(new Error('site `id` is not defined'));
  }

  this.wpcom.req.send('sites.posts.get', { site: this._id }, params, fn);
};

/**
 * Create a `Post` instance
 *
 * @param {String} id
 * @api public
 */

Sites.prototype.post = function(id){
  return Post(id, this._id, this.wpcom);
};

/**
 * Add a new blog post
 *
 * @param {Object} data
 * @param {Function} fn
 * @return {Post} new Post instance
 */

Sites.prototype.addPost = function(data, fn){
  var post = Post(null, this._id, this.wpcom);
  post.add(data, fn);
  return post;
};

/**
 * Delete a blog post
 *
 * @param {String} id
 * @param {Function} fn
 * @return {Post} remove Post instance
 */

Sites.prototype.deletePost = function(id, fn){
  var post = Post(id, this._id, this.wpcom);
  post.delete(fn);
  return post;
};

/**
 * Expose `Sites` module
 */

module.exports = Sites;

@@ -944,24 +944,334 @@
 s, fn);%0A%7D;%0A%0A
+/**%0A * Require the media library%0A *%0A * @param %7BObject%7D %5Bparams%5D%0A * @param %7BFunction%7D fn%0A * @api public%0A */%0A%0ASites.prototype.media = function(params, fn)%7B%0A  if (!this._id) %7B%0A    return fn(new Error('site %60id%60 is not defined'));%0A  %7D%0A%0A  this.wpcom.req.send('sites.media.get', %7B site: this._id %7D, params, fn);%0A%7D;%0A%0A
 /**%0A * Creat

add `.media()` method