Skip to content

Commit 5768176

Browse files
authored
Merge pull request #249 from Iterable/MOB-1113-update-subscriptions
[MOB-1113] Fix updateSubscriptions signature and data types
2 parents ccfbbd5 + d27448a commit 5768176

File tree

4 files changed

+47
-7
lines changed

4 files changed

+47
-7
lines changed

Tests/swift-sdk-swift-tests/IterableAPITests.swift

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -616,9 +616,11 @@ class IterableAPITests: XCTestCase {
616616

617617
func testUpdateSubscriptions() {
618618
let expectation1 = expectation(description: "update subscriptions")
619-
let emailListIds = ["[email protected]"]
620-
let unsubscriptedChannelIds = ["channedl1", "channel2"]
621-
let unsubscribedMessageTypeIds = ["messageType1" ,"messageType2"]
619+
let emailListIds = [NSNumber(value: 382)]
620+
let unsubscriptedChannelIds = [NSNumber(value: 7845), NSNumber(value: 1048)]
621+
let unsubscribedMessageTypeIds = [NSNumber(value: 5671), NSNumber(value: 9087)]
622+
let campaignId = NSNumber(value: 23)
623+
let templateId = NSNumber(value: 10)
622624

623625
let networkSession = MockNetworkSession(statusCode: 200)
624626
networkSession.callback = {(_,_,_) in
@@ -632,12 +634,19 @@ class IterableAPITests: XCTestCase {
632634
TestUtils.validateMatch(keyPath: KeyPath(AnyHashable.ITBL_KEY_EMAIL_LIST_IDS), value: emailListIds, inDictionary: body)
633635
TestUtils.validateMatch(keyPath: KeyPath(AnyHashable.ITBL_KEY_UNSUB_CHANNEL), value: unsubscriptedChannelIds, inDictionary: body)
634636
TestUtils.validateMatch(keyPath: KeyPath(AnyHashable.ITBL_KEY_UNSUB_MESSAGE), value: unsubscribedMessageTypeIds, inDictionary: body)
637+
TestUtils.validateMatch(keyPath: KeyPath(AnyHashable.ITBL_KEY_CAMPAIGN_ID), value: campaignId, inDictionary: body)
638+
TestUtils.validateMatch(keyPath: KeyPath(AnyHashable.ITBL_KEY_TEMPLATE_ID), value: templateId, inDictionary: body)
635639
expectation1.fulfill()
636640
}
637641
let config = IterableConfig()
638642
TestUtils.getTestUserDefaults().set("[email protected]", forKey: .ITBL_USER_DEFAULTS_EMAIL_KEY)
639643
IterableAPI.initializeForTesting(apiKey: IterableAPITests.apiKey, config:config, networkSession: networkSession)
640-
IterableAPI.updateSubscriptions(emailListIds, unsubscribedChannelIds: unsubscriptedChannelIds, unsubscribedMessageTypeIds: unsubscribedMessageTypeIds)
644+
IterableAPI.updateSubscriptions(emailListIds,
645+
unsubscribedChannelIds: unsubscriptedChannelIds,
646+
unsubscribedMessageTypeIds: unsubscribedMessageTypeIds,
647+
subscribedMessageTypeIds: nil,
648+
campaignId: campaignId,
649+
templateId: templateId)
641650
wait(for: [expectation1], timeout: testExpectationTimeout)
642651
}
643652

swift-sdk/ITBConsts.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public extension AnyHashable {
6060
static let ITBL_KEY_TOTAL = "total"
6161
static let ITBL_KEY_UNSUB_CHANNEL = "unsubscribedChannelIds"
6262
static let ITBL_KEY_UNSUB_MESSAGE = "unsubscribedMessageTypeIds"
63+
static let ITBL_KEY_SUB_MESSAGE = "subscribedMessageTypeIds"
6364
static let ITBL_KEY_USER = "user"
6465
static let ITBL_KEY_USER_ID = "userId"
6566
static let ITBL_KEY_ACTION_IDENTIFIER = "actionIdentifier"

swift-sdk/Internal/IterableAPIInternal.swift

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,20 +383,39 @@ final class IterableAPIInternal : NSObject, PushTrackerProtocol {
383383
}
384384
}
385385

386-
func updateSubscriptions(_ emailListIds: [String]?, unsubscribedChannelIds: [String]?, unsubscribedMessageTypeIds: [String]?) {
386+
func updateSubscriptions(_ emailListIds: [NSNumber]? = nil,
387+
unsubscribedChannelIds: [NSNumber]? = nil,
388+
unsubscribedMessageTypeIds: [NSNumber]? = nil,
389+
subscribedMessageTypeIds: [NSNumber]? = nil,
390+
campaignId: NSNumber? = nil,
391+
templateId: NSNumber? = nil) {
387392
var dictionary = [AnyHashable : Any]()
388393
addEmailOrUserId(args: &dictionary)
389394

390395
if let emailListIds = emailListIds {
391396
dictionary[.ITBL_KEY_EMAIL_LIST_IDS] = emailListIds
392397
}
398+
393399
if let unsubscribedChannelIds = unsubscribedChannelIds {
394400
dictionary[.ITBL_KEY_UNSUB_CHANNEL] = unsubscribedChannelIds
395401
}
402+
396403
if let unsubscribedMessageTypeIds = unsubscribedMessageTypeIds {
397404
dictionary[.ITBL_KEY_UNSUB_MESSAGE] = unsubscribedMessageTypeIds
398405
}
399406

407+
if let subscribedMessageTypeIds = subscribedMessageTypeIds {
408+
dictionary[.ITBL_KEY_SUB_MESSAGE] = subscribedMessageTypeIds
409+
}
410+
411+
if let campaignId = campaignId?.intValue {
412+
dictionary[.ITBL_KEY_CAMPAIGN_ID] = campaignId
413+
}
414+
415+
if let templateId = templateId?.intValue {
416+
dictionary[.ITBL_KEY_TEMPLATE_ID] = templateId
417+
}
418+
400419
if let request = createPostRequest(forPath: .ITBL_PATH_UPDATE_SUBSCRIPTIONS, withBody: dictionary) {
401420
sendRequest(request, onSuccess: IterableAPIInternal.defaultOnSucess(identifier: "updateSubscriptions"), onFailure: IterableAPIInternal.defaultOnFailure(identifier: "updateSubscriptions"))
402421
}

swift-sdk/IterableAPI.swift

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,19 @@ public final class IterableAPI : NSObject {
353353

354354
- remark: passing in an empty array will clear subscription list, passing in nil will not modify the list
355355
*/
356-
@objc(updateSubscriptions:unsubscribedChannelIds:unsubscribedMessageTypeIds:) public static func updateSubscriptions(_ emailListIds: [String]?, unsubscribedChannelIds: [String]?, unsubscribedMessageTypeIds: [String]?) {
357-
internalImplementation?.updateSubscriptions(emailListIds, unsubscribedChannelIds: unsubscribedChannelIds, unsubscribedMessageTypeIds: unsubscribedMessageTypeIds)
356+
@objc(updateSubscriptions:unsubscribedChannelIds:unsubscribedMessageTypeIds:subscribedMessageTypeIds:campaignIds:templateId:)
357+
public static func updateSubscriptions(_ emailListIds: [NSNumber]?,
358+
unsubscribedChannelIds: [NSNumber]?,
359+
unsubscribedMessageTypeIds: [NSNumber]?,
360+
subscribedMessageTypeIds: [NSNumber]?,
361+
campaignId: NSNumber?,
362+
templateId: NSNumber?) {
363+
internalImplementation?.updateSubscriptions(emailListIds,
364+
unsubscribedChannelIds: unsubscribedChannelIds,
365+
unsubscribedMessageTypeIds: unsubscribedMessageTypeIds,
366+
subscribedMessageTypeIds: subscribedMessageTypeIds,
367+
campaignId: campaignId,
368+
templateId: templateId)
358369
}
359370

360371
//MARK: In-App Notifications

0 commit comments

Comments
 (0)