com.sponsorpay.sdk.android.publisher
Class AsyncRequest

java.lang.Object
  extended by 
      extended by com.sponsorpay.sdk.android.publisher.AsyncRequest

public class AsyncRequest
extends

Requests and loads a resource using the HTTP GET method in the background. Will call the AsyncRequest.ResultListener registered in the constructor in the same thread which triggered the request / loading process. Uses the Android AsyncTask mechanism.


Nested Class Summary
static interface AsyncRequest.ResultListener
           
 
Field Summary
static java.lang.String LOG_TAG
           
private  java.lang.String[] mCookieStrings
          Cookies returned by the server.
private  java.lang.Exception mRequestException
          Stores an exception triggered when launching the request, usually caused by network connectivity problem.
private  java.lang.String mRequestUrl
          URL for the request that will be performed in the background.
private  java.lang.String mResponseBody
          Server's response body.
private  AsyncRequest.ResultListener mResultListener
          Registered AsyncRequest.ResultListener to be notified of the request's results when they become available.
private  int mStatusCode
          Status code of the server's response.
private static java.lang.String USER_AGENT_HEADER_NAME
          Key of the User-Agent header sent on background requests.
private static java.lang.String USER_AGENT_HEADER_VALUE
          Value of the User-Agent header sent on background requests.
 
Constructor Summary
AsyncRequest(java.lang.String requestUrl, AsyncRequest.ResultListener listener)
           
 
Method Summary
 boolean didRequestTriggerException()
          Returns whether a local exception was triggered when trying to send the request.
protected  java.lang.Void doInBackground(java.lang.Void... params)
          Performs the request in the background.
 java.lang.String[] getCookieStrings()
          Gets the cookie strings returned by the server.
 int getHttpStatusCode()
          Gets the returned HTTP status code.
 java.lang.Exception getRequestTriggeredException()
          Returns the local exception triggered when trying to send the request.
 java.lang.String getResponseBody()
          Gets the response body returned by the server.
 boolean hasSucessfulStatusCode()
          Returns whether a successful HTTP status code was returned.
protected  void onPostExecute(java.lang.Void result)
          Called in the original thread when a response from the server is available.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG_TAG

public static java.lang.String LOG_TAG

USER_AGENT_HEADER_NAME

private static java.lang.String USER_AGENT_HEADER_NAME
Key of the User-Agent header sent on background requests.


USER_AGENT_HEADER_VALUE

private static java.lang.String USER_AGENT_HEADER_VALUE
Value of the User-Agent header sent on background requests.


mRequestUrl

private java.lang.String mRequestUrl
URL for the request that will be performed in the background.


mStatusCode

private int mStatusCode
Status code of the server's response.


mResponseBody

private java.lang.String mResponseBody
Server's response body.


mCookieStrings

private java.lang.String[] mCookieStrings
Cookies returned by the server.


mResultListener

private AsyncRequest.ResultListener mResultListener
Registered AsyncRequest.ResultListener to be notified of the request's results when they become available.


mRequestException

private java.lang.Exception mRequestException
Stores an exception triggered when launching the request, usually caused by network connectivity problem.

Constructor Detail

AsyncRequest

public AsyncRequest(java.lang.String requestUrl,
                    AsyncRequest.ResultListener listener)
Parameters:
requestUrl - URL to send the backgorund request to.
listener - AsyncRequest.ResultListener to be notified of the request's results when they become available.
Method Detail

doInBackground

protected java.lang.Void doInBackground(java.lang.Void... params)
Performs the request in the background. Called by the parent AsyncTask when #execute(Void...) is invoked.

Parameters:
-
Returns:

onPostExecute

protected void onPostExecute(java.lang.Void result)
Called in the original thread when a response from the server is available. Notifies the request result listener.

Parameters:
result -

getCookieStrings

public java.lang.String[] getCookieStrings()
Gets the cookie strings returned by the server.


getResponseBody

public java.lang.String getResponseBody()
Gets the response body returned by the server.


getHttpStatusCode

public int getHttpStatusCode()
Gets the returned HTTP status code.


didRequestTriggerException

public boolean didRequestTriggerException()
Returns whether a local exception was triggered when trying to send the request. An exception typically means that there was a problem connecting to the network, but checking the type of the exception returned by getRequestTriggeredException() is recommended.


getRequestTriggeredException

public java.lang.Exception getRequestTriggeredException()
Returns the local exception triggered when trying to send the request. An exception typically means that there was a problem connecting to the network, but checking the type of the returned exception can give a more accurate cause for the error.


hasSucessfulStatusCode

public boolean hasSucessfulStatusCode()
Returns whether a successful HTTP status code was returned.