From b2eaba7009d418a658539ce8b726621d91344313 Mon Sep 17 00:00:00 2001 From: Anders Evenrud Date: Sat, 11 Apr 2020 00:54:51 +0200 Subject: [PATCH] Abstracted some package management functionality (#106) --- src/packages.js | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/packages.js b/src/packages.js index d9be22da..d090252e 100644 --- a/src/packages.js +++ b/src/packages.js @@ -358,15 +358,7 @@ export default class Packages { * @param {PackageInstallationOption} [options] */ uninstall(name, options = {}) { - return this._apiRequest('uninstall', { - name, - options: createPackageInstallationOptions(options) - }) - .then((body) => { - if (body.reload) { - this.init(); - } - }); + return this._manageApiRequest('uninstall', options, {name}); } /** @@ -375,10 +367,20 @@ export default class Packages { * @param {PackageInstallationOption} [options] */ install(url, options = {}) { - return this._apiRequest('install', { - url, + return this._manageApiRequest('install', options, {url}); + } + + /** + * Creates a new API request for package management + * @param {string} endpoint + * @param {object} body + * @param {object} append + * @return {object} JSON + */ + _manageApiRequest(endpoint, options, append) { + return this._apiRequest(endpoint, Object.assign({ options: createPackageInstallationOptions(options) - }) + }, append)) .then((body) => { if (body.reload) { this.init();