@@ -278,11 +278,7 @@ public void track(String eventName, String campaignId, String templateId) {
278
278
public void track (String eventName , String campaignId , String templateId , JSONObject dataFields ) {
279
279
JSONObject requestJSON = new JSONObject ();
280
280
try {
281
- if (_email != null ) {
282
- requestJSON .put (IterableConstants .KEY_EMAIL , _email );
283
- } else {
284
- requestJSON .put (IterableConstants .KEY_USER_ID , _userId );
285
- }
281
+ addEmailOrUserIdToJson (requestJSON );
286
282
requestJSON .put (IterableConstants .KEY_EVENTNAME , eventName );
287
283
288
284
requestJSON .put (IterableConstants .KEY_CAMPAIGNID , campaignId );
@@ -342,19 +338,19 @@ public void sendPush(String email, int campaignId, Date sendAt, JSONObject dataF
342
338
}
343
339
344
340
public void updateEmail (String newEmail ) {
345
- JSONObject requestJSON = new JSONObject ();
341
+ if (_email != null ) {
342
+ JSONObject requestJSON = new JSONObject ();
346
343
347
- try {
348
- requestJSON .put (IterableConstants .KEY_CURRENT_EMAIL , _email );
349
- requestJSON .put (IterableConstants .KEY_NEW_EMAIL , newEmail );
350
- }
351
- catch (JSONException e ) {
352
- e .printStackTrace ();
353
- }
344
+ try {
345
+ requestJSON .put (IterableConstants .KEY_CURRENT_EMAIL , _email );
346
+ requestJSON .put (IterableConstants .KEY_NEW_EMAIL , newEmail );
347
+ }
348
+ catch (JSONException e ) {
349
+ e .printStackTrace ();
350
+ }
354
351
355
- sendRequest (IterableConstants .ENDPOINT_UPDATEEMAIL , requestJSON );
352
+ sendRequest (IterableConstants .ENDPOINT_UPDATEEMAIL , requestJSON );
356
353
357
- if (_email != null ) {
358
354
_email = newEmail ;
359
355
} else {
360
356
IterableLogger .w (TAG , "updateEmail should not be called with a userId. " +
@@ -366,12 +362,7 @@ public void updateUser(JSONObject dataFields) {
366
362
JSONObject requestJSON = new JSONObject ();
367
363
368
364
try {
369
- if (_email != null ) {
370
- requestJSON .put (IterableConstants .KEY_EMAIL , _email );
371
- } else {
372
- requestJSON .put (IterableConstants .KEY_USER_ID , _userId );
373
- }
374
-
365
+ addEmailOrUserIdToJson (requestJSON );
375
366
requestJSON .put (IterableConstants .KEY_DATAFIELDS , dataFields );
376
367
}
377
368
catch (JSONException e ) {
@@ -425,11 +416,7 @@ protected void trackPushOpen(int campaignId, int templateId, String messageId) {
425
416
JSONObject requestJSON = new JSONObject ();
426
417
427
418
try {
428
- if (_email != null ) {
429
- requestJSON .put (IterableConstants .KEY_EMAIL , _email );
430
- } else {
431
- requestJSON .put (IterableConstants .KEY_USER_ID , _userId );
432
- }
419
+ addEmailOrUserIdToJson (requestJSON );
433
420
requestJSON .put (IterableConstants .KEY_CAMPAIGNID , campaignId );
434
421
requestJSON .put (IterableConstants .KEY_TEMPLATE_ID , templateId );
435
422
requestJSON .put (IterableConstants .KEY_MESSAGE_ID , messageId );
@@ -448,12 +435,7 @@ protected void trackPushOpen(int campaignId, int templateId, String messageId) {
448
435
protected void disablePush (String token ) {
449
436
JSONObject requestJSON = new JSONObject ();
450
437
try {
451
- requestJSON .put (IterableConstants .KEY_TOKEN , token );
452
- if (_email != null ) {
453
- requestJSON .put (IterableConstants .KEY_EMAIL , _email );
454
- } else {
455
- requestJSON .put (IterableConstants .KEY_USER_ID , _userId );
456
- }
438
+ requestJSON .put (IterableConstants .KEY_TOKEN , token );addEmailOrUserIdToJson (requestJSON );
457
439
}
458
440
catch (JSONException e ) {
459
441
e .printStackTrace ();
@@ -495,11 +477,7 @@ private void registerDeviceToken(String applicationName, String token, JSONObjec
495
477
496
478
JSONObject requestJSON = new JSONObject ();
497
479
try {
498
- if (_email != null ) {
499
- requestJSON .put (IterableConstants .KEY_EMAIL , _email );
500
- } else {
501
- requestJSON .put (IterableConstants .KEY_USER_ID , _userId );
502
- }
480
+ addEmailOrUserIdToJson (requestJSON );
503
481
504
482
if (dataFields == null ) {
505
483
dataFields = new JSONObject ();
@@ -529,6 +507,18 @@ private void sendRequest(String resourcePath, JSONObject json) {
529
507
new IterableRequest ().execute (request );
530
508
}
531
509
510
+ private void addEmailOrUserIdToJson (JSONObject requestJSON ) {
511
+ try {
512
+ if (_email != null ) {
513
+ requestJSON .put (IterableConstants .KEY_EMAIL , _email );
514
+ } else {
515
+ requestJSON .put (IterableConstants .KEY_USER_ID , _userId );
516
+ }
517
+ } catch (JSONException e ) {
518
+ e .printStackTrace ();
519
+ }
520
+ }
521
+
532
522
//---------------------------------------------------------------------------------------
533
523
//endregion
534
524
0 commit comments