How to use wpcom-xhr-request - 10 common examples

To help you get started, we’ve selected a few wpcom-xhr-request examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Automattic / wpcom.js / app.js View on Github external
// add attributes
      body.attrs[i] = {};
      for (k in m) {
        if ('url' !== k) {
          body.attrs[i][k] = m[k];
        }
      }
      url = m[k];
    }

    // push url into [media_url]
    body.media_urls.push(url);
  }

  return request.post(this.wpcom, def, path, query, body, fn);
};
github Automattic / wpcom.js / app.js View on Github external
for (k in f) {
        debug('add %o => %o', k, f[k]);
        if ('file' !== k) {
          param = 'attrs[' + i + '][' + k + ']';
          params.formData.push([param, f[k]]);
        }
      }
      // set file path
      f = f.file;
      f = 'string' === typeof f ? fs.createReadStream(f) : f;
    }

    params.formData.push(['media[]', f]);
  }

  return request.post(this.wpcom, def, params, query, null, fn);
};
github Automattic / wpcom.js / app.js View on Github external
Post.prototype.add = function (query, body, fn) {
  if ('function' === typeof body) {
    fn = body;
    body = query;
    query = {};
  }

  var path = '/sites/' + this._sid + '/posts/new';
  return request.post(this.wpcom, null, path, query, body, function (err, data) {
    if (err) {
      return fn(err);
    }

    // update POST object
    this._id = data.ID;
    debug('Set post _id: %s', this._id);

    this._slug = data.slug;
    debug('Set post _slug: %s', this._slug);

    fn(null, data)
  }.bind(this));
};
github Automattic / wpcom.js / app.js View on Github external
Me.prototype.get = function (query, fn) {
  return request.get(this.wpcom, null, '/me', query, fn);
};
github Automattic / wpcom.js / app.js View on Github external
Me.prototype.connections = function (query, fn) {
  return request.get(this.wpcom, null, '/me/connections', query, fn);
};
github Automattic / wpcom.js / app.js View on Github external
Site.prototype.renderEmbed = function (embed, query, fn) {
  if ('string' !== typeof embed) {
    throw new TypeError('expected an embed String');
  }

  var path = '/sites/' + this._id + '/embeds/render';
  return request.get(this.wpcom, { embed_url: embed }, path, query, fn);
};
github Automattic / wpcom.js / app.js View on Github external
Media.prototype.get = function (query, fn) {
  var path = '/sites/' + this._sid + '/media/' + this._id;
  return request.get(this.wpcom, def, path, query, fn);
};
github Automattic / wpcom.js / app.js View on Github external
Site.prototype.get = function (query, fn) {
  return request.get(this.wpcom, null, '/sites/' + this._id, query, fn);
};
github Automattic / wpcom.js / app.js View on Github external
Comment.prototype.get = function (query, fn) {
  var path = '/sites/' + this._sid + '/comments/' + this._cid;
  return request.get(this.wpcom, null, path, query, fn);
};
github Automattic / wpcom.js / app.js View on Github external
Users.prototype.suggest = function (query, fn) {
  return request.get(this.wpcom, null, '/users/suggest', query, fn);
};

wpcom-xhr-request

REST API requests to WordPress.com via XMLHttpRequest (and CORS)

MIT
Latest version published 3 years ago

Package Health Score

49 / 100
Full package analysis