Skip to content
This repository was archived by the owner on Jul 22, 2020. It is now read-only.

Commit 38f740e

Browse files
authored
Adds in updateSubscriptions functionality (#42)
* Adds in updateSubscriptions functionality * code review fixes * update documentation
1 parent 7f123f4 commit 38f740e

File tree

5 files changed

+83
-1
lines changed

5 files changed

+83
-1
lines changed

Artifacts/include/Iterable-iOS-SDK/IterableAPI.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,17 @@ typedef NS_ENUM(NSInteger, PushServicePlatform) {
445445
*/
446446
- (void)track:(NSString *)eventName dataFields:(nullable NSDictionary *)dataFields onSuccess:(OnSuccessHandler)onSuccess onFailure:(OnFailureHandler)onFailure;
447447

448+
/*!
449+
@method
450+
451+
@abstract Updates a user's subscription preferences
452+
453+
@param emailListIds Email lists to subscribe to
454+
@param unsubscribedChannelIds List of channels to unsubscribe from
455+
@param unsubscribedMessageTypeIds List of message types to unsubscribe from
456+
*/
457+
- (void)updateSubscriptions:(nullable NSArray *)emailListIds unsubscribedChannelIds:(nullable NSArray *)unsubscribedChannelIds unsubscribedMessageTypeIds:(nullable NSArray *)unsubscribedMessageTypeIds;
458+
448459
/////////////////////////
449460
/// @name In-App Notifications
450461
/////////////////////////

Iterable-iOS-SDK/IterableAPI.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,19 @@ typedef NS_ENUM(NSInteger, PushServicePlatform) {
445445
*/
446446
- (void)track:(NSString *)eventName dataFields:(nullable NSDictionary *)dataFields onSuccess:(OnSuccessHandler)onSuccess onFailure:(OnFailureHandler)onFailure;
447447

448+
/*!
449+
@method
450+
451+
@abstract Updates a user's subscription preferences
452+
453+
@param emailListIds Email lists to subscribe to
454+
@param unsubscribedChannelIds List of channels to unsubscribe from
455+
@param unsubscribedMessageTypeIds List of message types to unsubscribe from
456+
457+
@discussion passing in an empty array will clear subscription list, passing in nil will not modify the list
458+
*/
459+
- (void)updateSubscriptions:(nullable NSArray *)emailListIds unsubscribedChannelIds:(nullable NSArray *)unsubscribedChannelIds unsubscribedMessageTypeIds:(nullable NSArray *)unsubscribedMessageTypeIds;
460+
448461
/////////////////////////
449462
/// @name In-App Notifications
450463
/////////////////////////

Iterable-iOS-SDK/IterableAPI.m

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,21 @@ - (void)trackPurchase:(NSNumber *)total items:(NSArray<CommerceItem *> *)items d
860860
[self sendRequest:request onSuccess:onSuccess onFailure:onFailure];
861861
}
862862

863+
// documented in IterableAPI.h
864+
- (void)updateSubscriptions:(NSArray *)emailListIds unsubscribedChannelIds:(NSArray *)unsubscribedChannelIds unsubscribedMessageTypeIds:(NSArray *)unsubscribedMessageTypeIds
865+
{
866+
NSMutableDictionary *mutableDictionary = [[NSMutableDictionary alloc] init];
867+
868+
[self addEmailOrUserIdToDictionary:mutableDictionary];
869+
870+
[self tryAddValueToMutableDictionary:mutableDictionary key:ITBL_KEY_EMAIL_LIST_IDS value:emailListIds];
871+
[self tryAddValueToMutableDictionary:mutableDictionary key:ITBL_KEY_UNSUB_CHANNEL value:unsubscribedChannelIds];
872+
[self tryAddValueToMutableDictionary:mutableDictionary key:ITBL_KEY_UNSUB_MESSAGE value:unsubscribedMessageTypeIds];
873+
874+
NSURLRequest *request = [self createRequestForAction:ENDPOINT_UPDATE_SUBSCRIPTIONS withArgs:mutableDictionary];
875+
[self sendRequest:request onSuccess:[IterableAPI defaultOnSuccess:@"updateSubscriptions"] onFailure:[IterableAPI defaultOnFailure:@"updateSubscriptions"]];
876+
}
877+
863878
// documented in IterableAPI.h
864879
- (void)spawnInAppNotification:(ITEActionBlock)callbackBlock
865880
{
@@ -937,4 +952,40 @@ -(void) showSystemNotification:(NSString *)title body:(NSString *)body buttonLef
937952
[IterableInAppManager showSystemNotification:title body:body buttonLeft:buttonLeft buttonRight:buttonRight callbackBlock:callbackBlock];
938953
}
939954

955+
/*!
956+
@method
957+
958+
@abstract Helper function to add the email or userId to the dictionary
959+
960+
@param mutableDictionary the dictionary
961+
962+
*/
963+
- (void)addEmailOrUserIdToDictionary:(NSMutableDictionary *) mutableDictionary
964+
{
965+
if (mutableDictionary != nil) {
966+
if (self.email != nil) {
967+
[self tryAddValueToMutableDictionary:mutableDictionary key:ITBL_KEY_EMAIL value:self.email];
968+
} else {
969+
if (self.userId != nil) {
970+
[self tryAddValueToMutableDictionary:mutableDictionary key:ITBL_KEY_USER_ID value:self.userId];
971+
}
972+
}
973+
}
974+
}
975+
976+
/*!
977+
@method
978+
979+
@abstract Helper function to add a kvp to a dictionary
980+
981+
@param callbackBlock Callback ITEActionBlock
982+
983+
*/
984+
- (void)tryAddValueToMutableDictionary:(NSMutableDictionary *)mutableDictionary key:(NSString *)key value:(NSObject *)value
985+
{
986+
if (mutableDictionary != nil && value != nil && key != nil) {
987+
[mutableDictionary setObject:value forKey:key];
988+
}
989+
}
990+
940991
@end

Iterable-iOS-SDK/IterableConstants.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ extern NSString *const ITBL_KEY_CURRENT_EMAIL;
1717
extern NSString *const ITBL_KEY_DATA_FIELDS;
1818
extern NSString *const ITBL_KEY_DEVICE;
1919
extern NSString *const ITBL_KEY_EMAIL;
20+
extern NSString *const ITBL_KEY_EMAIL_LIST_IDS;
2021
extern NSString *const ITBL_KEY_EVENT_NAME;
2122
extern NSString *const ITBL_KEY_ITEMS;
2223
extern NSString *const ITBL_KEY_MERGE_NESTED;
@@ -29,6 +30,8 @@ extern NSString *const ITBL_KEY_SEND_AT;
2930
extern NSString *const ITBL_KEY_TOKEN;
3031
extern NSString *const ITBL_KEY_TEMPLATE_ID;
3132
extern NSString *const ITBL_KEY_TOTAL;
33+
extern NSString *const ITBL_KEY_UNSUB_CHANNEL;
34+
extern NSString *const ITBL_KEY_UNSUB_MESSAGE;
3235
extern NSString *const ITBL_KEY_USER;
3336
extern NSString *const ITBL_KEY_USER_ID;
3437

@@ -53,8 +56,9 @@ extern NSString *const ITBL_DEVICE_USER_INTERFACE;
5356
#define ENDPOINT_TRACK_INAPP_CLICK @"events/trackInAppClick"
5457
#define ENDPOINT_TRACK_INAPP_OPEN @"events/trackInAppOpen"
5558
#define ENDPOINT_TRACK_PUSH_OPEN @"events/trackPushOpen"
56-
#define ENDPOINT_UPDATE_EMAIL @"users/updateEmail"
5759
#define ENDPOINT_UPDATE_USER @"users/update"
60+
#define ENDPOINT_UPDATE_EMAIL @"users/updateEmail"
61+
#define ENDPOINT_UPDATE_SUBSCRIPTIONS @"users/updateSubscriptions"
5862

5963
//MISC
6064
#define ITBL_KEY_GET @"GET"

Iterable-iOS-SDK/IterableConstants.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ @implementation IterableConstants : NSObject
1919
NSString *const ITBL_KEY_DATA_FIELDS = @"dataFields";
2020
NSString *const ITBL_KEY_DEVICE = @"device";
2121
NSString *const ITBL_KEY_EMAIL = @"email";
22+
NSString *const ITBL_KEY_EMAIL_LIST_IDS = @"emailListIds";
2223
NSString *const ITBL_KEY_EVENT_NAME = @"eventName";
2324
NSString *const ITBL_KEY_INAPP_DISPLAY = @"inAppDisplaySettings";
2425
NSString *const ITBL_KEY_ITEMS = @"items";
@@ -32,6 +33,8 @@ @implementation IterableConstants : NSObject
3233
NSString *const ITBL_KEY_TOKEN = @"token";
3334
NSString *const ITBL_KEY_TEMPLATE_ID = @"templateId";
3435
NSString *const ITBL_KEY_TOTAL = @"total";
36+
NSString *const ITBL_KEY_UNSUB_CHANNEL = @"unsubscribedChannelIds";
37+
NSString *const ITBL_KEY_UNSUB_MESSAGE = @"unsubscribedMessageTypeIds";
3538
NSString *const ITBL_KEY_USER = @"user";
3639
NSString *const ITBL_KEY_USER_ID = @"userId";
3740

0 commit comments

Comments
 (0)