Skip to content

Commit

Permalink
BaseEvent implementation
Browse files Browse the repository at this point in the history
	- Create a new class, BaseEvent, which is now the parent class of MPEvent and CommerceEvent. MParticle.logEvent() is consolidated into a single method that accepts a BaseEvent argument, and does not result in any breaking API changes
	- Update Optimizely submodule
  • Loading branch information
willpassidomo committed Oct 7, 2019
1 parent b4dcd86 commit 74a34d7
Show file tree
Hide file tree
Showing 43 changed files with 547 additions and 306 deletions.
4 changes: 3 additions & 1 deletion android-core/proguard.pro
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@
-keep class com.mparticle.ReferrerReceiver { *; }
-keep class com.mparticle.kits.ForeseeKit { *; }
-keep class com.mparticle.UserAttributeListener { *; }
-keep class com.mparticle.BaseEvent { *; }
-keep class com.mparticle.BaseEvent$Type { *; }
-keep class com.mparticle.BaseEvent$MessageType { *; }

-keep class com.mparticle.consent.ConsentState { *; }
-keep class com.mparticle.consent.ConsentState$Builder { *; }
Expand All @@ -131,7 +134,6 @@
-keep class com.mparticle.internal.Logger$* { *; }
-keep class com.mparticle.internal.BackgroundTaskHandler { *; }


-keep class com.mparticle.identity.IdentityApi { *; }
-keep class com.mparticle.identity.IdentityApiRequest { *; }
-keep class com.mparticle.identity.IdentityApiRequest$* { *; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void onApiCalled(@NonNull String apiName, @NonNull List<Object> objects,

//invoke an API method from an external package ;)
MParticle mParticle = MParticle.getInstance();
Method method = mParticle.getClass().getMethod("logEvent", MPEvent.class);
Method method = mParticle.getClass().getMethod("logEvent", BaseEvent.class);
try {
method.invoke(mParticle, mpEvent);
} catch (Exception ignore) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ void assertEventEquals(MPEvent mpEvent, JSONObject jsonObject) throws JSONExcept
assertTrue(mpEvent.getEventType().toString().equals(jsonObject.getString("et")));
}

Map<String, String> customAttributesTarget = mpEvent.getInfo() == null ? new HashMap<String, String>() : mpEvent.getInfo();
Map<String, String> customAttributesTarget = mpEvent.getCustomAttributes() == null ? new HashMap<String, String>() : mpEvent.getCustomAttributes();
JSONObject customAttributes = jsonObject.optJSONObject("attrs");
if (customAttributes != null) {
Iterator<String> keysIterator = customAttributes.keys();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ public void testUpdateSessionInstallReferrer() throws Exception {
cursor.close();
}
}
Assert.fail("Failed to find updated app info object.");
Assert.fail("Failed to find updated app customAttributes object.");
}
}
106 changes: 106 additions & 0 deletions android-core/src/main/java/com/mparticle/BaseEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package com.mparticle;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.mparticle.internal.Logger;
import com.mparticle.internal.MPUtility;

import org.json.JSONArray;

import java.util.List;
import java.util.Map;

public class BaseEvent {

private MessageType mType;
private Map<String, List<String>> mCustomFlags;
private Map<String, String> mCustomAttributes;

protected BaseEvent(MessageType type) {
mType = type;
}

@NonNull
public MessageType getType() {
return mType;
}

protected void setType(MessageType type) {
this.mType = type;
}

/**
* Retrieve the custom flags set on this event. Custom Flags are used to send data or trigger behavior
* to individual 3rd-party services that you have enabled for your app. By default, flags are not forwarded
* to any providers.
*
* @return returns the map of custom flags, or null if none are set
*/
@Nullable
public Map<String, List<String>> getCustomFlags() {
return mCustomFlags;
}


protected void setCustomFlags(@Nullable Map<String, List<String>> flags) {
if (flags != null && MPUtility.containsNullKey(flags)) {
Logger.warning(String.format("disregarding \"MPEvent.customFlag\" value of %s. Key was found to be null", new JSONArray(flags.get(null))));
flags.remove(null);
}
this.mCustomFlags = flags;
}

/**
* Retrieve the Map of custom attributes of the event.
*
* @return returns a Map of custom attributes, or null if no custom attributes are set.
*/
@Nullable
public Map<String, String> getCustomAttributes() {
return mCustomAttributes;
}

protected void setCustomAttributes(@Nullable Map<String, String> customAttributes) {
if (customAttributes != null && MPUtility.containsNullKey(customAttributes)) {
Logger.warning(String.format("disregarding \"Event.customFlag\" value of \"%s\". Key was found to be null", customAttributes.get(null)));
customAttributes.remove(null);
}
this.mCustomAttributes = customAttributes;
}

public interface MessageType {
String getMessageType();
}

public enum Type implements MessageType {
SESSION_START("ss"),
SESSION_END("se"),
EVENT("e"),
SCREEN_VIEW("v"),
COMMERCE_EVENT("cm"),
OPT_OUT("o"),
ERROR("x"),
PUSH_REGISTRATION("pr"),
REQUEST_HEADER("h"),
FIRST_RUN("fr"),
APP_STATE_TRANSITION("ast"),
PUSH_RECEIVED("pm"),
BREADCRUMB("bc"),
NETWORK_PERFORMNACE("npe"),
PROFILE("pro"),
USER_ATTRIBUTE_CHANGE("uac"),
USER_IDENTITY_CHANGE("uic");

private String messageType;

Type(String messageType) {
this.messageType = messageType;
}

public String getMessageType() {
return messageType;
}
}

}
Loading

0 comments on commit 74a34d7

Please sign in to comment.