|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.sponsorpay.sdk.android.publisher.AbstractConnector
com.sponsorpay.sdk.android.publisher.currency.VirtualCurrencyConnector
public class VirtualCurrencyConnector
Provides services to access SponsorPay's Virtual Currency Server.
| Nested Class Summary | |
|---|---|
private class |
VirtualCurrencyConnector.CurrencyServerRequestAsyncTask
VirtualCurrencyConnector.CurrencyServerRequestAsyncTask used to perform the HTTP requests on a background thread and be notified of
its results on the calling thread. |
static class |
VirtualCurrencyConnector.RequestType
Types of requests to be sent to the Virtual Currency Server. |
| Field Summary | |
|---|---|
private static java.lang.String |
CURRENCY_DELTA_REQUEST_RESOURCE
|
private SPCurrencyServerListener |
mUserListener
SPCurrencyServerListener registered by the developer's code to be notified of the
result of requests to the Virtual Currency Server. |
private static java.lang.String |
STATE_LATEST_TRANSACTION_ID_KEY_PREFIX
Key for the String containing the latest known transaction ID, which is saved as state in the Publisher SDK preferences file (whose name is defined in SponsorPayPublisher.PREFERENCES_FILENAME). |
private static java.lang.String |
STATE_LATEST_TRANSACTION_ID_KEY_SEPARATOR
|
private static java.lang.String |
URL_PARAM_KEY_LAST_TRANSACTION_ID
|
private static java.lang.String |
URL_PARAM_VALUE_NO_TRANSACTION
|
private static java.lang.String |
VIRTUAL_CURRENCY_SERVER_PRODUCTION_BASE_URL
|
private static java.lang.String |
VIRTUAL_CURRENCY_SERVER_STAGING_BASE_URL
|
| Fields inherited from class com.sponsorpay.sdk.android.publisher.AbstractConnector |
|---|
mContext, mCustomParameters, mHostInfo, mSecurityToken, mUserId, remoteResourceUrl, URL_PARAM_KEY_TIMESTAMP |
| Constructor Summary | |
|---|---|
VirtualCurrencyConnector(Context context,
java.lang.String userId,
SPCurrencyServerListener userListener,
HostInfo hostInfo,
java.lang.String securityToken)
Initializes a new instance with the provided context and application data. |
|
| Method Summary | |
|---|---|
void |
fetchDeltaOfCoins()
Sends a request to the SponsorPay currency server to obtain the variation in amount of virtual currency for a given user since the last time this method was called. |
void |
fetchDeltaOfCoinsForCurrentUserSinceTransactionId(java.lang.String transactionId)
Sends a request to the SponsorPay currency server to obtain the variation in amount of virtual currency for the current user's transactions newer than the one whose ID is passed. |
static java.lang.String |
fetchLatestTransactionId(Context context,
java.lang.String appId,
java.lang.String userId)
Retrieves the saved latest transaction ID for a given user from the publisher state preferences file. |
private java.lang.String |
fetchLatestTransactionIdForCurrentAppAndUser()
Retrieves the saved latest known transaction ID for the current user from the publisher state preferences file. |
private static java.lang.String |
generatePreferencesLatestTransactionIdKey(java.lang.String appId,
java.lang.String userId)
|
void |
onAsyncRequestComplete(AsyncRequest request)
Called by VirtualCurrencyConnector.CurrencyServerRequestAsyncTask when a response from the currency server is
received. |
void |
onSPCurrencyDeltaReceived(CurrencyServerDeltaOfCoinsResponse response)
Implemented from SPCurrencyServerListener. |
void |
onSPCurrencyServerError(CurrencyServerAbstractResponse response)
Implemented from SPCurrencyServerListener. |
private void |
saveLatestTransactionIdForCurrentUser(java.lang.String transactionId)
Saves the provided transaction ID for the current user into the publisher state preferences file. |
| Methods inherited from class com.sponsorpay.sdk.android.publisher.AbstractConnector |
|---|
getCurrentUnixTimestampAsString, setCustomParameters |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private static final java.lang.String VIRTUAL_CURRENCY_SERVER_STAGING_BASE_URL
private static final java.lang.String VIRTUAL_CURRENCY_SERVER_PRODUCTION_BASE_URL
private static final java.lang.String CURRENCY_DELTA_REQUEST_RESOURCE
private static final java.lang.String URL_PARAM_KEY_LAST_TRANSACTION_ID
private static final java.lang.String URL_PARAM_VALUE_NO_TRANSACTION
private static final java.lang.String STATE_LATEST_TRANSACTION_ID_KEY_PREFIX
SponsorPayPublisher.PREFERENCES_FILENAME).
private static final java.lang.String STATE_LATEST_TRANSACTION_ID_KEY_SEPARATOR
private SPCurrencyServerListener mUserListener
SPCurrencyServerListener registered by the developer's code to be notified of the
result of requests to the Virtual Currency Server.
| Constructor Detail |
|---|
public VirtualCurrencyConnector(Context context,
java.lang.String userId,
SPCurrencyServerListener userListener,
HostInfo hostInfo,
java.lang.String securityToken)
context - Android application context.userId - ID of the user for whom the requests will be made.userListener - SPCurrencyServerListener registered by the developer code to be notified
of the result of requests to the Virtual Currency Server.hostInfo - HostInfo containing data about the host device and application, including
its application ID.securityToken - Security token used to sign requests to the server and verify its responses.| Method Detail |
|---|
public void fetchDeltaOfCoins()
public void fetchDeltaOfCoinsForCurrentUserSinceTransactionId(java.lang.String transactionId)
transactionId - The transaction ID used as excluded lower limit to calculate the delta of coins.public void onAsyncRequestComplete(AsyncRequest request)
VirtualCurrencyConnector.CurrencyServerRequestAsyncTask when a response from the currency server is
received. Performs the first stage of error handling and initializes the right kind of
CurrencyServerAbstractResponse.
onAsyncRequestComplete in interface AsyncRequest.AsyncRequestResultListenerrequestTask - The calling VirtualCurrencyConnector.CurrencyServerRequestAsyncTask with the response data.private void saveLatestTransactionIdForCurrentUser(java.lang.String transactionId)
transactionId - The transaction ID to save.
private static java.lang.String generatePreferencesLatestTransactionIdKey(java.lang.String appId,
java.lang.String userId)
private java.lang.String fetchLatestTransactionIdForCurrentAppAndUser()
public static java.lang.String fetchLatestTransactionId(Context context,
java.lang.String appId,
java.lang.String userId)
context - Android application context.userId - ID of the user related to which the fetched transaction ID must belong.
public void onSPCurrencyServerError(CurrencyServerAbstractResponse response)
SPCurrencyServerListener. Forwards the call to the user listener.
onSPCurrencyServerError in interface SPCurrencyServerListenerresponse - Instance implementing the AbstractResponse.getErrorType(),
AbstractResponse.getErrorCode(),
AbstractResponse.getErrorMessage() and methods.public void onSPCurrencyDeltaReceived(CurrencyServerDeltaOfCoinsResponse response)
SPCurrencyServerListener. Saves the returned latest transaction id
and forwards the call to the user listener.
onSPCurrencyDeltaReceived in interface SPCurrencyServerListenerresponse - A response instance that implements the CurrencyServerDeltaOfCoinsResponse.getDeltaOfCoins()
and CurrencyServerDeltaOfCoinsResponse.getLatestTransactionId() methods.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||