From 7b2a4a970ba9de6d5f78e44fa9e23829c093d841 Mon Sep 17 00:00:00 2001
From: David Truong
Date: Thu, 13 Oct 2016 10:24:11 -0700
Subject: [PATCH 1/4] removes deprecated trackConversion
---
.idea/misc.xml | 58 +++++++++++++++++++
.../com/iterable/iterableapi/IterableApi.java | 23 --------
.../iterableapi/IterableConstants.java | 1 -
3 files changed, 58 insertions(+), 24 deletions(-)
create mode 100644 .idea/misc.xml
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 000000000..b87fe2436
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,58 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/iterableapi/src/main/java/com/iterable/iterableapi/IterableApi.java b/iterableapi/src/main/java/com/iterable/iterableapi/IterableApi.java
index 47f9d1bd9..15af4ad52 100644
--- a/iterableapi/src/main/java/com/iterable/iterableapi/IterableApi.java
+++ b/iterableapi/src/main/java/com/iterable/iterableapi/IterableApi.java
@@ -231,29 +231,6 @@ public void track(String eventName, String campaignId, String templateId, JSONOb
sendRequest(IterableConstants.ENDPOINT_TRACK, requestJSON);
}
- public void trackConversion(int campaignId, int templateId) {
- trackConversion(campaignId, templateId, null);
- }
-
- public void trackConversion(int campaignId, int templateId, JSONObject dataFields) {
-
- JSONObject requestJSON = new JSONObject();
-
- try {
- requestJSON.put(IterableConstants.KEY_EMAIL, _email);
- requestJSON.put(IterableConstants.KEY_CAMPAIGNID, campaignId);
- requestJSON.put(IterableConstants.KEY_TEMPLATE_ID, templateId);
- if (dataFields != null) {
- requestJSON.put(IterableConstants.KEY_DATAFIELDS, dataFields);
- }
- }
- catch (JSONException e) {
- e.printStackTrace();
- }
-
- sendRequest(IterableConstants.ENDPOINT_TRACKCONVERSION, requestJSON);
- }
-
public void sendPush(String email, int campaignId) {
sendPush(email, campaignId, null, null);
}
diff --git a/iterableapi/src/main/java/com/iterable/iterableapi/IterableConstants.java b/iterableapi/src/main/java/com/iterable/iterableapi/IterableConstants.java
index 2bac70d5e..2c95a3945 100644
--- a/iterableapi/src/main/java/com/iterable/iterableapi/IterableConstants.java
+++ b/iterableapi/src/main/java/com/iterable/iterableapi/IterableConstants.java
@@ -33,7 +33,6 @@ public final class IterableConstants {
public static final String ENDPOINT_PUSHTARGET = "push/target";
public static final String ENDPOINT_REGISTERDEVICETOKEN = "users/registerDeviceToken";
public static final String ENDPOINT_TRACK = "events/track";
- public static final String ENDPOINT_TRACKCONVERSION = "events/trackConversion";
public static final String ENDPOINT_TRACKPURCHASE = "commerce/trackPurchase";
public static final String ENDPOINT_TRACKPUSHOPEN = "events/trackPushOpen";
public static final String ENDPOINT_UPDATEEMAIL = "users/updateEmail";
From 1bb54926425b15c2b9c8e925dcd772b965ea9384 Mon Sep 17 00:00:00 2001
From: David Truong
Date: Thu, 13 Oct 2016 12:00:53 -0700
Subject: [PATCH 2/4] changed call signatures of the sharedInstance fuction to
take in a userId
---
.../com/iterable/iterableapi/IterableApi.java | 89 ++++++++++++++++---
1 file changed, 79 insertions(+), 10 deletions(-)
diff --git a/iterableapi/src/main/java/com/iterable/iterableapi/IterableApi.java b/iterableapi/src/main/java/com/iterable/iterableapi/IterableApi.java
index 15af4ad52..a631176e7 100644
--- a/iterableapi/src/main/java/com/iterable/iterableapi/IterableApi.java
+++ b/iterableapi/src/main/java/com/iterable/iterableapi/IterableApi.java
@@ -27,6 +27,7 @@ public class IterableApi {
private Context _applicationContext;
private String _apiKey;
private String _email;
+ private String _userId;
private boolean _debugMode;
private Bundle _payloadData;
private IterableNotificationData _notificationData;
@@ -39,9 +40,6 @@ public class IterableApi {
IterableApi(){
}
- IterableApi(Context context, String apiKey, String email){
- updateData(context, apiKey, email);
- }
//---------------------------------------------------------------------------------------
//endregion
@@ -104,6 +102,60 @@ void setNotificationData(IterableNotificationData data) {
* Returns a shared instance of IterableApi. Updates the client data if an instance already exists.
* Should be called whenever the app is opened.
* @param currentActivity The current activity
+ * @param userId The current userId
+ * @return stored instance of IterableApi
+ */
+ public static IterableApi sharedInstanceWithApiKeyWithUserId(Activity currentActivity, String apiKey,
+ String userId)
+ {
+ return sharedInstanceWithApiKeyWithUserId(currentActivity, apiKey, userId, false);
+ }
+
+ /**
+ * Returns a shared instance of IterableApi. Updates the client data if an instance already exists.
+ * Should be called whenever the app is opened.
+ * Allows the IterableApi to be intialized with debugging enabled
+ * @param currentActivity The current activity
+ * @param userId
+ * The current userId@return stored instance of IterableApi
+ */
+ public static IterableApi sharedInstanceWithApiKeyWithUserId(Activity currentActivity, String apiKey,
+ String userId, boolean debugMode)
+ {
+ return sharedInstanceWithApiKeyWithUserId((Context) currentActivity, apiKey, userId, debugMode);
+ }
+
+ /**
+ * Returns a shared instance of IterableApi. Updates the client data if an instance already exists.
+ * Should be called whenever the app is opened.
+ * @param currentContext The current context
+ * @param userId The current userId
+ * @return stored instance of IterableApi
+ */
+ public static IterableApi sharedInstanceWithApiKeyWithUserId(Context currentContext, String apiKey,
+ String userId)
+ {
+ return sharedInstanceWithApiKey(currentContext, apiKey, null, userId, false);
+ }
+
+ /**
+ * Returns a shared instance of IterableApi. Updates the client data if an instance already exists.
+ * Should be called whenever the app is opened.
+ * Allows the IterableApi to be intialized with debugging enabled
+ * @param currentContext The current context
+ * @return stored instance of IterableApi
+ */
+ public static IterableApi sharedInstanceWithApiKeyWithUserId(Context currentContext, String apiKey,
+ String userId, boolean debugMode)
+ {
+ return sharedInstanceWithApiKey(currentContext, apiKey, null, userId, debugMode);
+ }
+
+ /**
+ * Returns a shared instance of IterableApi. Updates the client data if an instance already exists.
+ * Should be called whenever the app is opened.
+ * @param currentActivity The current activity
+ * @param email The current email
* @return stored instance of IterableApi
*/
public static IterableApi sharedInstanceWithApiKey(Activity currentActivity, String apiKey,
@@ -117,6 +169,7 @@ public static IterableApi sharedInstanceWithApiKey(Activity currentActivity, Str
* Should be called whenever the app is opened.
* Allows the IterableApi to be intialized with debugging enabled
* @param currentActivity The current activity
+ * @param email The current email
* @return stored instance of IterableApi
*/
public static IterableApi sharedInstanceWithApiKey(Activity currentActivity, String apiKey,
@@ -128,13 +181,14 @@ public static IterableApi sharedInstanceWithApiKey(Activity currentActivity, Str
/**
* Returns a shared instance of IterableApi. Updates the client data if an instance already exists.
* Should be called whenever the app is opened.
- * @param currentActivity The current activity
+ * @param currentContext The current context
+ * @param email The current email
* @return stored instance of IterableApi
*/
- public static IterableApi sharedInstanceWithApiKey(Context currentActivity, String apiKey,
+ public static IterableApi sharedInstanceWithApiKey(Context currentContext, String apiKey,
String email)
{
- return sharedInstanceWithApiKey(currentActivity, apiKey, email, false);
+ return sharedInstanceWithApiKey(currentContext, apiKey, email, false);
}
/**
@@ -142,12 +196,19 @@ public static IterableApi sharedInstanceWithApiKey(Context currentActivity, Stri
* Should be called whenever the app is opened.
* Allows the IterableApi to be intialized with debugging enabled
* @param currentContext The current context
+ * @param email The current email
* @return stored instance of IterableApi
*/
public static IterableApi sharedInstanceWithApiKey(Context currentContext, String apiKey,
String email, boolean debugMode)
{
- sharedInstance.updateData(currentContext.getApplicationContext(), apiKey, email);
+ return sharedInstanceWithApiKey(currentContext, apiKey, email, null, debugMode);
+ }
+
+ private static IterableApi sharedInstanceWithApiKey(Context currentContext, String apiKey,
+ String email, String userId, boolean debugMode)
+ {
+ sharedInstance.updateData(currentContext.getApplicationContext(), apiKey, email, userId);
if (currentContext instanceof Activity) {
Activity currentActivity = (Activity) currentContext;
@@ -217,7 +278,11 @@ public void track(String eventName, String campaignId, String templateId) {
public void track(String eventName, String campaignId, String templateId, JSONObject dataFields) {
JSONObject requestJSON = new JSONObject();
try {
- requestJSON.put(IterableConstants.KEY_EMAIL, _email);
+ if (_email != null) {
+ requestJSON.put(IterableConstants.KEY_EMAIL, _email);
+ } else {
+
+ }
requestJSON.put(IterableConstants.KEY_EVENTNAME, eventName);
requestJSON.put(IterableConstants.KEY_CAMPAIGNID, campaignId);
@@ -296,7 +361,10 @@ public void updateUser(JSONObject dataFields) {
JSONObject requestJSON = new JSONObject();
try {
- requestJSON.put(IterableConstants.KEY_EMAIL, _email);
+ if (_email != null) {
+ requestJSON.put(IterableConstants.KEY_EMAIL, _email);
+ }
+
requestJSON.put(IterableConstants.KEY_DATAFIELDS, dataFields);
}
catch (JSONException e) {
@@ -383,10 +451,11 @@ protected void disablePush(String token) {
//region Private Fuctions
//---------------------------------------------------------------------------------------
- private void updateData(Context context, String apiKey, String email) {
+ private void updateData(Context context, String apiKey, String email, String userId) {
this._applicationContext = context;
this._apiKey = apiKey;
this._email = email;
+ this._userId = userId;
}
private void tryTrackNotifOpen(Intent calledIntent) {
From 3fe68f77568c939418016e1bc26cae23c3104b11 Mon Sep 17 00:00:00 2001
From: David Truong
Date: Thu, 13 Oct 2016 12:59:31 -0700
Subject: [PATCH 3/4] added in userId for each api call instead of email
---
.../com/iterable/iterableapi/IterableApi.java | 36 ++++++++++++++-----
.../iterableapi/IterableConstants.java | 3 +-
2 files changed, 30 insertions(+), 9 deletions(-)
diff --git a/iterableapi/src/main/java/com/iterable/iterableapi/IterableApi.java b/iterableapi/src/main/java/com/iterable/iterableapi/IterableApi.java
index a631176e7..c6b01bc61 100644
--- a/iterableapi/src/main/java/com/iterable/iterableapi/IterableApi.java
+++ b/iterableapi/src/main/java/com/iterable/iterableapi/IterableApi.java
@@ -150,7 +150,7 @@ public static IterableApi sharedInstanceWithApiKeyWithUserId(Context currentCont
{
return sharedInstanceWithApiKey(currentContext, apiKey, null, userId, debugMode);
}
-
+
/**
* Returns a shared instance of IterableApi. Updates the client data if an instance already exists.
* Should be called whenever the app is opened.
@@ -281,7 +281,7 @@ public void track(String eventName, String campaignId, String templateId, JSONOb
if (_email != null) {
requestJSON.put(IterableConstants.KEY_EMAIL, _email);
} else {
-
+ requestJSON.put(IterableConstants.KEY_USER_ID, _userId);
}
requestJSON.put(IterableConstants.KEY_EVENTNAME, eventName);
@@ -297,8 +297,8 @@ public void track(String eventName, String campaignId, String templateId, JSONOb
}
public void sendPush(String email, int campaignId) {
- sendPush(email, campaignId, null, null);
-}
+ sendPush(email, campaignId, null, null);
+ }
/**
* Sends a push campaign to an email address at the given time.
@@ -354,7 +354,12 @@ public void updateEmail(String newEmail) {
sendRequest(IterableConstants.ENDPOINT_UPDATEEMAIL, requestJSON);
- _email = newEmail;
+ if (_email != null) {
+ _email = newEmail;
+ } else {
+ IterableLogger.w(TAG, "updateEmail should not be called with a userId. " +
+ "Init SDK with sharedInstanceWithApiKey instead of sharedInstanceWithApiKeyWithUserId");
+ }
}
public void updateUser(JSONObject dataFields) {
@@ -363,6 +368,8 @@ public void updateUser(JSONObject dataFields) {
try {
if (_email != null) {
requestJSON.put(IterableConstants.KEY_EMAIL, _email);
+ } else {
+ requestJSON.put(IterableConstants.KEY_USER_ID, _userId);
}
requestJSON.put(IterableConstants.KEY_DATAFIELDS, dataFields);
@@ -418,7 +425,11 @@ protected void trackPushOpen(int campaignId, int templateId, String messageId) {
JSONObject requestJSON = new JSONObject();
try {
- requestJSON.put(IterableConstants.KEY_EMAIL, _email);
+ if (_email != null) {
+ requestJSON.put(IterableConstants.KEY_EMAIL, _email);
+ } else {
+ requestJSON.put(IterableConstants.KEY_USER_ID, _userId);
+ }
requestJSON.put(IterableConstants.KEY_CAMPAIGNID, campaignId);
requestJSON.put(IterableConstants.KEY_TEMPLATE_ID, templateId);
requestJSON.put(IterableConstants.KEY_MESSAGE_ID, messageId);
@@ -438,7 +449,11 @@ protected void disablePush(String token) {
JSONObject requestJSON = new JSONObject();
try {
requestJSON.put(IterableConstants.KEY_TOKEN, token);
- requestJSON.put(IterableConstants.KEY_EMAIL, _email);
+ if (_email != null) {
+ requestJSON.put(IterableConstants.KEY_EMAIL, _email);
+ } else {
+ requestJSON.put(IterableConstants.KEY_USER_ID, _userId);
+ }
}
catch (JSONException e) {
e.printStackTrace();
@@ -480,7 +495,12 @@ private void registerDeviceToken(String applicationName, String token, JSONObjec
JSONObject requestJSON = new JSONObject();
try {
- requestJSON.put(IterableConstants.KEY_EMAIL, _email);
+ if (_email != null) {
+ requestJSON.put(IterableConstants.KEY_EMAIL, _email);
+ } else {
+ requestJSON.put(IterableConstants.KEY_USER_ID, _userId);
+ }
+
if (dataFields == null) {
dataFields = new JSONObject();
}
diff --git a/iterableapi/src/main/java/com/iterable/iterableapi/IterableConstants.java b/iterableapi/src/main/java/com/iterable/iterableapi/IterableConstants.java
index 2c95a3945..c29a2c7f5 100644
--- a/iterableapi/src/main/java/com/iterable/iterableapi/IterableConstants.java
+++ b/iterableapi/src/main/java/com/iterable/iterableapi/IterableConstants.java
@@ -20,8 +20,9 @@ public final class IterableConstants {
public static final String KEY_RECIPIENT_EMAIL = "recipientEmail";
public static final String KEY_SEND_AT = "sendAt";
public static final String KEY_TEMPLATE_ID = "templateId";
- public static final String KEY_MESSAGE_ID = "messageId";
+ public static final String KEY_MESSAGE_ID = "messageId";
public static final String KEY_TOKEN = "token";
+ public static final String KEY_USER_ID = "userId";
public static final String KEY_PLATFORM = "platform";
public static final String KEY_APPLICATIONNAME = "applicationName";
public static final String KEY_DEVICE = "device";
From 3a395dd771c8399fc55c7411e841eaf21b528998 Mon Sep 17 00:00:00 2001
From: David Truong
Date: Thu, 13 Oct 2016 16:17:56 -0700
Subject: [PATCH 4/4] code review - refactor check for email and userId.
---
.idea/misc.xml | 58 -----------------
.../com/iterable/iterableapi/IterableApi.java | 64 ++++++++-----------
2 files changed, 27 insertions(+), 95 deletions(-)
delete mode 100644 .idea/misc.xml
diff --git a/.idea/misc.xml b/.idea/misc.xml
deleted file mode 100644
index b87fe2436..000000000
--- a/.idea/misc.xml
+++ /dev/null
@@ -1,58 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/iterableapi/src/main/java/com/iterable/iterableapi/IterableApi.java b/iterableapi/src/main/java/com/iterable/iterableapi/IterableApi.java
index c6b01bc61..3d9b2a6ff 100644
--- a/iterableapi/src/main/java/com/iterable/iterableapi/IterableApi.java
+++ b/iterableapi/src/main/java/com/iterable/iterableapi/IterableApi.java
@@ -278,11 +278,7 @@ public void track(String eventName, String campaignId, String templateId) {
public void track(String eventName, String campaignId, String templateId, JSONObject dataFields) {
JSONObject requestJSON = new JSONObject();
try {
- if (_email != null) {
- requestJSON.put(IterableConstants.KEY_EMAIL, _email);
- } else {
- requestJSON.put(IterableConstants.KEY_USER_ID, _userId);
- }
+ addEmailOrUserIdToJson(requestJSON);
requestJSON.put(IterableConstants.KEY_EVENTNAME, eventName);
requestJSON.put(IterableConstants.KEY_CAMPAIGNID, campaignId);
@@ -342,19 +338,19 @@ public void sendPush(String email, int campaignId, Date sendAt, JSONObject dataF
}
public void updateEmail(String newEmail) {
- JSONObject requestJSON = new JSONObject();
+ if (_email != null) {
+ JSONObject requestJSON = new JSONObject();
- try {
- requestJSON.put(IterableConstants.KEY_CURRENT_EMAIL, _email);
- requestJSON.put(IterableConstants.KEY_NEW_EMAIL, newEmail);
- }
- catch (JSONException e) {
- e.printStackTrace();
- }
+ try {
+ requestJSON.put(IterableConstants.KEY_CURRENT_EMAIL, _email);
+ requestJSON.put(IterableConstants.KEY_NEW_EMAIL, newEmail);
+ }
+ catch (JSONException e) {
+ e.printStackTrace();
+ }
- sendRequest(IterableConstants.ENDPOINT_UPDATEEMAIL, requestJSON);
+ sendRequest(IterableConstants.ENDPOINT_UPDATEEMAIL, requestJSON);
- if (_email != null) {
_email = newEmail;
} else {
IterableLogger.w(TAG, "updateEmail should not be called with a userId. " +
@@ -366,12 +362,7 @@ public void updateUser(JSONObject dataFields) {
JSONObject requestJSON = new JSONObject();
try {
- if (_email != null) {
- requestJSON.put(IterableConstants.KEY_EMAIL, _email);
- } else {
- requestJSON.put(IterableConstants.KEY_USER_ID, _userId);
- }
-
+ addEmailOrUserIdToJson(requestJSON);
requestJSON.put(IterableConstants.KEY_DATAFIELDS, dataFields);
}
catch (JSONException e) {
@@ -425,11 +416,7 @@ protected void trackPushOpen(int campaignId, int templateId, String messageId) {
JSONObject requestJSON = new JSONObject();
try {
- if (_email != null) {
- requestJSON.put(IterableConstants.KEY_EMAIL, _email);
- } else {
- requestJSON.put(IterableConstants.KEY_USER_ID, _userId);
- }
+ addEmailOrUserIdToJson(requestJSON);
requestJSON.put(IterableConstants.KEY_CAMPAIGNID, campaignId);
requestJSON.put(IterableConstants.KEY_TEMPLATE_ID, templateId);
requestJSON.put(IterableConstants.KEY_MESSAGE_ID, messageId);
@@ -448,12 +435,7 @@ protected void trackPushOpen(int campaignId, int templateId, String messageId) {
protected void disablePush(String token) {
JSONObject requestJSON = new JSONObject();
try {
- requestJSON.put(IterableConstants.KEY_TOKEN, token);
- if (_email != null) {
- requestJSON.put(IterableConstants.KEY_EMAIL, _email);
- } else {
- requestJSON.put(IterableConstants.KEY_USER_ID, _userId);
- }
+ requestJSON.put(IterableConstants.KEY_TOKEN, token);addEmailOrUserIdToJson(requestJSON);
}
catch (JSONException e) {
e.printStackTrace();
@@ -495,11 +477,7 @@ private void registerDeviceToken(String applicationName, String token, JSONObjec
JSONObject requestJSON = new JSONObject();
try {
- if (_email != null) {
- requestJSON.put(IterableConstants.KEY_EMAIL, _email);
- } else {
- requestJSON.put(IterableConstants.KEY_USER_ID, _userId);
- }
+ addEmailOrUserIdToJson(requestJSON);
if (dataFields == null) {
dataFields = new JSONObject();
@@ -529,6 +507,18 @@ private void sendRequest(String resourcePath, JSONObject json) {
new IterableRequest().execute(request);
}
+ private void addEmailOrUserIdToJson(JSONObject requestJSON) {
+ try {
+ if (_email != null) {
+ requestJSON.put(IterableConstants.KEY_EMAIL, _email);
+ } else {
+ requestJSON.put(IterableConstants.KEY_USER_ID, _userId);
+ }
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ }
+
//---------------------------------------------------------------------------------------
//endregion