8000 Add Delete method · DHLRPAadmin/orchestrator-nodejs@b82864b · GitHub
[go: up one dir, main page]

Skip to content

Commit b82864b

Browse files
committed
Add Delete method
1 parent 9001954 commit b82864b

File tree

4 files changed

+67
-44
lines changed

4 files changed

+67
-44
lines changed

lib/Orchestrator.js

Lines changed: 56 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -234,54 +234,69 @@ Orchestrator.prototype._processQueue = function () {
234234
};
235235

236236
/**
237+
* @param {WELL_KNOWN_METHODS} method
237238
* @param {string} path
238-
* @param {Object.<string|Array.<string>>} query
239+
* @param {Object} data
239240
* @param {function(err: Error|undefined, response: Object=)} callback
241+
* @private
240242
*/
241-
Orchestrator.prototype.get = function (path, query, callback) {
243+
Orchestrator.prototype._methodWrapper = function (method, path, data, callback) {
242244
/** @type {OrchestratorOptions} */
243245
var options = this._options;
244-
/** @type {string} */
245-
var pathWithQuery = path + '?' + querystring.encode(query);
246246

247247
this._queue.push({
248-
method: WELL_KNOWN_METHODS.GET,
248+
method: method,
249249
options: {
250250
hostname: options.hostname,
251251
isSecure: options.isSecure,
252252
port: options.port,
253-
path: pathWithQuery,
253+
path: path,
254254
agent: this._agent,
255255
invalidCertificate: options.invalidCertificate
256256
},
257+
data: < 8000 span class=pl-s1>data,
257258
cb: callback
258259
});
259260
this._processQueue();
260261
};
261262

263+
// TODO add options (e.g. headers?, organizationUnitId, etc...)
264+
265+
/**
266+
* @param {string} path
267+
* @param {Object.<string|Array.<string>>} query
268+
* @param {function(err: Error|undefined, response: Object=)} callback
269+
*/
270+
Orchestrator.prototype.get = function (path, query, callback) {
271+
/** @type {string} */
272+
var pathWithQuery;
273+
274+
if (Object.keys(query).length > 0) {
275+
pathWithQuery = path + '?' + querystring.encode(query);
276+
} else {
277+
pathWithQuery = path;
278+
}
279+
280+
this._methodWrapper(
281+
WELL_KNOWN_METHODS.GET,
282+
pathWithQuery,
283+
undefined,
284+
callback
285+
);
286+
};
287+
262288
/**
263289
* @param {string} path
264290
* @param {Object} data
265291
* @param {function(err: Error|undefined, response: Object=)} callback
266292
*/
267293
Orchestrator.prototype.post = function (path, data, callback) {
268-
/** @type {OrchestratorOptions} */
269-
var options = this._options;
270-
271-
this._queue.push({
272-
method: WELL_KNOWN_METHODS.POST,
273-
options: {
274-
hostname: options.hostname,
275-
isSecure: options.isSecure,
276-
port: options.port,
277-
path: path,
278-
agent: this._agent,
279-
invalidCertificate: options.invalidCertificate
280-
},
281-
data: data,
282-
cb: callback
283-
});
284-
this._processQueue();
294+
this._methodWrapper(
295+
WELL_KNOWN_METHODS.POST,
296+
path,
297+
data,
298+
callback
299+
);
285300
};
286301

287302
/**
@@ -290,23 +305,25 @@ Orchestrator.prototype.post = function (path, data, callback) {
290305
* @param {function(err: Error|undefined, response: Object=)} callback
291306
*/
292307
Orchestrator.prototype.put = function (path, data, callback) {
293-
/** @type {OrchestratorOptions} */
294-
var options = this._options;
308+
this._methodWrapper(
309+
WELL_KNOWN_METHODS.PUT,
310+
path,
311+
data,
312+
callback
313+
);
314+
};
295315

296-
this._queue.push({
297-
method: WELL_KNOWN_METHODS.PUT,
298-
options: {
299-
hostname: options.hostname,
300-
isSecure: options.isSecure,
301-
port: options.port,
302-
path: path,
303-
agent: this._agent,
304-
invalidCertificate: options.invalidCertificate
305-
},
306-
data: data,
307-
cb: callback
308-
});
309-
this._processQueue();
316+
/**
317+
* @param {string} path
318+
* @param {function(err: Error|undefined, response: Object=)} callback
319+
*/
320+
Orchestrator.prototype.delete = function (path, callback) {
321+
this._methodWrapper(
322+
WELL_KNOWN_METHODS.DELETE,
323+
path,
324+
undefined,
325+
callback
326+
);
310327
};
311328

312329
/**

lib/RestGroup.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ function checkNameExistence(restGroup, name) {
3636
* @param {string} name
3737
* @param {WELL_KNOWN_METHODS} method
3838
* @param {string} path
39+
* @protected
3940
*/
4041
RestGroup.prototype.graftLeaf = function (name, method, path) {
4142
/** @type {Orchestrator} */
@@ -80,6 +81,7 @@ RestGroup.prototype.graftLeaf = function (name, method, path) {
8081
* @param {string} name
8182
* @param {string} path
8283
* @returns {RestGroup}
84+
* @protected
8385
*/
8486
RestGroup.prototype.graftNode = function (name, path) {
8587
/** @type {RestGroup} */

lib/restHelper.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ var https = require('https');
88
var WELL_KNOWN_METHODS = {
99
GET: 'GET',
1010
PUT: 'PUT',
11-
POST: 'POST'
11+
POST: 'POST',
12+
DELETE: 'DELETE'
1213
};
1314
module.exports.WELL_KNOWN_METHODS = WELL_KNOWN_METHODS;
1415

@@ -28,7 +29,7 @@ function optionMapper(method, options) {
2829
if (options.port !== undefined) {
2930
port = options.port;
3031
} else {
31-
port = (!!options.isSecure ? 443 : 80);
32+
port = (options.isSecure ? 443 : 80);
3233
}
3334
headers['content-type'] = 'application/json';
3435
headers.accept = 'application/json';
@@ -107,7 +108,7 @@ function responseHandlerFactory(callback) {
107108
* @param {OrchestratorRestHelperCallback} callback
108109
*/
109110
module.exports.getJSON = function (options, callback) {
110-
var httpModule = !!options.isSecure ? https : http;
111+
var httpModule = options.isSecure ? https : http;
111112
/** @type {ClientRequest|EventEmitter} */
112113
var request = httpModule.request(
113114
optionMapper(WELL_KNOWN_METHODS.GET, options),
@@ -128,7 +129,7 @@ module.exports.getJSON = function (options, callback) {
128129
* @param {OrchestratorRestHelperCallback} callback
129130
*/
130131
module.exports.postJSON = function (options, data, callback) {
131-
var httpModule = !!options.isSecure ? https : http;
132+
var httpModule = options.isSecure ? https : http;
132133
/** @type {ClientRequest|EventEmitter} */
133134
var request = httpModule.request(
134135
optionMapper(WELL_KNOWN_METHODS.POST, options),
@@ -150,7 +151,7 @@ module.exports.postJSON = function (options, data, callback) {
150151
* @param {OrchestratorRestHelperCallback} callback
151152
*/
152153
module.exports.putJSON = function (options, data, callback) {
153-
var httpModule = !!options.isSecure ? https : http;
154+
var httpModule = options.isSecure ? https : http;
154155
/** @type {ClientRequest|EventEmitter} */
155156
var request = httpModule.request(
156157
optionMapper(WELL_KNOWN_METHODS.PUT, options),

lib/v2/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ function populateRestGroupLeaves(restGroup, descriptors) {
2424
name = current[0];
2525
method = current[1];
2626
path = current[2];
27+
// noinspection JSAccessibilityCheck
2728
restGroup.graftLeaf(name, method, path);
2829
}
2930
}
@@ -35,8 +36,10 @@ function populateRestGroupLeaves(restGroup, descriptors) {
3536
function v2Factory(orchestrator) {
3637
/** @type {V2RestGroup|RestGroup} */
3738
var rootRestGroup = new RestGroup(orchestrator, '/');
39+
// noinspection JSAccessibilityCheck
3840
/** @type {RestGroup} */
3941
var apiRestGroup = rootRestGroup.graftNode('api', 'api/');
42+
// noinspection JSAccessibilityCheck
4043
/** @type {RestGroup} */
4144
var odataRestGroup = rootRestGroup.graftNode('odata', 'odata/');
4245

0 commit comments

Comments
 (0)
0