Skip to content

Commit a547ea2

Browse files
author
Hovhannes Babayan
committed
using Api.Methods.XXX constants for http methods
1 parent 057fbe4 commit a547ea2

16 files changed

Lines changed: 45 additions & 31 deletions

dist/attask.js

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6556,6 +6556,13 @@ function Api(config) {
65566556
this.httpOptions.path = path;
65576557
}
65586558

6559+
Api.Methods = {
6560+
GET: 'GET',
6561+
PUT: 'PUT',
6562+
DELETE: 'DELETE',
6563+
POST: 'POST'
6564+
};
6565+
65596566
require('./plugins/request')(Api);
65606567
require('./plugins/login')(Api);
65616568
require('./plugins/logout')(Api);
@@ -7117,7 +7124,7 @@ module.exports = function(Api) {
71177124
if (updates) {
71187125
params.updates = JSON.stringify(updates);
71197126
}
7120-
return this.request(objCode, params, fields, 'POST');
7127+
return this.request(objCode, params, fields, Api.Methods.POST);
71217128
};
71227129
};
71237130
},{}],41:[function(require,module,exports){
@@ -7131,7 +7138,7 @@ module.exports = function(Api) {
71317138
Api.prototype.count = function (objCode, query) {
71327139
var that = this;
71337140
return new Promise(function (resolve, reject) {
7134-
that.request(objCode + '/count', query, null, 'GET')
7141+
that.request(objCode + '/count', query, null, Api.Methods.GET)
71357142
.then(function (data) {
71367143
resolve(data.count);
71377144
}, reject);
@@ -7148,7 +7155,7 @@ module.exports = function(Api) {
71487155
* @returns {Promise} A promise which will resolved with the ID and any other specified fields of newly created object
71497156
*/
71507157
Api.prototype.create = function (objCode, params, fields) {
7151-
return this.request(objCode, params, fields, 'POST');
7158+
return this.request(objCode, params, fields, Api.Methods.POST);
71527159
};
71537160
};
71547161
},{}],43:[function(require,module,exports){
@@ -7165,7 +7172,7 @@ module.exports = function(Api) {
71657172
var params = {
71667173
updates: JSON.stringify(updates)
71677174
};
7168-
return this.request(objCode + '/' + objID, params, fields, 'PUT');
7175+
return this.request(objCode + '/' + objID, params, fields, Api.Methods.PUT);
71697176
};
71707177
};
71717178
},{}],44:[function(require,module,exports){
@@ -7180,7 +7187,7 @@ module.exports = function(Api) {
71807187
* @returns {Promise} A promise which will resolved if everything went ok and rejected otherwise
71817188
*/
71827189
Api.prototype.execute = function (objCode, objID, action, actionArgs) {
7183-
return this.request(objCode + '/' + objID + '/' + action, actionArgs, null, 'PUT');
7190+
return this.request(objCode + '/' + objID + '/' + action, actionArgs, null, Api.Methods.PUT);
71847191
};
71857192
};
71867193
},{}],45:[function(require,module,exports){
@@ -7197,9 +7204,9 @@ module.exports = function(Api) {
71977204
objIDs = [objIDs];
71987205
}
71997206
if (objIDs.length === 1) {
7200-
return this.request(objCode + '/' + objIDs[0], null, fields, 'GET');
7207+
return this.request(objCode + '/' + objIDs[0], null, fields, Api.Methods.GET);
72017208
} else {
7202-
return this.request(objCode, {id: objIDs}, fields, 'GET');
7209+
return this.request(objCode, {id: objIDs}, fields, Api.Methods.GET);
72037210
}
72047211
};
72057212
};
@@ -7215,7 +7222,7 @@ module.exports = function(Api) {
72157222
Api.prototype.login = function (username, password) {
72167223
var that = this;
72177224
return new Promise(function (resolve, reject) {
7218-
that.request('login', {username: username, password: password}, null, 'POST')
7225+
that.request('login', {username: username, password: password}, null, Api.Methods.POST)
72197226
.then(function (data) {
72207227
that.httpOptions.headers.sessionID = data.sessionID;
72217228
resolve(data);
@@ -7232,7 +7239,7 @@ module.exports = function(Api) {
72327239
Api.prototype.logout = function () {
72337240
var that = this;
72347241
return new Promise(function (resolve, reject) {
7235-
that.request('logout', null, null, 'GET').then(function (result) {
7242+
that.request('logout', null, null, Api.Methods.GET).then(function (result) {
72367243
if (result && result.success) {
72377244
delete that.httpOptions.headers.sessionID;
72387245
resolve();
@@ -7255,7 +7262,7 @@ module.exports = function(Api) {
72557262
if (objCode) {
72567263
path = objCode + path;
72577264
}
7258-
return this.request(path, null, null, 'GET');
7265+
return this.request(path, null, null, Api.Methods.GET);
72597266
};
72607267
};
72617268
},{}],49:[function(require,module,exports){
@@ -7270,7 +7277,7 @@ module.exports = function(Api) {
72707277
* @returns {Promise} A promise which will resolved with received data if everything went ok and rejected with error info otherwise
72717278
*/
72727279
Api.prototype.namedQuery = function (objCode, query, queryArgs, fields) {
7273-
return this.request(objCode + '/' + query, queryArgs, fields, 'GET');
7280+
return this.request(objCode + '/' + query, queryArgs, fields, Api.Methods.GET);
72747281
};
72757282
};
72767283
},{}],50:[function(require,module,exports){
@@ -7287,7 +7294,7 @@ module.exports = function(Api) {
72877294
var that = this;
72887295
return new Promise(function (resolve, reject) {
72897296
var params = bForce ? {force: true} : null;
7290-
that.request(objCode + '/' + objID, params, null, 'DELETE').then(function (result) {
7297+
that.request(objCode + '/' + objID, params, null, Api.Methods.DELETE).then(function (result) {
72917298
if (result && result.success) {
72927299
resolve();
72937300
} else {
@@ -7310,7 +7317,7 @@ var queryString = require('querystring'),
73107317

73117318
module.exports = function(Api) {
73127319
var requestHasData = function(method) {
7313-
return method !== 'GET' && method !== 'PUT';
7320+
return method !== Api.Methods.GET && method !== Api.Methods.PUT;
73147321
};
73157322

73167323
Api.prototype.request = function(path, params, fields, method) {
@@ -7389,7 +7396,7 @@ module.exports = function(Api) {
73897396
* @return {Promise} A promise which will resolved with search results if everything went ok and rejected otherwise
73907397
*/
73917398
Api.prototype.search = function (objCode, query, fields) {
7392-
return this.request(objCode + '/search', query, fields, 'GET');
7399+
return this.request(objCode + '/search', query, fields, Api.Methods.GET);
73937400
};
73947401
};
73957402
},{}],54:[function(require,module,exports){

dist/attask.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Api.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ function Api(config) {
3636
this.httpOptions.path = path;
3737
}
3838

39+
Api.Methods = {
40+
GET: 'GET',
41+
PUT: 'PUT',
42+
DELETE: 'DELETE',
43+
POST: 'POST'
44+
};
45+
3946
require('./plugins/request')(Api);
4047
require('./plugins/login')(Api);
4148
require('./plugins/logout')(Api);

src/plugins/copy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ module.exports = function(Api) {
1515
if (updates) {
1616
params.updates = JSON.stringify(updates);
1717
}
18-
return this.request(objCode, params, fields, 'POST');
18+
return this.request(objCode, params, fields, Api.Methods.POST);
1919
};
2020
};

src/plugins/count.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = function(Api) {
88
Api.prototype.count = function (objCode, query) {
99
var that = this;
1010
return new Promise(function (resolve, reject) {
11-
that.request(objCode + '/count', query, null, 'GET')
11+
that.request(objCode + '/count', query, null, Api.Methods.GET)
1212
.then(function (data) {
1313
resolve(data.count);
1414
}, reject);

src/plugins/create.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ module.exports = function(Api) {
77
* @returns {Promise} A promise which will resolved with the ID and any other specified fields of newly created object
88
*/
99
Api.prototype.create = function (objCode, params, fields) {
10-
return this.request(objCode, params, fields, 'POST');
10+
return this.request(objCode, params, fields, Api.Methods.POST);
1111
};
1212
};

src/plugins/edit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ module.exports = function(Api) {
1111
var params = {
1212
updates: JSON.stringify(updates)
1313
};
14-
return this.request(objCode + '/' + objID, params, fields, 'PUT');
14+
return this.request(objCode + '/' + objID, params, fields, Api.Methods.PUT);
1515
};
1616
};

src/plugins/execute.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ module.exports = function(Api) {
99
* @returns {Promise} A promise which will resolved if everything went ok and rejected otherwise
1010
*/
1111
Api.prototype.execute = function (objCode, objID, action, actionArgs) {
12-
return this.request(objCode + '/' + objID + '/' + action, actionArgs, null, 'PUT');
12+
return this.request(objCode + '/' + objID + '/' + action, actionArgs, null, Api.Methods.PUT);
1313
};
1414
};

src/plugins/get.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ module.exports = function(Api) {
1111
objIDs = [objIDs];
1212
}
1313
if (objIDs.length === 1) {
14-
return this.request(objCode + '/' + objIDs[0], null, fields, 'GET');
14+
return this.request(objCode + '/' + objIDs[0], null, fields, Api.Methods.GET);
1515
} else {
16-
return this.request(objCode, {id: objIDs}, fields, 'GET');
16+
return this.request(objCode, {id: objIDs}, fields, Api.Methods.GET);
1717
}
1818
};
1919
};

src/plugins/login.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module.exports = function(Api) {
99
Api.prototype.login = function (username, password) {
1010
var that = this;
1111
return new Promise(function (resolve, reject) {
12-
that.request('login', {username: username, password: password}, null, 'POST')
12+
that.request('login', {username: username, password: password}, null, Api.Methods.POST)
1313
.then(function (data) {
1414
that.httpOptions.headers.sessionID = data.sessionID;
1515
resolve(data);

0 commit comments

Comments
 (0)