public abstract class ServerRequest
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
boolean |
constructError_ |
protected PrefHelper |
prefHelper_ |
protected java.lang.String |
requestPath_ |
| Modifier | Constructor and Description |
|---|---|
|
ServerRequest(android.content.Context context,
java.lang.String requestPath)
Creates an instance of ServerRequest.
|
protected |
ServerRequest(java.lang.String requestPath,
org.json.JSONObject post,
android.content.Context context)
Creates an instance of ServerRequest.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
addGetParam(java.lang.String paramKey,
java.lang.String paramValue)
Adds a param and its value to the get request
|
abstract void |
clearCallbacks()
Clears the callbacks associated to this request.
|
protected boolean |
doesAppHasInternetPermission(android.content.Context context) |
static ServerRequest |
fromJSON(org.json.JSONObject json,
android.content.Context context)
Converts a
JSONObject object containing keys stored as key-value pairs into
a ServerRequest. |
org.json.JSONObject |
getGetParams()
Returns a JsonObject with the parameters that needed to be set with the get request.
|
org.json.JSONObject |
getPost()
Gets a
JSONObject containing the post data supplied with the current request as
key-value pairs. |
org.json.JSONObject |
getPostWithInstrumentationValues(java.util.concurrent.ConcurrentHashMap<java.lang.String,java.lang.String> instrumentationData)
Gets a
JSONObject containing the post data supplied with the current request as
key-value pairs appended with the instrumentation data. |
long |
getQueueWaitTime()
Returns the amount of time this request was in queque
|
java.lang.String |
getRequestPath()
Provides the path to server for this request.
|
java.lang.String |
getRequestUrl()
Provides the complete url for executing this request.
|
abstract boolean |
handleErrors(android.content.Context context)
Should be implemented by the child class.Specifies any error associated with request.
|
abstract void |
handleFailure(int statusCode,
java.lang.String causeMsg)
Called when there is an error on executing this request.
|
boolean |
isGAdsParamsRequired()
Specifies whether this request need to be updated with Google Ads Id and LAT value
By default update GAds params update is turned off.
|
abstract boolean |
isGetRequest()
Specify whether the request is a GET or POST.
|
void |
onRequestQueued()
Called when request is added to teh queue
|
abstract void |
onRequestSucceeded(ServerResponse response,
Branch branch)
Called when execution of this request to server succeeds.
|
protected void |
setPost(org.json.JSONObject post)
Sets a
JSONObject containing the post data supplied with the current request. |
boolean |
shouldRetryOnFail()
Specifies whether to retry this request on failure.
|
org.json.JSONObject |
toJSON()
|
void |
updateGAdsParams(io.branch.referral.SystemObserver sysObserver)
Updates the google ads parameters.
|
protected java.lang.String requestPath_
protected PrefHelper prefHelper_
public boolean constructError_
public ServerRequest(android.content.Context context,
java.lang.String requestPath)
Creates an instance of ServerRequest.
context - Application context.requestPath - Path to server for this request.protected ServerRequest(java.lang.String requestPath,
org.json.JSONObject post,
android.content.Context context)
Creates an instance of ServerRequest.
requestPath - Path to server for this request.post - A JSONObject containing the post data supplied with the current request
as key-value pairs.context - Application context.public abstract boolean handleErrors(android.content.Context context)
Should be implemented by the child class.Specifies any error associated with request. If there are errors request will not be executed.
context - Application context.Boolean which is set to true if there are errors with this request.
Child class is responsible for implementing its own logic for error check and reporting.public abstract void onRequestSucceeded(ServerResponse response, Branch branch)
Called when execution of this request to server succeeds. Child class should implement its own logic for handling the post request execution.
response - A ServerResponse object containing server response for this request.branch - Current Branch instancepublic abstract void handleFailure(int statusCode,
java.lang.String causeMsg)
Called when there is an error on executing this request. Child class should handle the failure accordingly.
statusCode - A Integer value specifying http return code or any branch specific error defined in BranchError.causeMsg - A String value specifying cause for the error if any.public abstract boolean isGetRequest()
Boolean value specifying if this request is a GET or not.public abstract void clearCallbacks()
public boolean shouldRetryOnFail()
Boolean whose values is true if request needed to retry on failure.public final java.lang.String getRequestPath()
Provides the path to server for this request.
see Defines.RequestPath
public java.lang.String getRequestUrl()
Provides the complete url for executing this request. URl consist of API base url and request path. Child class need to extend this method if they need to add specific items to the url
protected void setPost(org.json.JSONObject post)
Sets a JSONObject containing the post data supplied with the current request.
post - A JSONObject containing the post data supplied with the current request
as key-value pairs.public org.json.JSONObject getPost()
Gets a JSONObject containing the post data supplied with the current request as
key-value pairs.
JSONObject containing the post data supplied with the current request
as key-value pairs.public boolean isGAdsParamsRequired()
Specifies whether this request need to be updated with Google Ads Id and LAT value By default update GAds params update is turned off. Override this on request which need to have GAds params
Boolean with value true if this reuest need GAds paramspublic org.json.JSONObject getPostWithInstrumentationValues(java.util.concurrent.ConcurrentHashMap<java.lang.String,java.lang.String> instrumentationData)
Gets a JSONObject containing the post data supplied with the current request as
key-value pairs appended with the instrumentation data.
ConcurrentHashMap with instrumentation valuesJSONObject containing the post data supplied with the current request
as key-value pairs and the instrumentation meta data.public org.json.JSONObject getGetParams()
JSONObject representation of get request parameters.protected void addGetParam(java.lang.String paramKey,
java.lang.String paramValue)
paramKey - A String value for the get param keyparamValue - A String value for the get param valuepublic org.json.JSONObject toJSON()
Gets a JSONObject corresponding to the ServerRequest and
POST_KEY as currently configured.
JSONObject corresponding to the values of ServerRequest and
POST_KEY as currently configured, or null if
one or both of those values have not yet been set.public static ServerRequest fromJSON(org.json.JSONObject json, android.content.Context context)
Converts a JSONObject object containing keys stored as key-value pairs into
a ServerRequest.
json - A JSONObject object containing post data stored as key-value pairscontext - Application context.ServerRequest object with the POST_KEY
values set if not null; this can be one or the other. If both values in the
supplied JSONObject are null, null is returned instead of an object.public void updateGAdsParams(io.branch.referral.SystemObserver sysObserver)
sysObserver - SystemObserver instance.protected boolean doesAppHasInternetPermission(android.content.Context context)
public void onRequestQueued()
public long getQueueWaitTime()
Integer with value of queued time in milli sec