mirror of
https://github.com/pierre42100/ComunicWeb
synced 2024-11-22 12:09:21 +00:00
Can make API requests with promises
This commit is contained in:
parent
f815ea4fd4
commit
239bfe896e
@ -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
|
||||
*
|
||||
|
@ -47,6 +47,12 @@ var ComunicWeb = {
|
||||
* API functions
|
||||
*/
|
||||
api: {
|
||||
|
||||
/**
|
||||
* Make an asynchronous request
|
||||
*/
|
||||
exec: function(apiURI, args, withLogin){},
|
||||
|
||||
/**
|
||||
* Make an API request
|
||||
*/
|
||||
|
@ -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
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user