com.sponsorpay.sdk.android.publisher
Class OfferBannerRequest

java.lang.Object
  extended by com.sponsorpay.sdk.android.publisher.OfferBannerRequest
All Implemented Interfaces:
AsyncRequest.ResultListener

public class OfferBannerRequest
extends java.lang.Object
implements AsyncRequest.ResultListener

Requests a new offer banner to the SponsorPay server and notifies the registered SPOfferBannerListener of the result of the request.


Field Summary
private  AsyncRequest mAsyncRequest
          AsyncRequest used to send the request in the background.
private  java.lang.String mBaseDomain
          Base domain of the request URL which will be passed to the WebView which displays the returned banner to load associated resources (like images).
private  java.lang.String mBaseUrl
          BaseUrl of the resource from which the ad will be requested.
private  Context mContext
          Android application context.
private  java.lang.String mCurrencyName
          Currency Name to be sent in the request.
private  HostInfo mHostInfo
          HostInfo instance containing the Application ID and data about the device.
private  SPOfferBannerListener mListener
          Registered SPOfferBannerListener which will be notified of the result of the request.
private  OfferBanner.AdShape mOfferBannerAdShape
          OfferBanner.AdShape whose description will be sent to the server in the request.
private  java.lang.String mUserId
          User ID to include in the request.
private static java.lang.String OFFERBANNER_PRODUCTION_BASE_URL
           
private static java.lang.String OFFERBANNER_PRODUCTION_DOMAIN
           
private static java.lang.String OFFERBANNER_STAGING_BASE_URL
           
private static java.lang.String OFFERBANNER_STAGING_DOMAIN
           
private static java.lang.String STATE_OFFSET_COUNT_KEY
           
private static java.lang.String URL_PARAM_OFFERBANNER_KEY
           
 
Constructor Summary
OfferBannerRequest(Context context, java.lang.String userId, HostInfo hostInfo, SPOfferBannerListener listener, OfferBanner.AdShape offerBannerAdShape, java.lang.String currencyName)
          Initializes a new instance and sends the request immediately.
 
Method Summary
private  int fetchPersistedBannerOffset()
          Fetches the persisted offset sent on the banner requests.
private  int fetchPersistedBannerOffset(SharedPreferences prefs)
          Fetches the persisted offset sent on the banner requests.
private  SharedPreferences fetchSharedPreferences()
          Returns the shared preferences file used by the Publisher functionality of the SponsorPay SDK.
 int getHttpStatusCode()
          Gets the HTTP status code returned as a result of this request.
 java.lang.Exception getRequestException()
          Returns the local exception triggered when trying to send the request.
private  void incrementPersistedBannerOffset()
          Increments and persists the banner offset sent on every request to get different banners in a round-robin fashion.
 void onAsyncRequestComplete(AsyncRequest request)
          Called by the mAsyncRequest instance when the background request's results are available.
private  void requestOfferBanner()
          Generates the request URL and sends it on the background.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OFFERBANNER_PRODUCTION_BASE_URL

private static final java.lang.String OFFERBANNER_PRODUCTION_BASE_URL
See Also:
Constant Field Values

OFFERBANNER_STAGING_BASE_URL

private static final java.lang.String OFFERBANNER_STAGING_BASE_URL
See Also:
Constant Field Values

OFFERBANNER_PRODUCTION_DOMAIN

private static final java.lang.String OFFERBANNER_PRODUCTION_DOMAIN
See Also:
Constant Field Values

OFFERBANNER_STAGING_DOMAIN

private static final java.lang.String OFFERBANNER_STAGING_DOMAIN
See Also:
Constant Field Values

URL_PARAM_OFFERBANNER_KEY

private static final java.lang.String URL_PARAM_OFFERBANNER_KEY
See Also:
Constant Field Values

STATE_OFFSET_COUNT_KEY

private static final java.lang.String STATE_OFFSET_COUNT_KEY
See Also:
Constant Field Values

mContext

private Context mContext
Android application context.


mListener

private SPOfferBannerListener mListener
Registered SPOfferBannerListener which will be notified of the result of the request.


mUserId

private java.lang.String mUserId
User ID to include in the request.


mOfferBannerAdShape

private OfferBanner.AdShape mOfferBannerAdShape
OfferBanner.AdShape whose description will be sent to the server in the request.


mHostInfo

private HostInfo mHostInfo
HostInfo instance containing the Application ID and data about the device.


mBaseUrl

private java.lang.String mBaseUrl
BaseUrl of the resource from which the ad will be requested.


mBaseDomain

private java.lang.String mBaseDomain
Base domain of the request URL which will be passed to the WebView which displays the returned banner to load associated resources (like images).


mCurrencyName

private java.lang.String mCurrencyName
Currency Name to be sent in the request.


mAsyncRequest

private AsyncRequest mAsyncRequest
AsyncRequest used to send the request in the background.

Constructor Detail

OfferBannerRequest

public OfferBannerRequest(Context context,
                          java.lang.String userId,
                          HostInfo hostInfo,
                          SPOfferBannerListener listener,
                          OfferBanner.AdShape offerBannerAdShape,
                          java.lang.String currencyName)
Initializes a new instance and sends the request immediately.

Parameters:
context - Android application context.
userId - ID of the user on whose behalf the banner will be requested.
hostInfo - HostInfo instance containing the Application ID and data about the device.
listener - SPOfferBannerListener which will be notified of the result of the request.
offerBannerAdShape - OfferBanner.AdShape of the requested banner.
currencyName - Currency Name to be sent in the request.
Method Detail

requestOfferBanner

private void requestOfferBanner()
Generates the request URL and sends it on the background.


onAsyncRequestComplete

public void onAsyncRequestComplete(AsyncRequest request)
Called by the mAsyncRequest instance when the background request's results are available. Will notify the registered SPOfferBannerListener.

Specified by:
onAsyncRequestComplete in interface AsyncRequest.ResultListener

incrementPersistedBannerOffset

private void incrementPersistedBannerOffset()
Increments and persists the banner offset sent on every request to get different banners in a round-robin fashion.


fetchSharedPreferences

private SharedPreferences fetchSharedPreferences()
Returns the shared preferences file used by the Publisher functionality of the SponsorPay SDK.


fetchPersistedBannerOffset

private int fetchPersistedBannerOffset()
Fetches the persisted offset sent on the banner requests.


fetchPersistedBannerOffset

private int fetchPersistedBannerOffset(SharedPreferences prefs)
Fetches the persisted offset sent on the banner requests.

Parameters:
prefs - The SharedPreferences instance which will be used to fetch this value.
Returns:
The persisted offset value.

getHttpStatusCode

public int getHttpStatusCode()
Gets the HTTP status code returned as a result of this request.


getRequestException

public java.lang.Exception getRequestException()
Returns the local exception triggered 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 exception can give a more accurate cause for the error.