12
12
import com .google .android .gms .common .GooglePlayServicesNotAvailableException ;
13
13
import com .google .android .gms .common .GooglePlayServicesRepairableException ;
14
14
15
+ import org .json .JSONArray ;
15
16
import org .json .JSONException ;
16
17
import org .json .JSONObject ;
17
18
18
19
import java .io .IOException ;
19
20
import java .text .SimpleDateFormat ;
21
+ import java .util .Arrays ;
20
22
import java .util .Date ;
21
23
import java .util .TimeZone ;
22
24
import java .util .regex .Matcher ;
@@ -501,7 +503,6 @@ public void registerForPush(String iterableAppId, String projectNumber, String p
501
503
502
504
/**
503
505
* Disables the device from push notifications
504
- *
505
506
* @param iterableAppId
506
507
* @param gcmProjectNumber
507
508
*/
@@ -511,7 +512,6 @@ public void disablePush(String iterableAppId, String gcmProjectNumber) {
511
512
512
513
/**
513
514
* Disables the device from push notifications
514
- *
515
515
* @param iterableAppId
516
516
* @param projectNumber
517
517
* @param pushServicePlatform
@@ -521,6 +521,40 @@ public void disablePush(String iterableAppId, String projectNumber, String pushS
521
521
new IterablePushRegistration ().execute (data );
522
522
}
523
523
524
+ /**
525
+ * Updates the user subscription preferences
526
+ * @param emailListIds
527
+ * @param unsubscribedChannelIds
528
+ * @param unsubscribedMessageTypeIds
529
+ * @discussion passing in an empty array will clear subscription list, passing in null will not modify the list
530
+ */
531
+ public void updateSubscriptions (Integer [] emailListIds , Integer [] unsubscribedChannelIds , Integer [] unsubscribedMessageTypeIds ) {
532
+ JSONObject requestJSON = new JSONObject ();
533
+ addEmailOrUserIdToJson (requestJSON );
534
+
535
+ tryAddArrayToJSON (requestJSON , IterableConstants .KEY_EMAIL_LIST_IDS , emailListIds );
536
+ tryAddArrayToJSON (requestJSON , IterableConstants .KEY_UNSUB_CHANNEL , unsubscribedChannelIds );
537
+ tryAddArrayToJSON (requestJSON , IterableConstants .KEY_UNSUB_MESSAGE , unsubscribedMessageTypeIds );
538
+
539
+ sendPostRequest (IterableConstants .ENDPOINT_UPDATE_USER_SUBS , requestJSON );
540
+ }
541
+
542
+ /**
543
+ * Attempts to add an array as a JSONArray to a JSONObject
544
+ * @param requestJSON
545
+ * @param key
546
+ * @param value
547
+ */
548
+ void tryAddArrayToJSON (JSONObject requestJSON , String key , Object [] value ) {
549
+ if (requestJSON != null && key != null && value != null )
550
+ try {
551
+ JSONArray mJSONArray = new JSONArray (Arrays .asList (value ));
552
+ requestJSON .put (key , mJSONArray );
553
+ } catch (JSONException e ) {
554
+ IterableLogger .e (TAG , e .toString ());
555
+ }
556
+ }
557
+
524
558
/**
525
559
* Gets a notification from Iterable and displays it on device.
526
560
* @param context
0 commit comments