Skip to content

Commit

Permalink
Merge pull request #138 from Automattic/add/me-endpoints
Browse files Browse the repository at this point in the history
Add `me` endpoints
  • Loading branch information
retrofox authored and jsnajdr committed Jan 27, 2020
1 parent 5ba28b7 commit 704bc86
Show file tree
Hide file tree
Showing 30 changed files with 1,665 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/wpcom.js/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ TESTAPP_PORT := 3001

# Files
JS_FILES := $(wildcard index.js lib/*.js test/*.js)
JS_TESTING_FILES := $(wildcard test/test*.js)
JS_TESTING_FILES := $(wildcard test/test*.js test-whitelist/test*.js)

# applications
NODE ?= node
Expand Down
63 changes: 63 additions & 0 deletions packages/wpcom.js/dist/lib/me.connected-application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
var _createClass = require('babel-runtime/helpers/create-class')['default'];

var _classCallCheck = require('babel-runtime/helpers/class-call-check')['default'];

var root = '/me/connected-applications/';

var MeConnectedApp = (function () {

/**
* `MeConnectedApp` constructor.
*
* @param {String} appId - application identifier
* @param {WPCOM} wpcom - wpcom instance
* @return {Null} null
*/

function MeConnectedApp(appId, wpcom) {
_classCallCheck(this, MeConnectedApp);

if (!(this instanceof MeConnectedApp)) {
return new MeConnectedApp(appId, wpcom);
}
this._id = appId;
this.wpcom = wpcom;
}

/**
* Expose `MeConnectedApp` module
*/

/**
* Get one of current user's connected applications.
*
* @param {Object} [query] - query object parameter
* @param {Function} fn - callback function
* @return {Function} request handler
*/

_createClass(MeConnectedApp, [{
key: 'get',
value: function get(query, fn) {
return this.wpcom.req.get(root + this._id, query, fn);
}

/**
* Delete the app of the current user
* through of the given appId
*
* @param {Object} [query] - query object parameter
* @param {Function} fn - callback function
* @return {Function} request handler
*/
}, {
key: 'delete',
value: function _delete(query, fn) {
return this.wpcom.req.del(root + this._id + '/delete', query, fn);
}
}]);

return MeConnectedApp;
})();

module.exports = MeConnectedApp;
120 changes: 120 additions & 0 deletions packages/wpcom.js/dist/lib/me.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
var _interopRequireDefault = require('babel-runtime/helpers/interop-require-default')['default'];

/**
* Module dependencies
*/

var _meKeyringConnection = require('./me.keyring-connection');

var _meKeyringConnection2 = _interopRequireDefault(_meKeyringConnection);

var _meConnectedApplication = require('./me.connected-application');

var _meConnectedApplication2 = _interopRequireDefault(_meConnectedApplication);

var _mePublicizeConnection = require('./me.publicize-connection');

var _mePublicizeConnection2 = _interopRequireDefault(_mePublicizeConnection);

var _meSettings = require('./me.settings');

var _meSettings2 = _interopRequireDefault(_meSettings);

var _meTwoStep = require('./me.two-step');

var _meTwoStep2 = _interopRequireDefault(_meTwoStep);

/**
* Create `Me` instance
*
Expand All @@ -23,6 +49,17 @@ Me.prototype.get = function (query, fn) {
return this.wpcom.req.get('/me', query, fn);
};

/**
* Get user billing history.
*
* @param {Object} [query] - query object parameter
* @param {Function} [fn] - callback function
* @return {Function} request handler
*/
Me.prototype.billingHistory = function (query, fn) {
return this.wpcom.req.get('/me/billing-history', query, fn);
};

/**
* A list of the current user's sites
*
Expand Down Expand Up @@ -56,6 +93,89 @@ Me.prototype.groups = function (query, fn) {
return this.wpcom.req.get('/me/groups', query, fn);
};

/**
* Get current user's connected applications.
*
* @param {Object} [query] - query object parameter
* @param {Function} fn - callback function
* @return {Function} request handler
*/
Me.prototype.connectedApps = function (query, fn) {
return this.wpcom.req.get('/me/connected-applications', query, fn);
};

/**
* Get a list of all the keyring connections
* associated with the current user
*
* @param {Object} [query] - query object parameter
* @param {Function} fn - callback function
* @return {Function} request handler
*/
Me.prototype.keyringConnections = function (query, fn) {
return this.wpcom.req.get('/me/keyring-connections', query, fn);
};

/**
* Get a list of publicize connections
* that the current user has set up.
*
* @param {Object} [query] - query object parameter
* @param {Function} fn - callback function
* @return {Function} request handler
*/
Me.prototype.publicizeConnections = function (query, fn) {
return this.wpcom.req.get('/me/publicize-connections', query, fn);
};

/**
* Return a `MeSettings` instance.
*
* @return {MeSettings} MeSettings instance
*/
Me.prototype.settings = function () {
return new _meSettings2['default'](this.wpcom);
};

/**
* Return a `MeConnectedApp` instance.
*
* @param {String} id - app id
* @return {ConnectedApp} Me ConnectedApp instance
*/
Me.prototype.connectedApp = function (id) {
return new _meConnectedApplication2['default'](id, this.wpcom);
};

/**
* Return a `MePublicizeConnection` instance.
*
* @param {String} id - connection id
* @return {MePublicizeConnection} MeSettings instance
*/
Me.prototype.publicizeConnection = function (id) {
return new _mePublicizeConnection2['default'](id, this.wpcom);
};

/**
* Return a `MeTwoStep` instance.
*
* @return {MeTwoStep} MeTwoStep instance
*/
Me.prototype.twoStep = function () {
return new _meTwoStep2['default'](this.wpcom);
};

/**
* Return a `MeKeyringConnection` instance.
*
* @param {String} id - connection id
* @return {MeKeyringConnection} MeKeyringConnection instance
*/
Me.prototype.keyringConnection = function (id) {
return new _meKeyringConnection2['default'](id, this.wpcom);
};

/**
* Expose `Me` module
*/
Expand Down
63 changes: 63 additions & 0 deletions packages/wpcom.js/dist/lib/me.keyring-connection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
var _createClass = require('babel-runtime/helpers/create-class')['default'];

var _classCallCheck = require('babel-runtime/helpers/class-call-check')['default'];

var root = '/me/keyring-connections/';

var KeyringConnection = (function () {

/**
* `KeyringConnection` constructor.
*
* @param {String} keyId - the connection ID to take action on.
* @param {WPCOM} wpcom - wpcom instance
* @return {Null} null
*/

function KeyringConnection(keyId, wpcom) {
_classCallCheck(this, KeyringConnection);

if (!(this instanceof KeyringConnection)) {
return new KeyringConnection(keyId, wpcom);
}
this._id = keyId;
this.wpcom = wpcom;
}

/**
* Expose `KeyringConnection` module
*/

/**
* Get a single Keyring connection that the current user has setup.
*
* @param {Object} [query] - query object parameter
* @param {Function} fn - callback function
* @return {Function} request handler
*/

_createClass(KeyringConnection, [{
key: 'get',
value: function get(query, fn) {
return this.wpcom.req.get(root + this._id, query, fn);
}

/**
* Delete the Keyring connection (and associated token) with the
* provided ID. Also deletes all associated publicize connections.
*
* @param {Object} [query] - query object parameter
* @param {Function} fn - callback function
* @return {Function} request handler
*/
}, {
key: 'delete',
value: function _delete(query, fn) {
return this.wpcom.req.del(root + this._id + '/delete', query, fn);
}
}]);

return KeyringConnection;
})();

module.exports = KeyringConnection;
90 changes: 90 additions & 0 deletions packages/wpcom.js/dist/lib/me.publicize-connection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
var _createClass = require('babel-runtime/helpers/create-class')['default'];

var _classCallCheck = require('babel-runtime/helpers/class-call-check')['default'];

var root = '/me/publicize-connections/';

var PublicizeConnection = (function () {
/**
* `PublicizeConnection` constructor.
*
* @param {String} connectionId - application identifier
* @param {WPCOM} wpcom - wpcom instance
* @return {Null} null
*/

function PublicizeConnection(connectionId, wpcom) {
_classCallCheck(this, PublicizeConnection);

if (!(this instanceof PublicizeConnection)) {
return new PublicizeConnection(connectionId, wpcom);
}
this._id = connectionId;
this.wpcom = wpcom;
}

/**
* Expose `PublicizeConnection` module
*/

/**
* Get a single publicize connection that the current user has set up.
*
* @param {Object} [query] - query object parameter
* @param {Function} fn - callback function
* @return {Function} request handler
*/

_createClass(PublicizeConnection, [{
key: 'get',
value: function get(query, fn) {
return this.wpcom.req.get(root + this._id, query, fn);
}

/**
* Add a publicize connection belonging to the current user.
*
* @param {Object} [query] - query object parameter
* @param {Object} body - body object parameter
* @param {Function} fn - callback function
* @return {Function} request handler
*/
}, {
key: 'add',
value: function add(query, body, fn) {
return this.wpcom.req.post(root + 'new', query, body, fn);
}

/**
* Update a publicize connection belonging to the current user.
*
* @param {Object} [query] - query object parameter
* @param {Object} body - body object parameter
* @param {Function} fn - callback function
* @return {Function} request handler
*/
}, {
key: 'update',
value: function update(query, body, fn) {
return this.wpcom.req.put(root + this._id, query, body, fn);
}

/**
* Delete the app of the current user
* through of the given connectionId
*
* @param {Object} [query] - query object parameter
* @param {Function} fn - callback function
* @return {Function} request handler
*/
}, {
key: 'delete',
value: function _delete(query, fn) {
return this.wpcom.req.del(root + this._id + '/delete', query, fn);
}
}]);

return PublicizeConnection;
})();

module.exports = PublicizeConnection;
Loading

0 comments on commit 704bc86

Please sign in to comment.