Skip to content

Commit 0092f1d

Browse files
committed
Fix updateSubscriptions signature and data types
1 parent ccfbbd5 commit 0092f1d

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

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

Lines changed: 8 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 campaignId = NSNumber(value: 23)
620+
let templateId = NSNumber(value: 10)
621+
let emailListIds = [NSNumber(value: 382)]
622+
let unsubscriptedChannelIds = [NSNumber(value: 7845), NSNumber(value: 1048)]
623+
let unsubscribedMessageTypeIds = [NSNumber(value: 5671), NSNumber(value: 9087)]
622624

623625
let networkSession = MockNetworkSession(statusCode: 200)
624626
networkSession.callback = {(_,_,_) in
@@ -629,6 +631,8 @@ class IterableAPITests: XCTestCase {
629631
queryParams: [])
630632

631633
let body = networkSession.getRequestBody() as! [String : Any]
634+
TestUtils.validateMatch(keyPath: KeyPath(AnyHashable.ITBL_KEY_CAMPAIGN_ID), value: campaignId, inDictionary: body)
635+
TestUtils.validateMatch(keyPath: KeyPath(AnyHashable.ITBL_KEY_TEMPLATE_ID), value: templateId, inDictionary: body)
632636
TestUtils.validateMatch(keyPath: KeyPath(AnyHashable.ITBL_KEY_EMAIL_LIST_IDS), value: emailListIds, inDictionary: body)
633637
TestUtils.validateMatch(keyPath: KeyPath(AnyHashable.ITBL_KEY_UNSUB_CHANNEL), value: unsubscriptedChannelIds, inDictionary: body)
634638
TestUtils.validateMatch(keyPath: KeyPath(AnyHashable.ITBL_KEY_UNSUB_MESSAGE), value: unsubscribedMessageTypeIds, inDictionary: body)
@@ -637,7 +641,7 @@ class IterableAPITests: XCTestCase {
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(campaignId: campaignId, templateId: templateId, emailListIds: emailListIds, unsubscribedChannelIds: unsubscriptedChannelIds, unsubscribedMessageTypeIds: unsubscribedMessageTypeIds, subscribedMessageTypeIds: nil)
641645
wait(for: [expectation1], timeout: testExpectationTimeout)
642646
}
643647

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: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,20 +383,34 @@ final class IterableAPIInternal : NSObject, PushTrackerProtocol {
383383
}
384384
}
385385

386-
func updateSubscriptions(_ emailListIds: [String]?, unsubscribedChannelIds: [String]?, unsubscribedMessageTypeIds: [String]?) {
386+
func updateSubscriptions(campaignId: NSNumber?, templateId: NSNumber?, emailListIds: [NSNumber]?, unsubscribedChannelIds: [NSNumber]?, unsubscribedMessageTypeIds: [NSNumber]?, subscribedMessageTypeIds: [NSNumber]?) {
387387
var dictionary = [AnyHashable : Any]()
388388
addEmailOrUserId(args: &dictionary)
389389

390+
if let campaignId = campaignId?.intValue {
391+
dictionary[.ITBL_KEY_CAMPAIGN_ID] = campaignId
392+
}
393+
394+
if let templateId = templateId?.intValue {
395+
dictionary[.ITBL_KEY_TEMPLATE_ID] = templateId
396+
}
397+
390398
if let emailListIds = emailListIds {
391399
dictionary[.ITBL_KEY_EMAIL_LIST_IDS] = emailListIds
392400
}
401+
393402
if let unsubscribedChannelIds = unsubscribedChannelIds {
394403
dictionary[.ITBL_KEY_UNSUB_CHANNEL] = unsubscribedChannelIds
395404
}
405+
396406
if let unsubscribedMessageTypeIds = unsubscribedMessageTypeIds {
397407
dictionary[.ITBL_KEY_UNSUB_MESSAGE] = unsubscribedMessageTypeIds
398408
}
399409

410+
if let subscribedMessageTypeIds = subscribedMessageTypeIds {
411+
dictionary[.ITBL_KEY_SUB_MESSAGE] = subscribedMessageTypeIds
412+
}
413+
400414
if let request = createPostRequest(forPath: .ITBL_PATH_UPDATE_SUBSCRIPTIONS, withBody: dictionary) {
401415
sendRequest(request, onSuccess: IterableAPIInternal.defaultOnSucess(identifier: "updateSubscriptions"), onFailure: IterableAPIInternal.defaultOnFailure(identifier: "updateSubscriptions"))
402416
}

swift-sdk/IterableAPI.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,8 @@ 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:templateId:emailListIds:unsubscribedChannelIds:unsubscribedMessageTypeIds:subscribedMessageTypeIds:) public static func updateSubscriptions(campaignId: NSNumber?, templateId: NSNumber?, emailListIds: [NSNumber]?, unsubscribedChannelIds: [NSNumber]?, unsubscribedMessageTypeIds: [NSNumber]?, subscribedMessageTypeIds: [NSNumber]?) {
357+
internalImplementation?.updateSubscriptions(campaignId: campaignId, templateId: templateId, emailListIds: emailListIds, unsubscribedChannelIds: unsubscribedChannelIds, unsubscribedMessageTypeIds: unsubscribedMessageTypeIds, subscribedMessageTypeIds: subscribedMessageTypeIds)
358358
}
359359

360360
//MARK: In-App Notifications

0 commit comments

Comments
 (0)