Android Open Source - tapad-android-sdk Event Resource






From Project

Back to project page tapad-android-sdk.

License

The source code is released under:

MIT License

If you think the Android project tapad-android-sdk 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.tapad.tracking;
/*  w ww . j av a2  s . c  o m*/
import com.tapad.util.HttpClientUtil;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * Represents the resource interface to the event registration service.
 * Does the actual registration work using a HTTP Client.
 * <p/>
 * Single-threaded access only.
 */
class EventResource {
    private static final String RESOURCE_URL = "https://analytics.tapad.com/app/event";
    private static final String PARAM_APP_ID = "app_id";
    private static final String PARAM_DEVICE_ID = "device_id";
    private static final String PARAM_TYPED_DEVICE_ID = "typed_device_id";
    private static final String PARAM_EVENT_ID = "action_id";
    private static final String PARAM_EXTRA_PARAMS = "extra_params";

    private DefaultHttpClient client;

    private String appId;
    private DeviceIdentifier deviceId;

    /**
     * Constructs a new EventResource instance.
     *
     * @param appId    the application id to use
     * @param deviceId the device id to use
     */
    EventResource(String appId, DeviceIdentifier deviceId, String userAgent) {
        this.appId = appId;
        this.deviceId = deviceId;
        this.client = HttpClientUtil.createClient(userAgent);
    }

    protected void post(Event e) throws IOException {
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair(PARAM_APP_ID, appId));
        if (deviceId.isOptedOut() || deviceId.getTypedIds() == null) {
            params.add(new BasicNameValuePair(PARAM_DEVICE_ID, deviceId.get()));
        }
        else {
            params.add(new BasicNameValuePair(PARAM_TYPED_DEVICE_ID, deviceId.getTypedIds()));
        }
        params.add(new BasicNameValuePair(PARAM_EVENT_ID, e.getId()));
        if (e.getExtraParameters() != null)
            params.add(new BasicNameValuePair(PARAM_EXTRA_PARAMS, e.getExtraParameters()));
        String query = URLEncodedUtils.format(params, "UTF-8");

        String uri = RESOURCE_URL + "?" + query;
        HttpResponse response = client.execute(new HttpPost(uri));
        response.getEntity().consumeContent();
    }
}




Java Source Code List

com.tapad.adserving.AdRequestDispatcher.java
com.tapad.adserving.AdRequest.java
com.tapad.adserving.AdResource.java
com.tapad.adserving.AdResponse.java
com.tapad.adserving.AdServingServiceImpl.java
com.tapad.adserving.AdServingService.java
com.tapad.adserving.AdServing.java
com.tapad.adserving.AdSize.java
com.tapad.adserving.ui.AdView.java
com.tapad.sample.AdViewActivity.java
com.tapad.sample.MainActivity.java
com.tapad.sample.MainApplication.java
com.tapad.sample.ManualMarkupActivity.java
com.tapad.sample.SampleConstants.java
com.tapad.tracking.DeviceIdentifier.java
com.tapad.tracking.DeviceInfo.java
com.tapad.tracking.EventDispatcher.java
com.tapad.tracking.EventResource.java
com.tapad.tracking.Event.java
com.tapad.tracking.InstallReferrerReceiver.java
com.tapad.tracking.TrackingServiceImpl.java
com.tapad.tracking.TrackingService.java
com.tapad.tracking.Tracking.java
com.tapad.tracking.deviceidentification.AndroidId.java
com.tapad.tracking.deviceidentification.IdentifierSourceAggregator.java
com.tapad.tracking.deviceidentification.IdentifierSource.java
com.tapad.tracking.deviceidentification.PhoneId.java
com.tapad.tracking.deviceidentification.TypedIdentifier.java
com.tapad.tracking.deviceidentification.WifiMac.java
com.tapad.util.DigestUtil.java
com.tapad.util.HttpClientUtil.java
com.tapad.util.IoUtil.java
com.tapad.util.Logging.java