-
public abstract class ServerRequestAbstract class defining the structure of a Branch Server request.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public enumServerRequest.BRANCH_API_VERSION
-
Field Summary
Fields Modifier and Type Field Description public booleanconstructError_public intcurrentRetryCount
-
Constructor Summary
Constructors Constructor Description ServerRequest(Context context, Defines.RequestPath requestPath)Creates an instance of ServerRequest.
-
Method Summary
Modifier and Type Method Description abstract booleanhandleErrors(Context context)Should be implemented by the child class.Specifies any error associated with request.If there are errors request will not be executed. abstract voidonRequestSucceeded(ServerResponse response, Branch branch)Called when execution of this request to server succeeds. abstract voidhandleFailure(int statusCode, String causeMsg)Called when there is an error on executing this request. abstract booleanisGetRequest()Specify whether the request is a GET or POST. abstract voidclearCallbacks()Clears the callbacks associated to this request. booleanshouldRetryOnFail()Specifies whether to retry this request on failure. final StringgetRequestPath()Provides the path to server for this request. StringgetRequestUrl()Provides the complete url for executing this request. JSONObjectgetPost()Gets a JSONObject containing the post data supplied with the current request askey-value pairs. booleanisGAdsParamsRequired()Specifies whether this request need to be updated with Google Ads Id and LAT valueBy default update GAds params update is turned on. JSONObjectgetPostWithInstrumentationValues(ConcurrentHashMap<String, String> instrumentationData)Gets a JSONObject containing the post data supplied with the current request askey-value pairs appended with the instrumentation data. JSONObjectgetGetParams()Returns a JsonObject with the parameters that needed to be set with the get request. JSONObjecttoJSON()Gets a JSONObject corresponding to the ServerRequest and POST_KEY as currently configured. static ServerRequestfromJSON(JSONObject json, Context context)Converts a JSONObject object containing keys stored as key-value pairs intoa ServerRequest. voidonRequestQueued()Called when request is added to teh queue longgetQueueWaitTime()Returns the amount of time this request was in queque voidaddProcessWaitLock(ServerRequest.PROCESS_WAIT_LOCK lock)Set the specified process wait lock for this request. voidremoveProcessWaitLock(ServerRequest.PROCESS_WAIT_LOCK lock)Unlock the specified lock from the request. booleanisWaitingOnProcessToFinish()Check if this request is waiting on any operation to finish before processing voidonPreExecute()Called on UI thread just before executing a request. ServerRequest.BRANCH_API_VERSIONgetBranchRemoteAPIVersion()Returns the Branch API version -
-
Constructor Detail
-
ServerRequest
ServerRequest(Context context, Defines.RequestPath requestPath)
Creates an instance of ServerRequest.- Parameters:
context- Application context.requestPath- Path to server for this request.
-
-
Method Detail
-
handleErrors
abstract boolean handleErrors(Context context)
Should be implemented by the child class.Specifies any error associated with request.If there are errors request will not be executed.
- Parameters:
context- Application context.
-
onRequestSucceeded
abstract void onRequestSucceeded(ServerResponse response, Branch branch)
Called when execution of this request to server succeeds. Child class should implementits own logic for handling the post request execution.
- Parameters:
response- A ServerResponse object containing server response for this request.branch- Current Branch instance
-
handleFailure
abstract void handleFailure(int statusCode, String causeMsg)
Called when there is an error on executing this request. Child class should handle the failureaccordingly.
- Parameters:
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.
-
isGetRequest
abstract boolean isGetRequest()
Specify whether the request is a GET or POST. Child class has to implement accordingly.
-
clearCallbacks
abstract void clearCallbacks()
Clears the callbacks associated to this request.
-
shouldRetryOnFail
boolean shouldRetryOnFail()
Specifies whether to retry this request on failure. By default request is not retried on fail.Those request which need to retry on failure should override and handle accordingly
-
getRequestPath
final String getRequestPath()
Provides the path to server for this request.see Defines.RequestPath
-
getRequestUrl
String getRequestUrl()
Provides the complete url for executing this request. URl consist of API base url and requestpath. Child class need to extend this method if they need to add specific items to the url
-
getPost
JSONObject getPost()
Gets a JSONObject containing the post data supplied with the current request askey-value pairs.
-
isGAdsParamsRequired
boolean isGAdsParamsRequired()
Specifies whether this request need to be updated with Google Ads Id and LAT valueBy default update GAds params update is turned on. Override this on request which need to have GAds params
-
getPostWithInstrumentationValues
JSONObject getPostWithInstrumentationValues(ConcurrentHashMap<String, String> instrumentationData)
Gets a JSONObject containing the post data supplied with the current request askey-value pairs appended with the instrumentation data.
* @param instrumentationData ConcurrentHashMap with instrumentation values
-
getGetParams
JSONObject getGetParams()
Returns a JsonObject with the parameters that needed to be set with the get request.
-
toJSON
@CallSuper() JSONObject toJSON()
Gets a JSONObject corresponding to the ServerRequest and POST_KEY as currently configured.
-
fromJSON
static ServerRequest fromJSON(JSONObject json, Context context)
Converts a JSONObject object containing keys stored as key-value pairs intoa ServerRequest.
- Parameters:
json- A JSONObject object containing post data stored as key-value pairscontext- Application context.
-
onRequestQueued
void onRequestQueued()
Called when request is added to teh queue
-
getQueueWaitTime
long getQueueWaitTime()
Returns the amount of time this request was in queque
-
addProcessWaitLock
void addProcessWaitLock(ServerRequest.PROCESS_WAIT_LOCK lock)
Set the specified process wait lock for this request. This request will not be blocked fromExecution until the waiting process finishes *
- Parameters:
lock- PROCESS_WAIT_LOCK type of lock
-
removeProcessWaitLock
void removeProcessWaitLock(ServerRequest.PROCESS_WAIT_LOCK lock)
Unlock the specified lock from the request. Call this when the locked process finishes
- Parameters:
lock- PROCESS_WAIT_LOCK type of lock
-
isWaitingOnProcessToFinish
boolean isWaitingOnProcessToFinish()
Check if this request is waiting on any operation to finish before processing
-
onPreExecute
void onPreExecute()
Called on UI thread just before executing a request. Do any final updates to the request here
-
getBranchRemoteAPIVersion
ServerRequest.BRANCH_API_VERSION getBranchRemoteAPIVersion()
Returns the Branch API version
-
-
-
-