com.sponsorpay.sdk.android.publisher
Class AsyncRequest

java.lang.Object
  extended by 
      extended by com.sponsorpay.sdk.android.publisher.AsyncRequest
Direct Known Subclasses:
VirtualCurrencyConnector.CurrencyServerRequestAsyncTask

public class AsyncRequest
extends

Requests and loads a resource using the HTTP GET method in the background. Will call the AsyncRequest.AsyncRequestResultListener 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.AsyncRequestResultListener
           
 
Field Summary
private static java.lang.String ACCEPT_LANGUAGE_HEADER_NAME
          Key of the Accept-Language header sent on background requests.
static java.lang.String LOG_TAG
           
private  java.lang.String[] mCookieStrings
          Cookies returned by the server.
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  java.lang.String mResponseSignature
          Server's response signature, extracted of the "X-Sponsorpay-Response-Signature" header.
private  AsyncRequest.AsyncRequestResultListener mResultListener
          Registered AsyncRequest.AsyncRequestResultListener to be notified of the request's results when they become available.
private  int mStatusCode
          Status code of the server's response.
private  java.lang.Throwable mThrownRequestError
          Stores an error thrown when launching the request, usually caused by a network connectivity problem.
static boolean shouldLogVerbosely
           
private static java.lang.String SIGNATURE_HEADER
          Custom SponsorPay HTTP header containing the signature of the 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.AsyncRequestResultListener listener)
           
 
Method Summary
 boolean didRequestThrowError()
          Returns the local error thrown 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.Throwable getRequestThrownError()
          Returns the local error thrown when trying to send the request.
 java.lang.String getResponseBody()
          Gets the response body returned by the server.
 java.lang.String getResponseSignature()
           
 boolean hasCookies()
           
 boolean hasSucessfulStatusCode()
          Returns whether a successful HTTP status code was returned.
private  java.lang.String makeAcceptLanguageHeaderValue()
          Returns a value for the HTTP Accept-Language header based on the current locale set up for the device.
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

shouldLogVerbosely

public static boolean shouldLogVerbosely

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.


ACCEPT_LANGUAGE_HEADER_NAME

private static java.lang.String ACCEPT_LANGUAGE_HEADER_NAME
Key of the Accept-Language 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.


SIGNATURE_HEADER

private static final java.lang.String SIGNATURE_HEADER
Custom SponsorPay HTTP header containing the signature of the response.

See Also:
Constant Field Values

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.


mResponseSignature

private java.lang.String mResponseSignature
Server's response signature, extracted of the "X-Sponsorpay-Response-Signature" header.


mCookieStrings

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


mResultListener

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


mThrownRequestError

private java.lang.Throwable mThrownRequestError
Stores an error thrown when launching the request, usually caused by a network connectivity problem.

Constructor Detail

AsyncRequest

public AsyncRequest(java.lang.String requestUrl,
                    AsyncRequest.AsyncRequestResultListener listener)
Parameters:
requestUrl - URL to send the backgorund request to.
listener - AsyncRequest.AsyncRequestResultListener 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:

makeAcceptLanguageHeaderValue

private java.lang.String makeAcceptLanguageHeaderValue()
Returns a value for the HTTP Accept-Language header based on the current locale set up for the device.


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.


hasCookies

public boolean hasCookies()

getResponseBody

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


getHttpStatusCode

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


getResponseSignature

public java.lang.String getResponseSignature()

didRequestThrowError

public boolean didRequestThrowError()
Returns the local error thrown 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 error can give a more accurate cause for the error.


getRequestThrownError

public java.lang.Throwable getRequestThrownError()
Returns the local error thrown 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 error can give a more accurate cause for the error.


hasSucessfulStatusCode

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