![JAR search and dependency download from the Maven repository](/logo.png)
co.easimart.EasimartCloud Maven / Gradle / Ivy
package co.easimart;
import java.util.List;
import java.util.Map;
import bolts.Continuation;
import bolts.Task;
/**
* The EasimartCloud class defines provides methods for interacting with Easimart Cloud Functions. A Cloud
* Function can be called with {@link #callFunctionInBackground(String, Map, FunctionCallback)}
* using a {@link FunctionCallback}. For example, this sample code calls the "validateGame" Cloud
* Function and calls processResponse if the call succeeded and handleError if it failed.
*
*
* EasimartCloud.callFunctionInBackground("validateGame", parameters, new FunctionCallback
*
* Using the callback methods is usually preferred because the network operation will not block the
* calling thread. However, in some cases it may be easier to use the
* {@link #callFunction(String, Map)} call which do block the calling thread. For example, if your
* application has already spawned a background task to perform work, that background task could use
* the blocking calls and avoid the code complexity of callbacks.
*/
public final class EasimartCloud {
/* package for test */ static EasimartCloudCodeController getCloudCodeController() {
return EasimartCorePlugins.getInstance().getCloudCodeController();
}
/**
* Calls a cloud function in the background.
*
* @param name
* The cloud function to call.
* @param params
* The parameters to send to the cloud function. This map can contain anything that could
* be placed in a EasimartObject except for EasimartObjects themselves.
*
* @return A Task that will be resolved when the cloud function has returned.
*/
public static Task callFunctionInBackground(final String name,
final Map params) {
return EasimartUser.getCurrentSessionTokenAsync().onSuccessTask(new Continuation>() {
@Override
public Task then(Task task) throws Exception {
String sessionToken = task.getResult();
return getCloudCodeController().callFunctionInBackground(name, params, sessionToken);
}
});
}
/**
* Calls a cloud function.
*
* @param name
* The cloud function to call.
* @param params
* The parameters to send to the cloud function. This map can contain anything that could
* be placed in a EasimartObject except for EasimartObjects themselves.
* @return The result of the cloud call. Result may be a @{link Map}< {@link String}, ?>,
* {@link EasimartObject}, {@link List}<?>, or any type that can be set as a field in a
* EasimartObject.
* @throws EasimartException
*/
public static T callFunction(String name, Map params) throws EasimartException {
return EasimartTaskUtils.wait(EasimartCloud.callFunctionInBackground(name, params));
}
/**
* Calls a cloud function in the background.
*
* @param name
* The cloud function to call.
* @param params
* The parameters to send to the cloud function. This map can contain anything that could
* be placed in a EasimartObject except for EasimartObjects themselves.
* @param callback
* The callback that will be called when the cloud function has returned.
*/
public static void callFunctionInBackground(String name, Map params,
FunctionCallback callback) {
EasimartTaskUtils.callbackOnMainThreadAsync(
EasimartCloud.callFunctionInBackground(name, params),
callback);
}
private EasimartCloud() {
// do nothing
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy