maxleap-react-native
Version:
MaxLeap SDK for ReactNative
38 lines (34 loc) • 1.4 kB
JavaScript
;
var _ = require('underscore');
module.exports = function(ML){
/**
* @namespace Contains functions for calling and declaring
* <a href="/docs/cloud_code_guide#functions">cloud functions</a>.
* <p><strong><em>
* Some functions are only available from Cloud Code.
* </em></strong></p>
*/
ML.Cloud = ML.Cloud || {};
_.extend(ML.Cloud, /** @lends ML.Cloud */ {
/**
* Makes a call to a cloud function.
* @param {String} name The function name.
* @param {Object} data The parameters to send to the cloud function.
* @param {Object} options A Backbone-style options object
* options.success, if set, should be a function to handle a successful
* call to a cloud function. options.error should be a function that
* handles an error running the cloud function. Both functions are
* optional. Both functions take a single argument.
* @return {ML.Promise} A promise that will be resolved with the result
* of the function.
*/
run: function(name, data, options) {
var request = ML._request('functions', name, null, 'POST',
ML._encode(data, null, true), options && options.sessionToken);
return request.then(function(resp) {
var ret = ML._decode(null, resp);
return ret.result||result;
})._thenRunCallbacks(options);
}
});
}