Skip to content

Commit 3fe68f7

Browse files
committed
added in userId for each api call instead of email
1 parent 1bb5492 commit 3fe68f7

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

iterableapi/src/main/java/com/iterable/iterableapi/IterableApi.java

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public static IterableApi sharedInstanceWithApiKeyWithUserId(Context currentCont
150150
{
151151
return sharedInstanceWithApiKey(currentContext, apiKey, null, userId, debugMode);
152152
}
153-
153+
154154
/**
155155
* Returns a shared instance of IterableApi. Updates the client data if an instance already exists.
156156
* Should be called whenever the app is opened.
@@ -281,7 +281,7 @@ public void track(String eventName, String campaignId, String templateId, JSONOb
281281
if (_email != null) {
282282
requestJSON.put(IterableConstants.KEY_EMAIL, _email);
283283
} else {
284-
284+
requestJSON.put(IterableConstants.KEY_USER_ID, _userId);
285285
}
286286
requestJSON.put(IterableConstants.KEY_EVENTNAME, eventName);
287287

@@ -297,8 +297,8 @@ public void track(String eventName, String campaignId, String templateId, JSONOb
297297
}
298298

299299
public void sendPush(String email, int campaignId) {
300-
sendPush(email, campaignId, null, null);
301-
}
300+
sendPush(email, campaignId, null, null);
301+
}
302302

303303
/**
304304
* Sends a push campaign to an email address at the given time.
@@ -354,7 +354,12 @@ public void updateEmail(String newEmail) {
354354

355355
sendRequest(IterableConstants.ENDPOINT_UPDATEEMAIL, requestJSON);
356356

357-
_email = newEmail;
357+
if (_email != null) {
358+
_email = newEmail;
359+
} else {
360+
IterableLogger.w(TAG, "updateEmail should not be called with a userId. " +
361+
"Init SDK with sharedInstanceWithApiKey instead of sharedInstanceWithApiKeyWithUserId");
362+
}
358363
}
359364

360365
public void updateUser(JSONObject dataFields) {
@@ -363,6 +368,8 @@ public void updateUser(JSONObject dataFields) {
363368
try {
364369
if (_email != null) {
365370
requestJSON.put(IterableConstants.KEY_EMAIL, _email);
371+
} else {
372+
requestJSON.put(IterableConstants.KEY_USER_ID, _userId);
366373
}
367374

368375
requestJSON.put(IterableConstants.KEY_DATAFIELDS, dataFields);
@@ -418,7 +425,11 @@ protected void trackPushOpen(int campaignId, int templateId, String messageId) {
418425
JSONObject requestJSON = new JSONObject();
419426

420427
try {
421-
requestJSON.put(IterableConstants.KEY_EMAIL, _email);
428+
if (_email != null) {
429+
requestJSON.put(IterableConstants.KEY_EMAIL, _email);
430+
} else {
431+
requestJSON.put(IterableConstants.KEY_USER_ID, _userId);
432+
}
422433
requestJSON.put(IterableConstants.KEY_CAMPAIGNID, campaignId);
423434
requestJSON.put(IterableConstants.KEY_TEMPLATE_ID, templateId);
424435
requestJSON.put(IterableConstants.KEY_MESSAGE_ID, messageId);
@@ -438,7 +449,11 @@ protected void disablePush(String token) {
438449
JSONObject requestJSON = new JSONObject();
439450
try {
440451
requestJSON.put(IterableConstants.KEY_TOKEN, token);
441-
requestJSON.put(IterableConstants.KEY_EMAIL, _email);
452+
if (_email != null) {
453+
requestJSON.put(IterableConstants.KEY_EMAIL, _email);
454+
} else {
455+
requestJSON.put(IterableConstants.KEY_USER_ID, _userId);
456+
}
442457
}
443458
catch (JSONException e) {
444459
e.printStackTrace();
@@ -480,7 +495,12 @@ private void registerDeviceToken(String applicationName, String token, JSONObjec
480495

481496
JSONObject requestJSON = new JSONObject();
482497
try {
483-
requestJSON.put(IterableConstants.KEY_EMAIL, _email);
498+
if (_email != null) {
499+
requestJSON.put(IterableConstants.KEY_EMAIL, _email);
500+
} else {
501+
requestJSON.put(IterableConstants.KEY_USER_ID, _userId);
502+
}
503+
484504
if (dataFields == null) {
485505
dataFields = new JSONObject();
486506
}

iterableapi/src/main/java/com/iterable/iterableapi/IterableConstants.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ public final class IterableConstants {
2020
public static final String KEY_RECIPIENT_EMAIL = "recipientEmail";
2121
public static final String KEY_SEND_AT = "sendAt";
2222
public static final String KEY_TEMPLATE_ID = "templateId";
23-
public static final String KEY_MESSAGE_ID = "messageId";
23+
public static final String KEY_MESSAGE_ID = "messageId";
2424
public static final String KEY_TOKEN = "token";
25+
public static final String KEY_USER_ID = "userId";
2526
public static final String KEY_PLATFORM = "platform";
2627
public static final String KEY_APPLICATIONNAME = "applicationName";
2728
public static final String KEY_DEVICE = "device";

0 commit comments

Comments
 (0)