public class

ForgeTask

extends Object
java.lang.Object
   ↳ io.trigger.forge.android.core.ForgeTask

Class Overview

A ForgeTask contains details about a native API call from Javascript, and has several helper methods to perform common tasks from a native API call.

Summary

Fields
public final String callid UUID for this task, to be returned with response.
public final JsonObject params The parameters passed to this API call from Javascript.
public boolean returned Whether or not the task has returned a result yet
public final WebView webView The webview that initiated this task
Public Methods
void error(String result)
void error(JsonElement result)
Return an error with data
void error(String message, String type, String subtype)
Return an error in the standard template
void error(Throwable error)
Return an error with the message from a Throwable.
void performAsync(Runnable task)
Perform an async task not on the main thread.
void performUI(Runnable task)
Perform a task on the UI thread.
void success()
Return success with no data
void success(String result)
void success(boolean result)
void success(JsonElement result)
Return success with data
[Expand]
Inherited Methods
From class java.lang.Object

Fields

public final String callid

UUID for this task, to be returned with response.

public final JsonObject params

The parameters passed to this API call from Javascript.

public boolean returned

Whether or not the task has returned a result yet

public final WebView webView

The webview that initiated this task

Public Methods

public void error (String result)

public void error (JsonElement result)

Return an error with data

Parameters
result Any JSON serializable object to be returned, requires a message property.

public void error (String message, String type, String subtype)

Return an error in the standard template

Parameters
message Human readable error message
type One of EXPECTED_FAILURE, UNEXPECTED_FAILRE, UAVAILABLE or BAD_INPUT
subtype An optional easily matched constant for particular errors that may need to be sorted programmatically.

public void error (Throwable error)

Return an error with the message from a Throwable. Useful for unexpected exceptions to ensure some feedback is sent to javascript.

Parameters
error Any unexpected throwable

public void performAsync (Runnable task)

Perform an async task not on the main thread. By default Javascript API calls happen in the Javascript thread, any long running operation should be done asynchronously.

Parameters
task task to perform

public void performUI (Runnable task)

Perform a task on the UI thread.

Parameters
task task to perform

public void success ()

Return success with no data

public void success (String result)

public void success (boolean result)

public void success (JsonElement result)

Return success with data

Parameters
result Any JSON serializable object to be returned