com.sponsorpay.sdk.android.advertiser
Class SponsorPayAdvertiser

java.lang.Object
  extended by com.sponsorpay.sdk.android.advertiser.SponsorPayAdvertiser
All Implemented Interfaces:
AdvertiserCallbackSender.APIResultListener

public class SponsorPayAdvertiser
extends java.lang.Object
implements AdvertiserCallbackSender.APIResultListener

Provides convenience calls to run the Advertiser callback request. Manages the state of the SDK determining whether a successful response to the callback request has been already received since the application was installed in the host device.

It's implemented as a singleton, and its public methods are static.


Field Summary
private  AdvertiserCallbackSender mAPICaller
          AdvertiserCallbackSender used to call the Advertiser API asynchronously.
private  Context mContext
          Host app's Android application context.
private  HostInfo mHostInfo
          AdvertiserHostInfo used to collect data related to the host device and application.
private static SponsorPayAdvertiser mInstance
          Singleton instance.
private  SponsorPayAdvertiserState mPersistedState
          Keep track of the persisted state of the Advertiser part of the SDK
private static java.util.Map<java.lang.String,java.lang.String> sCustomParameters
          Map of custom key/values to add to the parameters on the requests to the REST API.
private static boolean sShouldUseStagingUrls
           
 
Constructor Summary
private SponsorPayAdvertiser(Context context)
          Constructor.
 
Method Summary
static void clearCustomParameters()
          Clears the map of custom key/values to add to the parameters on the requests to the REST API.
private static java.util.HashMap<java.lang.String,java.lang.String> getCustomParameters(java.util.Map<java.lang.String,java.lang.String> passedParameters)
          Returns the map of custom key/values to add to the parameters on the requests to the REST API.
 void onAPIResponse(boolean wasSuccessful)
          This method is invoked when a response for the advertiser callback is received.
static void register(Context context)
          Triggers the Advertiser callback.
static void register(Context context, java.lang.String overrideAppId)
          Triggers the Advertiser callback.
static void register(Context context, java.lang.String overrideAppId, java.util.Map<java.lang.String,java.lang.String> customParams)
          Triggers the Advertiser callback.
private  void register(java.lang.String overrideAppId, java.util.Map<java.lang.String,java.lang.String> customParams)
          This method does the actual registration at the SponsorPay backend, performing the advertiser callback, and including in it a parameter to signal if a successful response has been received yet.
static void registerWithDelay(Context context, int delayMin)
          Triggers the Advertiser callback after the specified delay has passed.
static void registerWithDelay(Context context, int delayMin, java.lang.String overrideAppId)
          Triggers the Advertiser callback after the specified delay has passed.
static void registerWithDelay(Context context, int delayMin, java.lang.String overrideAppId, java.util.Map<java.lang.String,java.lang.String> customParams)
          Triggers the Advertiser callback after the specified delay has passed.
static void setCustomParameters(java.util.Map<java.lang.String,java.lang.String> params)
          Sets a map of custom key/values to add to the parameters on the requests to the REST API.
static void setCustomParameters(java.lang.String[] keys, java.lang.String[] values)
          Sets a map of custom key/values to add to the parameters on the requests to the REST API.
static void setShouldUseStagingUrls(boolean value)
           
static boolean shouldUseStagingUrls()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sCustomParameters

private static java.util.Map<java.lang.String,java.lang.String> sCustomParameters
Map of custom key/values to add to the parameters on the requests to the REST API.


sShouldUseStagingUrls

private static boolean sShouldUseStagingUrls

mHostInfo

private HostInfo mHostInfo
AdvertiserHostInfo used to collect data related to the host device and application.


mAPICaller

private AdvertiserCallbackSender mAPICaller
AdvertiserCallbackSender used to call the Advertiser API asynchronously.


mContext

private Context mContext
Host app's Android application context.


mPersistedState

private SponsorPayAdvertiserState mPersistedState
Keep track of the persisted state of the Advertiser part of the SDK


mInstance

private static SponsorPayAdvertiser mInstance
Singleton instance.

Constructor Detail

SponsorPayAdvertiser

private SponsorPayAdvertiser(Context context)
Constructor. Stores the received application context and loads up the shared preferences.

Parameters:
context - The host application context.
Method Detail

setShouldUseStagingUrls

public static void setShouldUseStagingUrls(boolean value)

shouldUseStagingUrls

public static boolean shouldUseStagingUrls()

setCustomParameters

public static void setCustomParameters(java.util.Map<java.lang.String,java.lang.String> params)
Sets a map of custom key/values to add to the parameters on the requests to the REST API.

Parameters:
params -

setCustomParameters

public static void setCustomParameters(java.lang.String[] keys,
                                       java.lang.String[] values)
Sets a map of custom key/values to add to the parameters on the requests to the REST API.

Parameters:
keys -
values -

clearCustomParameters

public static void clearCustomParameters()
Clears the map of custom key/values to add to the parameters on the requests to the REST API.


getCustomParameters

private static java.util.HashMap<java.lang.String,java.lang.String> getCustomParameters(java.util.Map<java.lang.String,java.lang.String> passedParameters)
Returns the map of custom key/values to add to the parameters on the requests to the REST API.

Parameters:
-
Returns:
If passedParameters is not null, a copy of it is returned. Otherwise if the parameters set with setCustomParameters(Map) or setCustomParameters(String[], String[]) are not null, a copy of that map is returned. Otherwise null is returned.

register

public static void register(Context context)
Triggers the Advertiser callback. Will try to retrieve the Application ID from the value defined in the host application's Android Manifest XML file.

Parameters:
context - Host application context.

registerWithDelay

public static void registerWithDelay(Context context,
                                     int delayMin)
Triggers the Advertiser callback after the specified delay has passed. Will retrieve the App ID from the value defined in the host application's Android Manifest XML file.

Parameters:
context - Host application context.
delayMin - The delay in minutes for triggering the Advertiser callback.

registerWithDelay

public static void registerWithDelay(Context context,
                                     int delayMin,
                                     java.lang.String overrideAppId)
Triggers the Advertiser callback after the specified delay has passed. Will use the provided App ID instead of trying to retrieve the one defined in the host application's manifest.

Parameters:
context - Host application context.
delayMin - The delay in minutes for triggering the Advertiser callback.
overrideAppId - The App ID to use.

registerWithDelay

public static void registerWithDelay(Context context,
                                     int delayMin,
                                     java.lang.String overrideAppId,
                                     java.util.Map<java.lang.String,java.lang.String> customParams)
Triggers the Advertiser callback after the specified delay has passed. Will use the provided App ID instead of trying to retrieve the one defined in the host application's manifest.

Parameters:
context - Host application context.
delayMin - The delay in minutes for triggering the Advertiser callback.
overrideAppId - The App ID to use.
customParams - Map of custom key/values to add to the parameters on the requests to the REST API.

register

public static void register(Context context,
                            java.lang.String overrideAppId)
Triggers the Advertiser callback. If passed a non-null and non-empty Application ID, it will be used. Otherwise the Application ID will be retrieved from the value defined in the host application's Android Manifest XML file.

Parameters:
context - Host application context.
overrideAppId - The App ID to use.

register

public static void register(Context context,
                            java.lang.String overrideAppId,
                            java.util.Map<java.lang.String,java.lang.String> customParams)
Triggers the Advertiser callback. If passed a non-null and non-empty Application ID, it will be used. Otherwise the Application ID will be retrieved from the value defined in the host application's Android Manifest XML file.

Parameters:
context - Host application context.
overrideAppId - The App ID to use.
customParams - A map of extra key/value pairs to add to the request URL.

register

private void register(java.lang.String overrideAppId,
                      java.util.Map<java.lang.String,java.lang.String> customParams)
This method does the actual registration at the SponsorPay backend, performing the advertiser callback, and including in it a parameter to signal if a successful response has been received yet.

Parameters:
overrideAppId - If left empty (""), will use the App ID value from the application manifest xml file. Otherwise, will use the specified App ID.
customParams - A map of extra key/value pairs to add to the request URL.

onAPIResponse

public void onAPIResponse(boolean wasSuccessful)
This method is invoked when a response for the advertiser callback is received.

Specified by:
onAPIResponse in interface AdvertiserCallbackSender.APIResultListener
Parameters:
wasSuccessful - Status flag to indicate if Advertiser API has been contacted successfully.