Android Open Source - mobile-connector-sdk-android X M L A P I Manager






From Project

Back to project page mobile-connector-sdk-android.

License

The source code is released under:

Apache License

If you think the Android project mobile-connector-sdk-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.silverpop.engage;
// w ww  .j  a  v a  2s.com
import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;

import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.silverpop.engage.domain.XMLAPI;
import com.silverpop.engage.network.XMLAPIClient;
import com.silverpop.engage.response.EngageResponseXML;


/**
 * Created by jeremydyer on 5/21/14.
 */
public class XMLAPIManager {

    private static final String TAG = XMLAPIManager.class.getName();

    private Context context;
    private XMLAPIClient xmlapiClient;

    private static XMLAPIManager xmlapiManager = null;

    private XMLAPIManager(Context context, String clientId, String clientSecret, String refreshToken, String host) {
        setContext(context);
        xmlapiClient = XMLAPIClient.init(context, clientId, clientSecret, refreshToken, host);
    }

    public static XMLAPIManager initialize(Context context, String clientId, String clientSecret, String refreshToken, String host) {
        if (xmlapiManager == null) {
            xmlapiManager = new XMLAPIManager(context, clientId, clientSecret, refreshToken, host);
        }
        return xmlapiManager;
    }

    public static XMLAPIManager get() {
        if (xmlapiManager == null) {
            Log.e(TAG, "EngageSDK - You have not yet initialized your XMLAPIManager instance! " +
                    "A null XMLAPIManager instance will be returned!");
            return null;
        } else {
            return xmlapiManager;
        }
    }

    /**
     * Post an XMLAPI request to Engage
     *
     * @param api
     *      XMLAPI operation desired.
     *
     * @param successTask
     *      AsyncTask to execute on successful result.
     *
     * @param failureTask
     *      AsyncTask to execute on failure
     */
    public void postXMLAPI(XMLAPI api,
                           AsyncTask<EngageResponseXML, Void, Object> successTask,
                           AsyncTask<VolleyError, Void, Object> failureTask) {
        Response.Listener<String> successListener = successListenerForXMLAPI(api, successTask);
        Response.ErrorListener errorListener = null;
        xmlapiClient.postResource(api, successListener, errorListener);
    }

    /**
     * Create an anonymous user for the specified listId(database identifier)
     *
     * @param listId
     *      Database identifier.
     *
     * @param successTask
     *      AsyncTask to execute on successful result.
     *
     * @param failureTask
     *      AsyncTask to execute on failure
     */
    public void createAnonymousUserList(String listId,
                                        AsyncTask<EngageResponseXML, Void, Object> successTask,
                                        AsyncTask<VolleyError, Void, Object> failureTask) {
        XMLAPI createAnonymous = XMLAPI.addRecipientAnonymousToList(listId);
        postXMLAPI(createAnonymous, successTask, failureTask);
    }


    public void updateAnonymousUserToKnownUser(String listId, AsyncTask<EngageResponseXML, Void, Object> successTask,
                                               AsyncTask<VolleyError, Void, Object> failureTask) {
        XMLAPI createAnonymous = XMLAPI.addRecipientAnonymousToList(listId);
        postXMLAPI(createAnonymous, successTask, failureTask);
    }

    /**
     * Handles the successful completion of the UBF post
     *
     * @return
     */
    private Response.Listener<String> successListenerForXMLAPI(final XMLAPI api,
                                                                  final AsyncTask<EngageResponseXML, Void, Object> successTask) {
        return new Response.Listener<String>() {
            public void onResponse(String response) {

                //Perform the EngageSDK internal logic before passing processing off to user defined AsyncTask.
                EngageResponseXML responseXML = new EngageResponseXML(response);

                //If null the user doesn't want anything special to happen.
                if (successTask != null) {
                    successTask.execute(responseXML);
                }
            }
        };
    }


    /**
     * Handles the failure of a UBF event post.
     *
     * @return
     */
    private Response.ErrorListener errorListenerForXMLAPI(final XMLAPI api, final AsyncTask<VolleyError, Void, Object> failureTask) {
        return new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Log.e(TAG, error.getMessage());

                //Call the SDK user defined method.
                if (failureTask != null) {
                    failureTask.execute(error);
                }
            }
        };
    }

    public Context getContext() {
        return context;
    }

    public void setContext(Context context) {
        this.context = context;
    }
}




Java Source Code List

com.silverpop.engage.EngageApplication.java
com.silverpop.engage.UBFManager.java
com.silverpop.engage.XMLAPIManager.java
com.silverpop.engage.augmentation.UBFAugmentationServiceImpl.java
com.silverpop.engage.augmentation.UBFAugmentationService.java
com.silverpop.engage.augmentation.plugin.UBFAddressAugmentationPlugin.java
com.silverpop.engage.augmentation.plugin.UBFAugmentationPlugin.java
com.silverpop.engage.augmentation.plugin.UBFCoordinatesAugmentationPlugin.java
com.silverpop.engage.augmentation.plugin.UBFLocationNameAugmentationPlugin.java
com.silverpop.engage.config.EngageConfigManagerTests.java
com.silverpop.engage.config.EngageConfigManager.java
com.silverpop.engage.config.EngageConfigTest.java
com.silverpop.engage.config.EngageConfig.java
com.silverpop.engage.deeplinking.EngageDeepLinkManager.java
com.silverpop.engage.demo.engagetest.Application.java
com.silverpop.engage.demo.engagetest.EngageNotificationReceiver.java
com.silverpop.engage.demo.engagetest.MainActivity.java
com.silverpop.engage.demo.engagetest.PushReceiver.java
com.silverpop.engage.demo.engagetest.fragment.EngageConfigFragment.java
com.silverpop.engage.demo.engagetest.fragment.UBFAPIFragment.java
com.silverpop.engage.demo.engagetest.fragment.XMLAPIFragment.java
com.silverpop.engage.domain.EngageEvent.java
com.silverpop.engage.domain.JSONable.java
com.silverpop.engage.domain.UBFTests.java
com.silverpop.engage.domain.UBF.java
com.silverpop.engage.domain.XMLAPIEnum.java
com.silverpop.engage.domain.XMLAPITest.java
com.silverpop.engage.domain.XMLAPI.java
com.silverpop.engage.exception.XMLResponseParseException.java
com.silverpop.engage.location.manager.EngageLocationManager.java
com.silverpop.engage.location.manager.plugin.EngageLocationManagerDefault.java
com.silverpop.engage.location.receiver.EngageLocationReceiver.java
com.silverpop.engage.location.receiver.plugin.EngageLocationReceiverBase.java
com.silverpop.engage.location.receiver.plugin.EngageLocationReceiverGeocode.java
com.silverpop.engage.location.receiver.plugin.EngageLocationReceiverHardcodeTest.java
com.silverpop.engage.network.Credential.java
com.silverpop.engage.network.EngageClient.java
com.silverpop.engage.network.RequestCacheWrapper.java
com.silverpop.engage.network.UBFClient.java
com.silverpop.engage.network.XMLAPIClient.java
com.silverpop.engage.response.EngageResponseXMLTests.java
com.silverpop.engage.response.EngageResponseXML.java
com.silverpop.engage.response.XMLAPIResponseNode.java
com.silverpop.engage.store.EngageLocalEventStoreTest.java
com.silverpop.engage.store.EngageLocalEventStore.java
com.silverpop.engage.store.EngageSQLiteHelper.java
com.silverpop.engage.util.EngageExpirationParserTests.java
com.silverpop.engage.util.EngageExpirationParser.java
com.silverpop.engage.util.TimedAsyncTask.java