Can make API requests with promises

This commit is contained in:
Pierre HUBERT 2019-05-19 15:56:44 +02:00
parent f815ea4fd4
commit 239bfe896e
3 changed files with 44 additions and 0 deletions

View File

@ -4,6 +4,31 @@
* @author Pierre HUBERT
*/
ComunicWeb.common.api = {
/**
* Make an asynchronous request over the API
*
* @returns {Promise}
*/
exec: function(apiURI, args, withLogin){
if(!args)
args = {};
return new Promise((resolve, reject) => {
this.makeAPIrequest(apiURI, args, withLogin, result => {
if(result.error)
reject(result.error);
else
resolve(result);
});
});
},
/**
* Make an API request
*

View File

@ -47,6 +47,12 @@ var ComunicWeb = {
* API functions
*/
api: {
/**
* Make an asynchronous request
*/
exec: function(apiURI, args, withLogin){},
/**
* Make an API request
*/

View File

@ -4,6 +4,19 @@
* @author Pierre HUBERT
*/
/**
* Perform an API request
*
* @param {String} uri The URI of the request on the API
* @param {Object} args The list of arguments to pass with the request
* @param {Bool} withLogin Specify whether login is required or not to
* achieve the request
* @return {Promise}
*/
function api(uri, args, withLogin){
return ComunicWeb.common.api.exec(uri, args, withLogin);
}
/**
* Create a quick language access function shorcut
*