Skip to content
This repository has been archived by the owner on May 30, 2024. It is now read-only.

Add identify event, rename sendEvent to track #8

Merged
merged 2 commits into from
Jan 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/main/java/com/launchdarkly/client/IdentifyEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.launchdarkly.client;

import com.google.gson.JsonObject;

class IdentifyEvent extends Event {

IdentifyEvent(LDUser user) {
super("identify", user.getKey(), user);
}
}
20 changes: 17 additions & 3 deletions src/main/java/com/launchdarkly/client/LDClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ protected CloseableHttpClient createClient() {
* @param user the user that performed the event
* @param data a JSON object containing additional data associated with the event
*/
public void sendEvent(String eventName, LDUser user, JsonObject data) {
public void track(String eventName, LDUser user, JsonObject data) {
boolean processed = eventProcessor.sendEvent(new CustomEvent(eventName, user, data));
if (!processed) {
logger.warn("Exceeded event queue capacity. Increase capacity to avoid dropping events.");
Expand All @@ -117,11 +117,25 @@ public void sendEvent(String eventName, LDUser user, JsonObject data) {
* @param eventName the name of the event
* @param user the user that performed the event
*/
public void sendEvent(String eventName, LDUser user) {
public void track(String eventName, LDUser user) {
if (this.offline) {
return;
}
sendEvent(eventName, user, null);
track(eventName, user, null);
}

/**
* Register the user
* @param user the user to register
*/
public void identify(LDUser user) {
if (this.offline) {
return;
}
boolean processed = eventProcessor.sendEvent(new IdentifyEvent(user));
if (!processed) {
logger.warn("Exceeded event queue capacity. Increase capacity to avoid dropping events.");
}
}

private void sendFlagRequestEvent(String featureKey, LDUser user, boolean value) {
Expand Down
41 changes: 41 additions & 0 deletions src/main/java/com/launchdarkly/client/LDUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public class LDUser {
private String key;
private String secondary;
private String ip;
private String email;
private String gender;
private String firstName;
private String lastName;

private LDCountryCode country;
private Map<String, JsonElement> custom;
private static final Logger logger = LoggerFactory.getLogger(LDUser.class);
Expand All @@ -41,6 +46,10 @@ protected LDUser(Builder builder) {
this.ip = builder.ip;
this.country = builder.country;
this.secondary = builder.secondary;
this.firstName = builder.firstName;
this.lastName = builder.lastName;
this.email = builder.email;
this.gender = builder.gender;
this.custom = new HashMap<String, JsonElement>(builder.custom);
}

Expand All @@ -63,6 +72,14 @@ String getKey() {

String getSecondary() { return secondary; }

String getGender() { return gender; }

String getFirstName() { return firstName; }

String getLastName() { return lastName; }

String getEmail() { return email; }

JsonElement getCustom(String key) {
return custom.get(key);
}
Expand All @@ -84,6 +101,10 @@ public static class Builder {
private String key;
private String secondary;
private String ip;
private String firstName;
private String lastName;
private String email;
private String gender;
private LDCountryCode country;
private Map<String, JsonElement> custom;

Expand Down Expand Up @@ -157,6 +178,26 @@ public Builder country(LDCountryCode country) {
return this;
}

public Builder firstName(String firstName) {
this.firstName = firstName;
return this;
}

public Builder lastName(String lastName) {
this.lastName = lastName;
return this;
}

public Builder gender(String gender) {
this.gender = gender;
return this;
}

public Builder email(String email) {
this.email = email;
return this;
}

/**
* Add a {@link java.lang.String}-valued custom attribute
* @param k the key for the custom attribute
Expand Down