Skip to content

Commit 1bb5492

Browse files
committed
changed call signatures of the sharedInstance fuction to take in a userId
1 parent 7b2a4a9 commit 1bb5492

File tree

1 file changed

+79
-10
lines changed

1 file changed

+79
-10
lines changed

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

Lines changed: 79 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public class IterableApi {
2727
private Context _applicationContext;
2828
private String _apiKey;
2929
private String _email;
30+
private String _userId;
3031
private boolean _debugMode;
3132
private Bundle _payloadData;
3233
private IterableNotificationData _notificationData;
@@ -39,9 +40,6 @@ public class IterableApi {
3940
IterableApi(){
4041
}
4142

42-
IterableApi(Context context, String apiKey, String email){
43-
updateData(context, apiKey, email);
44-
}
4543
//---------------------------------------------------------------------------------------
4644
//endregion
4745

@@ -104,6 +102,60 @@ void setNotificationData(IterableNotificationData data) {
104102
* Returns a shared instance of IterableApi. Updates the client data if an instance already exists.
105103
* Should be called whenever the app is opened.
106104
* @param currentActivity The current activity
105+
* @param userId The current userId
106+
* @return stored instance of IterableApi
107+
*/
108+
public static IterableApi sharedInstanceWithApiKeyWithUserId(Activity currentActivity, String apiKey,
109+
String userId)
110+
{
111+
return sharedInstanceWithApiKeyWithUserId(currentActivity, apiKey, userId, false);
112+
}
113+
114+
/**
115+
* Returns a shared instance of IterableApi. Updates the client data if an instance already exists.
116+
* Should be called whenever the app is opened.
117+
* Allows the IterableApi to be intialized with debugging enabled
118+
* @param currentActivity The current activity
119+
* @param userId
120+
* The current userId@return stored instance of IterableApi
121+
*/
122+
public static IterableApi sharedInstanceWithApiKeyWithUserId(Activity currentActivity, String apiKey,
123+
String userId, boolean debugMode)
124+
{
125+
return sharedInstanceWithApiKeyWithUserId((Context) currentActivity, apiKey, userId, debugMode);
126+
}
127+
128+
/**
129+
* Returns a shared instance of IterableApi. Updates the client data if an instance already exists.
130+
* Should be called whenever the app is opened.
131+
* @param currentContext The current context
132+
* @param userId The current userId
133+
* @return stored instance of IterableApi
134+
*/
135+
public static IterableApi sharedInstanceWithApiKeyWithUserId(Context currentContext, String apiKey,
136+
String userId)
137+
{
138+
return sharedInstanceWithApiKey(currentContext, apiKey, null, userId, false);
139+
}
140+
141+
/**
142+
* Returns a shared instance of IterableApi. Updates the client data if an instance already exists.
143+
* Should be called whenever the app is opened.
144+
* Allows the IterableApi to be intialized with debugging enabled
145+
* @param currentContext The current context
146+
* @return stored instance of IterableApi
147+
*/
148+
public static IterableApi sharedInstanceWithApiKeyWithUserId(Context currentContext, String apiKey,
149+
String userId, boolean debugMode)
150+
{
151+
return sharedInstanceWithApiKey(currentContext, apiKey, null, userId, debugMode);
152+
}
153+
154+
/**
155+
* Returns a shared instance of IterableApi. Updates the client data if an instance already exists.
156+
* Should be called whenever the app is opened.
157+
* @param currentActivity The current activity
158+
* @param email The current email
107159
* @return stored instance of IterableApi
108160
*/
109161
public static IterableApi sharedInstanceWithApiKey(Activity currentActivity, String apiKey,
@@ -117,6 +169,7 @@ public static IterableApi sharedInstanceWithApiKey(Activity currentActivity, Str
117169
* Should be called whenever the app is opened.
118170
* Allows the IterableApi to be intialized with debugging enabled
119171
* @param currentActivity The current activity
172+
* @param email The current email
120173
* @return stored instance of IterableApi
121174
*/
122175
public static IterableApi sharedInstanceWithApiKey(Activity currentActivity, String apiKey,
@@ -128,26 +181,34 @@ public static IterableApi sharedInstanceWithApiKey(Activity currentActivity, Str
128181
/**
129182
* Returns a shared instance of IterableApi. Updates the client data if an instance already exists.
130183
* Should be called whenever the app is opened.
131-
* @param currentActivity The current activity
184+
* @param currentContext The current context
185+
* @param email The current email
132186
* @return stored instance of IterableApi
133187
*/
134-
public static IterableApi sharedInstanceWithApiKey(Context currentActivity, String apiKey,
188+
public static IterableApi sharedInstanceWithApiKey(Context currentContext, String apiKey,
135189
String email)
136190
{
137-
return sharedInstanceWithApiKey(currentActivity, apiKey, email, false);
191+
return sharedInstanceWithApiKey(currentContext, apiKey, email, false);
138192
}
139193

140194
/**
141195
* Returns a shared instance of IterableApi. Updates the client data if an instance already exists.
142196
* Should be called whenever the app is opened.
143197
* Allows the IterableApi to be intialized with debugging enabled
144198
* @param currentContext The current context
199+
* @param email The current email
145200
* @return stored instance of IterableApi
146201
*/
147202
public static IterableApi sharedInstanceWithApiKey(Context currentContext, String apiKey,
148203
String email, boolean debugMode)
149204
{
150-
sharedInstance.updateData(currentContext.getApplicationContext(), apiKey, email);
205+
return sharedInstanceWithApiKey(currentContext, apiKey, email, null, debugMode);
206+
}
207+
208+
private static IterableApi sharedInstanceWithApiKey(Context currentContext, String apiKey,
209+
String email, String userId, boolean debugMode)
210+
{
211+
sharedInstance.updateData(currentContext.getApplicationContext(), apiKey, email, userId);
151212

152213
if (currentContext instanceof Activity) {
153214
Activity currentActivity = (Activity) currentContext;
@@ -217,7 +278,11 @@ public void track(String eventName, String campaignId, String templateId) {
217278
public void track(String eventName, String campaignId, String templateId, JSONObject dataFields) {
218279
JSONObject requestJSON = new JSONObject();
219280
try {
220-
requestJSON.put(IterableConstants.KEY_EMAIL, _email);
281+
if (_email != null) {
282+
requestJSON.put(IterableConstants.KEY_EMAIL, _email);
283+
} else {
284+
285+
}
221286
requestJSON.put(IterableConstants.KEY_EVENTNAME, eventName);
222287

223288
requestJSON.put(IterableConstants.KEY_CAMPAIGNID, campaignId);
@@ -296,7 +361,10 @@ public void updateUser(JSONObject dataFields) {
296361
JSONObject requestJSON = new JSONObject();
297362

298363
try {
299-
requestJSON.put(IterableConstants.KEY_EMAIL, _email);
364+
if (_email != null) {
365+
requestJSON.put(IterableConstants.KEY_EMAIL, _email);
366+
}
367+
300368
requestJSON.put(IterableConstants.KEY_DATAFIELDS, dataFields);
301369
}
302370
catch (JSONException e) {
@@ -383,10 +451,11 @@ protected void disablePush(String token) {
383451

384452
//region Private Fuctions
385453
//---------------------------------------------------------------------------------------
386-
private void updateData(Context context, String apiKey, String email) {
454+
private void updateData(Context context, String apiKey, String email, String userId) {
387455
this._applicationContext = context;
388456
this._apiKey = apiKey;
389457
this._email = email;
458+
this._userId = userId;
390459
}
391460

392461
private void tryTrackNotifOpen(Intent calledIntent) {

0 commit comments

Comments
 (0)