@@ -27,6 +27,7 @@ public class IterableApi {
27
27
private Context _applicationContext ;
28
28
private String _apiKey ;
29
29
private String _email ;
30
+ private String _userId ;
30
31
private boolean _debugMode ;
31
32
private Bundle _payloadData ;
32
33
private IterableNotificationData _notificationData ;
@@ -39,9 +40,6 @@ public class IterableApi {
39
40
IterableApi (){
40
41
}
41
42
42
- IterableApi (Context context , String apiKey , String email ){
43
- updateData (context , apiKey , email );
44
- }
45
43
//---------------------------------------------------------------------------------------
46
44
//endregion
47
45
@@ -104,6 +102,60 @@ void setNotificationData(IterableNotificationData data) {
104
102
* Returns a shared instance of IterableApi. Updates the client data if an instance already exists.
105
103
* Should be called whenever the app is opened.
106
104
* @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
107
159
* @return stored instance of IterableApi
108
160
*/
109
161
public static IterableApi sharedInstanceWithApiKey (Activity currentActivity , String apiKey ,
@@ -117,6 +169,7 @@ public static IterableApi sharedInstanceWithApiKey(Activity currentActivity, Str
117
169
* Should be called whenever the app is opened.
118
170
* Allows the IterableApi to be intialized with debugging enabled
119
171
* @param currentActivity The current activity
172
+ * @param email The current email
120
173
* @return stored instance of IterableApi
121
174
*/
122
175
public static IterableApi sharedInstanceWithApiKey (Activity currentActivity , String apiKey ,
@@ -128,26 +181,34 @@ public static IterableApi sharedInstanceWithApiKey(Activity currentActivity, Str
128
181
/**
129
182
* Returns a shared instance of IterableApi. Updates the client data if an instance already exists.
130
183
* 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
132
186
* @return stored instance of IterableApi
133
187
*/
134
- public static IterableApi sharedInstanceWithApiKey (Context currentActivity , String apiKey ,
188
+ public static IterableApi sharedInstanceWithApiKey (Context currentContext , String apiKey ,
135
189
String email )
136
190
{
137
- return sharedInstanceWithApiKey (currentActivity , apiKey , email , false );
191
+ return sharedInstanceWithApiKey (currentContext , apiKey , email , false );
138
192
}
139
193
140
194
/**
141
195
* Returns a shared instance of IterableApi. Updates the client data if an instance already exists.
142
196
* Should be called whenever the app is opened.
143
197
* Allows the IterableApi to be intialized with debugging enabled
144
198
* @param currentContext The current context
199
+ * @param email The current email
145
200
* @return stored instance of IterableApi
146
201
*/
147
202
public static IterableApi sharedInstanceWithApiKey (Context currentContext , String apiKey ,
148
203
String email , boolean debugMode )
149
204
{
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 );
151
212
152
213
if (currentContext instanceof Activity ) {
153
214
Activity currentActivity = (Activity ) currentContext ;
@@ -217,7 +278,11 @@ public void track(String eventName, String campaignId, String templateId) {
217
278
public void track (String eventName , String campaignId , String templateId , JSONObject dataFields ) {
218
279
JSONObject requestJSON = new JSONObject ();
219
280
try {
220
- requestJSON .put (IterableConstants .KEY_EMAIL , _email );
281
+ if (_email != null ) {
282
+ requestJSON .put (IterableConstants .KEY_EMAIL , _email );
283
+ } else {
284
+
285
+ }
221
286
requestJSON .put (IterableConstants .KEY_EVENTNAME , eventName );
222
287
223
288
requestJSON .put (IterableConstants .KEY_CAMPAIGNID , campaignId );
@@ -296,7 +361,10 @@ public void updateUser(JSONObject dataFields) {
296
361
JSONObject requestJSON = new JSONObject ();
297
362
298
363
try {
299
- requestJSON .put (IterableConstants .KEY_EMAIL , _email );
364
+ if (_email != null ) {
365
+ requestJSON .put (IterableConstants .KEY_EMAIL , _email );
366
+ }
367
+
300
368
requestJSON .put (IterableConstants .KEY_DATAFIELDS , dataFields );
301
369
}
302
370
catch (JSONException e ) {
@@ -383,10 +451,11 @@ protected void disablePush(String token) {
383
451
384
452
//region Private Fuctions
385
453
//---------------------------------------------------------------------------------------
386
- private void updateData (Context context , String apiKey , String email ) {
454
+ private void updateData (Context context , String apiKey , String email , String userId ) {
387
455
this ._applicationContext = context ;
388
456
this ._apiKey = apiKey ;
389
457
this ._email = email ;
458
+ this ._userId = userId ;
390
459
}
391
460
392
461
private void tryTrackNotifOpen (Intent calledIntent ) {
0 commit comments