Ox.API: fix docs, return request id from API call

This commit is contained in:
rolux 2012-07-04 13:15:32 +02:00
parent 2d4ab2b32d
commit daec992536

View file

@ -1,11 +1,23 @@
'use strict';
/*@
Ox.API <f> bind remote api to object
options <o> Options object
timeout <n|60000> request timeout
url <s> request url
callback <f> called once api discover is done
Ox.API <f> Remote API controller
options <o> Options object
timeout <n|60000> request timeout
url <s> request url
callback <f> called once api discover is done
([options, ] callback) -> <o> API controller
api <f> Remote API discovery (calls the API's `api` method)
(callback) -> <n> Request id
callback <f> Callback functions
.* <f> Remote API method call
([data, [age, ]]callback) -> <n> Request id
data <o> Request data
age <n|-1> Max-age in ms (0: not from cache, -1: from cache)
callback <f> Callback function
cancel <f> Cancels a request
(id) -> <u> undefined
id <n> Request id
@*/
Ox.API = function(options, callback) {
@ -20,7 +32,7 @@ Ox.API = function(options, callback) {
},
that = {
api: function(callback) {
Ox.Request.send({
return Ox.Request.send({
url: self.options.url,
data: {action: 'api'},
callback: callback
@ -37,12 +49,6 @@ Ox.API = function(options, callback) {
url: self.options.url
});
/*@
api <o> bakcend API
[action] <f> all api requests available on backend
cancel <f> cancel a request
options <f> get or set options
@*/
that.api(function(result) {
Ox.forEach(result.data.actions, function(val, key) {
that[key] = function(/*data, age, callback*/) {
@ -65,10 +71,12 @@ Ox.API = function(options, callback) {
data: JSON.stringify(data)
},
url: self.options.url
}, !val.cache ? {age: 0}: {}));
}, !val.cache ? {age: 0} : {}));
};
});
callback && callback();
});
return that;
};