com.sponsorpay.sdk.android.publisher
Class AbstractResponse

java.lang.Object
  extended by com.sponsorpay.sdk.android.publisher.AbstractResponse
Direct Known Subclasses:
CurrencyServerAbstractResponse, UnlockedItemsResponse

public abstract class AbstractResponse
extends java.lang.Object

Encloses a basic response received from the SponsorPay API and methods to perform parsing of the returned JSON-encoded data.


Nested Class Summary
static class AbstractResponse.RequestErrorType
          Types of error condition which a request / response might result in.
 
Field Summary
protected static java.lang.String ERROR_CODE_KEY
           
protected static java.lang.String ERROR_MESSAGE_KEY
           
protected  java.lang.String mErrorCode
          Error code provided by the server.
protected  java.lang.String mErrorMessage
          Error message provided by the server.
protected  AbstractResponse.RequestErrorType mErrorType
          Type of error condition in which the request / response has resulted.
protected  java.lang.String mResponseBody
          Body of the HTTP response.
protected  java.lang.String mResponseSignature
          Server-provided signature of the response.
protected  int mResponseStatusCode
          Status code of the HTTP response.
 
Constructor Summary
AbstractResponse()
           
 
Method Summary
 java.lang.String getErrorCode()
          Gets the error code returned by the server.
 java.lang.String getErrorMessage()
          Gets the error message returned by the server.
 AbstractResponse.RequestErrorType getErrorType()
          Gets the error condition in which this request / response has resulted.
 boolean hasErrorStatusCode()
          Returns true if the response contains an HTTP status code out of the 200s.
abstract  void invokeOnErrorCallback()
          Implement to invoke the response-type-specific on error callback notification.
abstract  void invokeOnSuccessCallback()
          Implement to invoke the response-type-specific on success callback notification.
 void parseAndCallListener(java.lang.String securityToken)
          Performs a second-stage error checking, parses the response and invokes the relevant method of the listener registered with #setResponseListener(SPCurrencyServerListener).
 void parseErrorResponse()
          Parses a response containing a non-successful HTTP status code.
abstract  void parseSuccessfulResponse()
          Implement to parse a successful-HTTP-status-code containing response.
 void setResponseData(int responseStatusCode, java.lang.String responseBody, java.lang.String responseSignature)
          Sets the raw response data.
 boolean verifySignature(java.lang.String securityToken)
          Verify calculate the signature of the response with the provided security token and compare it against the server-provided response signature.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ERROR_CODE_KEY

protected static final java.lang.String ERROR_CODE_KEY
See Also:
Constant Field Values

ERROR_MESSAGE_KEY

protected static final java.lang.String ERROR_MESSAGE_KEY
See Also:
Constant Field Values

mResponseStatusCode

protected int mResponseStatusCode
Status code of the HTTP response.


mResponseBody

protected java.lang.String mResponseBody
Body of the HTTP response.


mResponseSignature

protected java.lang.String mResponseSignature
Server-provided signature of the response.


mErrorType

protected AbstractResponse.RequestErrorType mErrorType
Type of error condition in which the request / response has resulted.


mErrorCode

protected java.lang.String mErrorCode
Error code provided by the server.


mErrorMessage

protected java.lang.String mErrorMessage
Error message provided by the server.

Constructor Detail

AbstractResponse

public AbstractResponse()
Method Detail

parseSuccessfulResponse

public abstract void parseSuccessfulResponse()
Implement to parse a successful-HTTP-status-code containing response.


invokeOnSuccessCallback

public abstract void invokeOnSuccessCallback()
Implement to invoke the response-type-specific on success callback notification.


invokeOnErrorCallback

public abstract void invokeOnErrorCallback()
Implement to invoke the response-type-specific on error callback notification.


setResponseData

public void setResponseData(int responseStatusCode,
                            java.lang.String responseBody,
                            java.lang.String responseSignature)
Sets the raw response data.

Parameters:
responseStatusCode - HTTP status code returned by the server.
responseBody - Body of the HTTP response.
responseSignature - Signature of the response extracted from the response headers.

verifySignature

public boolean verifySignature(java.lang.String securityToken)
Verify calculate the signature of the response with the provided security token and compare it against the server-provided response signature.

Parameters:
securityToken - Security token which will be used to calculate the signature.
Returns:
true if the calculated signature matches the server-provided signature. false otherwise.

hasErrorStatusCode

public boolean hasErrorStatusCode()
Returns true if the response contains an HTTP status code out of the 200s.

Returns:
false if HTTP status code is between 200 and 299. True otherwise.

parseErrorResponse

public void parseErrorResponse()
Parses a response containing a non-successful HTTP status code. Tries to extract the error code and error message from the response body.


parseAndCallListener

public void parseAndCallListener(java.lang.String securityToken)
Performs a second-stage error checking, parses the response and invokes the relevant method of the listener registered with #setResponseListener(SPCurrencyServerListener).

Parameters:
securityToken - Security token used to verify the authenticity of the response.

getErrorType

public AbstractResponse.RequestErrorType getErrorType()
Gets the error condition in which this request / response has resulted.

Returns:
A AbstractResponse.RequestErrorType.

getErrorCode

public java.lang.String getErrorCode()
Gets the error code returned by the server.

Returns:

getErrorMessage

public java.lang.String getErrorMessage()
Gets the error message returned by the server.

Returns: