How to use the wpcom-xhr-request.post function in wpcom-xhr-request

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
Reblog.prototype.add = function (query, body, fn) {
  if ('function' === typeof body) {
    fn = body;
    body = query;
    query = {};
  }

  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 request.post(this.wpcom, null, path, query, body, fn);
};
github Automattic / wpcom.js / app.js View on Github external
Tag.prototype.add = function (query, body, fn) {
  var path = '/sites/' + this._sid + '/tags/new';
  return request.post(this.wpcom, null, path, query, body, 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