All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.makitoo.internal.EventBuilder Maven / Gradle / Ivy

The newest version!
package com.makitoo.internal;

import com.makitoo.Event;
import com.makitoo.Feature;
import com.makitoo.User;
import org.json.JSONObject;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by nicolas on 24/01/17.
 */
public class EventBuilder {

    private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");

    public JSONObject createRefreshEvent(User user) {
        return createEvent(EventType.REFRESH, user);
    }

    public JSONObject createSeenEvent(Feature feature, User user) {
        return createFeatureEvent(EventType.SEEN, feature, user);
    }

    public JSONObject createSkipEvent(Feature feature, User user) {
        return createFeatureEvent(EventType.SKIP, feature, user);
    }

    public JSONObject createSuccessEvent(Feature feature, User user) {
        return createFeatureEvent(EventType.SUCCESS, feature, user);
    }

    public JSONObject createTrackEvent(Event event, User user) {
        JSONObject eventObj = createEvent(EventType.TRACK, user);
        eventObj.put("eventName", event.getName());
        if (event.getProperties() != null) {
            eventObj.put("properties", event.getProperties());
        }
        return eventObj;
    }

    private JSONObject createFeatureEvent(EventType type, Feature feature, User user) {
        JSONObject event = createEvent(type, user);
        event.put("featureName", feature.getName());
        return event;
    }

    private JSONObject createEvent(EventType type, User user) {
        JSONObject eventObj = new JSONObject();
        eventObj.put("eventType", type.toString());
        eventObj.put("date", DATE_FORMAT.format(new Date()));
        eventObj.put("installationId", user.getId());

        if (user.getContext() != null) {
            eventObj.put("context", user.getContext());
        }

        eventObj.put("lib", new JSONObject().put("type", "java").put("version", "0.0.1"));
        return eventObj;
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy