|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.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 Context |
mContext
Android application context. |
private HostInfo |
mHostInfo
HostInfo containing data about the host device and application, including its application ID. |
private java.lang.String |
mSecurityToken
Security token used to sign requests to the server and verify its responses. |
private java.lang.String |
mUserId
ID of the user for whom the requests will be made. |
private SPCurrencyServerListener |
mUserListener
SPCurrencyServerListener registered by the developer 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_KEY_TIMESTAMP
|
private static java.lang.String |
URL_PARAM_VALUE_NO_TRANSACTION
|
private static java.lang.String |
VIRTUAL_CURRENCY_SERVER_BASE_URL
|
Constructor Summary | |
---|---|
VirtualCurrencyConnector(Context context,
java.lang.String userId,
SPCurrencyServerListener listener,
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)
|
private static java.lang.String |
getCurrentUnixTimestampAsString()
Gets the current UNIX timestamp (in seconds) for the outbound requests. |
private void |
onCurrencyServerResponse(VirtualCurrencyConnector.CurrencyServerRequestAsyncTask requestTask)
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 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_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 URL_PARAM_KEY_TIMESTAMP
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 Context mContext
private java.lang.String mUserId
private HostInfo mHostInfo
HostInfo
containing data about the host device and application, including its application ID.
private java.lang.String mSecurityToken
private SPCurrencyServerListener mUserListener
SPCurrencyServerListener
registered by the developer 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 listener, HostInfo hostInfo, java.lang.String securityToken)
context
- Android application context.userId
- ID of the user for whom the requests will be made.listener
- 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.private void onCurrencyServerResponse(VirtualCurrencyConnector.CurrencyServerRequestAsyncTask requestTask)
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
.
requestTask
- 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.
private static java.lang.String getCurrentUnixTimestampAsString()
public void onSPCurrencyServerError(CurrencyServerAbstractResponse response)
SPCurrencyServerListener
. Forwards the call to the user listener.
onSPCurrencyServerError
in interface SPCurrencyServerListener
response
- Instance implementing the CurrencyServerAbstractResponse.getErrorType()
,
CurrencyServerAbstractResponse.getErrorCode()
,
CurrencyServerAbstractResponse.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 SPCurrencyServerListener
response
- 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 |