diff --git a/Gemfile b/Gemfile index 4ef40fcf..d5985c5f 100644 --- a/Gemfile +++ b/Gemfile @@ -2,4 +2,4 @@ source "https://rubygems.org" gem "cocoapods" gem "fastlane" -gem 'rexml', '3.3.8' +gem 'rexml', '3.3.9' diff --git a/Gemfile.lock b/Gemfile.lock index 7cf3445a..5b686feb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -252,7 +252,7 @@ GEM trailblazer-option (>= 0.1.1, < 0.2.0) uber (< 0.2.0) retriable (3.1.2) - rexml (3.3.8) + rexml (3.3.9) rouge (2.0.7) ruby-macho (2.5.1) ruby2_keywords (0.0.5) @@ -311,7 +311,7 @@ PLATFORMS DEPENDENCIES cocoapods fastlane - rexml (= 3.3.8) + rexml (= 3.3.9) BUNDLED WITH 2.5.22 diff --git a/PubNub.xcodeproj/project.pbxproj b/PubNub.xcodeproj/project.pbxproj index bde66ac1..0d38533b 100644 --- a/PubNub.xcodeproj/project.pbxproj +++ b/PubNub.xcodeproj/project.pbxproj @@ -280,7 +280,7 @@ 35CDFEBA22E77E2B00F3B9F2 /* URLSessionConfiguration+PubNubTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35CDFEB922E77E2B00F3B9F2 /* URLSessionConfiguration+PubNubTests.swift */; }; 35CDFEBC22E789B200F3B9F2 /* ConstantsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35CDFEBB22E789B200F3B9F2 /* ConstantsTests.swift */; }; 35CDFEC022E7B48000F3B9F2 /* ImportTestResource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35CDFEBF22E7B48000F3B9F2 /* ImportTestResource.swift */; }; - 35CF548C248971BF0099FE81 /* ObjectsUUIDRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35CF548B248971BF0099FE81 /* ObjectsUUIDRouter.swift */; }; + 35CF548C248971BF0099FE81 /* ObjectsUserRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35CF548B248971BF0099FE81 /* ObjectsUserRouter.swift */; }; 35CF548E248971CD0099FE81 /* ObjectsChannelRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35CF548D248971CD0099FE81 /* ObjectsChannelRouter.swift */; }; 35CF5490248971DD0099FE81 /* ObjectsMembershipsRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35CF548F248971DD0099FE81 /* ObjectsMembershipsRouter.swift */; }; 35CF54922489912F0099FE81 /* PubNubUserMetadata.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35CF54912489912F0099FE81 /* PubNubUserMetadata.swift */; }; @@ -288,7 +288,7 @@ 35CF54962489B3760099FE81 /* PubNubMembershipMetadata.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35CF54952489B3760099FE81 /* PubNubMembershipMetadata.swift */; }; 35CF549C248ABE8B0099FE81 /* PubNubObjectMetadataPatcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35CF549B248ABE8B0099FE81 /* PubNubObjectMetadataPatcher.swift */; }; 35CF549D248D73500099FE81 /* SubscribeObjectPayload.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35AC162C2485E3C600A66030 /* SubscribeObjectPayload.swift */; }; - 35CF549E248D913A0099FE81 /* ObjectsUUIDRouterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35DA9AB42335491F00867989 /* ObjectsUUIDRouterTests.swift */; }; + 35CF549E248D913A0099FE81 /* ObjectsUserRouterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35DA9AB42335491F00867989 /* ObjectsUserRouterTests.swift */; }; 35CF54A0248D96320099FE81 /* SubscribeRouterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 359287BC23173D490046F7A2 /* SubscribeRouterTests.swift */; }; 35CF54A1248DA6430099FE81 /* ObjectsChannelRouterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3562DBC22345066F006DFFBC /* ObjectsChannelRouterTests.swift */; }; 35CF54A3248DA8650099FE81 /* ObjectsMembershipsRouterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35CF54A2248DA8650099FE81 /* ObjectsMembershipsRouterTests.swift */; }; @@ -909,7 +909,7 @@ 35CDFEB922E77E2B00F3B9F2 /* URLSessionConfiguration+PubNubTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "URLSessionConfiguration+PubNubTests.swift"; sourceTree = ""; }; 35CDFEBB22E789B200F3B9F2 /* ConstantsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConstantsTests.swift; sourceTree = ""; }; 35CDFEBF22E7B48000F3B9F2 /* ImportTestResource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImportTestResource.swift; sourceTree = ""; }; - 35CF548B248971BF0099FE81 /* ObjectsUUIDRouter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ObjectsUUIDRouter.swift; sourceTree = ""; }; + 35CF548B248971BF0099FE81 /* ObjectsUserRouter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ObjectsUserRouter.swift; sourceTree = ""; }; 35CF548D248971CD0099FE81 /* ObjectsChannelRouter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ObjectsChannelRouter.swift; sourceTree = ""; }; 35CF548F248971DD0099FE81 /* ObjectsMembershipsRouter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ObjectsMembershipsRouter.swift; sourceTree = ""; }; 35CF54912489912F0099FE81 /* PubNubUserMetadata.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PubNubUserMetadata.swift; sourceTree = ""; }; @@ -934,7 +934,7 @@ 35DA9AAC2331674000867989 /* .swiftformat */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = .swiftformat; sourceTree = ""; }; 35DA9AB02334479800867989 /* objects_uuid_all_success.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = objects_uuid_all_success.json; path = Tests/PubNubTests/Mocking/Responses/Objects/objects_uuid_all_success.json; sourceTree = SOURCE_ROOT; }; 35DA9AB2233447F200867989 /* objects_uuid_fetch_success.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = objects_uuid_fetch_success.json; sourceTree = ""; }; - 35DA9AB42335491F00867989 /* ObjectsUUIDRouterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ObjectsUUIDRouterTests.swift; sourceTree = ""; }; + 35DA9AB42335491F00867989 /* ObjectsUserRouterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ObjectsUserRouterTests.swift; sourceTree = ""; }; 35DB0C4A2874768C001E1F76 /* FlatJSONCodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlatJSONCodable.swift; sourceTree = ""; }; 35DB0C4C287476BF001E1F76 /* OptionalChange.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OptionalChange.swift; sourceTree = ""; }; 35E381FC23149BA900A17549 /* AutomaticRetryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AutomaticRetryTests.swift; sourceTree = ""; }; @@ -1306,7 +1306,7 @@ 35293A792368F9680049A71F /* MessageActionsRouter.swift */, 35CF548D248971CD0099FE81 /* ObjectsChannelRouter.swift */, 35CF548F248971DD0099FE81 /* ObjectsMembershipsRouter.swift */, - 35CF548B248971BF0099FE81 /* ObjectsUUIDRouter.swift */, + 35CF548B248971BF0099FE81 /* ObjectsUserRouter.swift */, 35A6C77C22FB159F00E97CC5 /* PresenceRouter.swift */, 35A6C7A722FBCC8B00E97CC5 /* PushRouter.swift */, 3534D4E322C57659008E89FA /* PublishRouter.swift */, @@ -1716,7 +1716,7 @@ 359287B3231720C20046F7A2 /* PublishRouterTests.swift */, 359287BC23173D490046F7A2 /* SubscribeRouterTests.swift */, 3557CDFF237F6380004BBACC /* TimeRouterTests.swift */, - 35DA9AB42335491F00867989 /* ObjectsUUIDRouterTests.swift */, + 35DA9AB42335491F00867989 /* ObjectsUserRouterTests.swift */, 3562DBC22345066F006DFFBC /* ObjectsChannelRouterTests.swift */, 35CF54A2248DA8650099FE81 /* ObjectsMembershipsRouterTests.swift */, ); @@ -3604,7 +3604,7 @@ 3DBFF2BB2C203EDC00142985 /* KMPUploadable.swift in Sources */, 35A66A8022F861BA00AC67A9 /* AutomaticRetry.swift in Sources */, 357D1C1B22CB04C4003625BA /* Bool+PubNub.swift in Sources */, - 35CF548C248971BF0099FE81 /* ObjectsUUIDRouter.swift in Sources */, + 35CF548C248971BF0099FE81 /* ObjectsUserRouter.swift in Sources */, 3585033222CD138300A11D9A /* Set+PubNub.swift in Sources */, 358C641C238C5232009CE354 /* FCMAndroidPayload.swift in Sources */, 35FAC1E72357C2AE0096E418 /* PubNubError.swift in Sources */, @@ -3784,7 +3784,7 @@ 3D38A0102B35AF6B006928E7 /* SubscribeEffectsTests.swift in Sources */, 3D38A0142B35AF6B006928E7 /* PresenceTransitionTests.swift in Sources */, OBJ_49 /* PubNubTests.swift in Sources */, - 35CF549E248D913A0099FE81 /* ObjectsUUIDRouterTests.swift in Sources */, + 35CF549E248D913A0099FE81 /* ObjectsUserRouterTests.swift in Sources */, 3DB925642B7A2BF5001B7E90 /* SubscriptionSetTests.swift in Sources */, 35458BA3230CB3570085B502 /* SubscribeSessionFactoryTests.swift in Sources */, 3580A5A222F13C6500B12E5E /* SessionStreamAwait.swift in Sources */, diff --git a/PubNubSpace/Sources/Space+PubNub.swift b/PubNubSpace/Sources/Space+PubNub.swift index 01fbedb7..12b83d17 100644 --- a/PubNubSpace/Sources/Space+PubNub.swift +++ b/PubNubSpace/Sources/Space+PubNub.swift @@ -197,7 +197,7 @@ public extension PubNubSpaceInterface { ) { let router = ObjectsChannelRouter( .all( - include: PubNub.IncludeFields(custom: includeCustom).channelIncludeFields, + include: PubNub.ChannelIncludeFields(custom: includeCustom).includeFields, totalCount: includeTotalCount, filter: filter, sort: sort.map { $0.routerParameter }, @@ -229,7 +229,7 @@ public extension PubNubSpaceInterface { completion: @escaping (Result) -> Void ) { let router = ObjectsChannelRouter( - .fetch(metadataId: spaceId, include: PubNub.IncludeFields(custom: includeCustom).channelIncludeFields), + .fetch(metadataId: spaceId, include: PubNub.ChannelIncludeFields(custom: includeCustom).includeFields), configuration: requestConfig.customConfiguration ?? configuration ) @@ -265,7 +265,7 @@ public extension PubNubSpaceInterface { channelDescription: description, custom: custom?.flatJSON ), - include: PubNub.IncludeFields(custom: includeCustom).channelIncludeFields + include: PubNub.ChannelIncludeFields(custom: includeCustom).includeFields ), configuration: requestConfig.customConfiguration ?? configuration ) diff --git a/PubNubUser/Sources/PubNubUser.swift b/PubNubUser/Sources/PubNubUser.swift index 189cf603..b3914230 100644 --- a/PubNubUser/Sources/PubNubUser.swift +++ b/PubNubUser/Sources/PubNubUser.swift @@ -140,7 +140,7 @@ extension PubNubUser: Codable { // MARK: Object v2 Migration public extension PubNubUserMetadata { - /// Converts Object V2 UUID Metadata to a Space entity + /// Converts Object V2 User Metadata to a User entity /// /// - returns: The `PubNubUser` built from the Object V2 data func convert() -> PubNubUser { diff --git a/PubNubUser/Sources/User+PubNub.swift b/PubNubUser/Sources/User+PubNub.swift index f243f14f..2d40b826 100644 --- a/PubNubUser/Sources/User+PubNub.swift +++ b/PubNubUser/Sources/User+PubNub.swift @@ -203,9 +203,9 @@ public extension PubNubUserInterface { requestConfig: PubNub.RequestConfiguration = .init(), completion: @escaping ((Result<(users: [PubNubUser], next: PubNubHashedPage?), Error>) -> Void) ) { - let router = ObjectsUUIDRouter( + let router = ObjectsUserRouter( .all( - include: PubNub.IncludeFields(custom: includeCustom).userIncludeFields, + include: PubNub.UserIncludeFields(custom: includeCustom).includeFields, totalCount: includeTotalCount, filter: filter, sort: sort.map { $0.routerParameter }, @@ -226,7 +226,7 @@ public extension PubNubUserInterface { completion(result.map { ( users: $0.payload.data, next: PubNub.Page(next: $0.payload.next, prev: $0.payload.prev, totalCount: $0.payload.totalCount) - ) }) + )}) } } @@ -236,10 +236,10 @@ public extension PubNubUserInterface { requestConfig: PubNub.RequestConfiguration = .init(), completion: @escaping (Result) -> Void ) { - let router = ObjectsUUIDRouter( + let router = ObjectsUserRouter( .fetch( metadataId: userId ?? (requestConfig.customConfiguration?.uuid ?? configuration.uuid), - include: PubNub.IncludeFields(custom: includeCustom).userIncludeFields + include: PubNub.UserIncludeFields(custom: includeCustom).includeFields ), configuration: requestConfig.customConfiguration ?? configuration ) @@ -268,7 +268,7 @@ public extension PubNubUserInterface { requestConfig: PubNub.RequestConfiguration = .init(), completion: ((Result) -> Void)? ) { - let router = ObjectsUUIDRouter( + let router = ObjectsUserRouter( .set( metadata: PubNubUserMetadataBase( metadataId: userId ?? (requestConfig.customConfiguration?.uuid ?? configuration.uuid), @@ -280,7 +280,7 @@ public extension PubNubUserInterface { email: email, custom: custom?.flatJSON ), - include: PubNub.IncludeFields(custom: includeCustom).userIncludeFields + include: PubNub.UserIncludeFields(custom: includeCustom).includeFields ), configuration: requestConfig.customConfiguration ?? configuration ) @@ -329,7 +329,7 @@ public extension PubNubUserInterface { requestConfig: PubNub.RequestConfiguration = .init(), completion: ((Result) -> Void)? ) { - let router = ObjectsUUIDRouter( + let router = ObjectsUserRouter( .remove(metadataId: userId ?? (requestConfig.customConfiguration?.uuid ?? configuration.uuid)), configuration: requestConfig.customConfiguration ?? configuration ) diff --git a/PubNubUser/Tests/Test+PubNubUserInterface.swift b/PubNubUser/Tests/Test+PubNubUserInterface.swift index 69dcee49..288d3138 100644 --- a/PubNubUser/Tests/Test+PubNubUserInterface.swift +++ b/PubNubUser/Tests/Test+PubNubUserInterface.swift @@ -101,7 +101,7 @@ class PubNubUserInterfaceTests: XCTestCase { func testUser_FetchUsers() { let expectation = XCTestExpectation(description: "Fetch Users API") - let testRouterEndpoint = ObjectsUUIDRouter.Endpoint.all( + let testRouterEndpoint = ObjectsUserRouter.Endpoint.all( customFields: true, totalCount: true, filter: nil, @@ -113,7 +113,7 @@ class PubNubUserInterfaceTests: XCTestCase { // Validate Inputs mockSession.validateRouter = { router in - XCTAssertEqual(testRouterEndpoint, (router as? ObjectsUUIDRouter)?.endpoint) + XCTAssertEqual(testRouterEndpoint, (router as? ObjectsUserRouter)?.endpoint) } // Provide Output @@ -141,14 +141,14 @@ class PubNubUserInterfaceTests: XCTestCase { func testUser_FetchUser_ConfigUserId() { let expectation = XCTestExpectation(description: "Fetch User API") - let testRouterEndpoint = ObjectsUUIDRouter.Endpoint.fetch( + let testRouterEndpoint = ObjectsUserRouter.Endpoint.fetch( metadataId: pubnub.configuration.userId, customFields: true ) // Validate Inputs mockSession.validateRouter = { router in - XCTAssertEqual(testRouterEndpoint, (router as? ObjectsUUIDRouter)?.endpoint) + XCTAssertEqual(testRouterEndpoint, (router as? ObjectsUserRouter)?.endpoint) } // Provide Output @@ -173,7 +173,7 @@ class PubNubUserInterfaceTests: XCTestCase { func testUser_CreateUser() { let expectation = XCTestExpectation(description: "Fetch User API") - let testRouterEndpoint = ObjectsUUIDRouter.Endpoint.set( + let testRouterEndpoint = ObjectsUserRouter.Endpoint.set( metadata: PubNubUserMetadataBase( metadataId: pubnub.configuration.userId, name: testUser.name, @@ -191,7 +191,7 @@ class PubNubUserInterfaceTests: XCTestCase { // Validate Inputs mockSession.validateRouter = { router in - XCTAssertEqual(testRouterEndpoint, (router as? ObjectsUUIDRouter)?.endpoint) + XCTAssertEqual(testRouterEndpoint, (router as? ObjectsUserRouter)?.endpoint) } // Provide Output @@ -227,7 +227,7 @@ class PubNubUserInterfaceTests: XCTestCase { func testUser_UpdateUser() { let expectation = XCTestExpectation(description: "Fetch User API") - let testRouterEndpoint = ObjectsUUIDRouter.Endpoint.set( + let testRouterEndpoint = ObjectsUserRouter.Endpoint.set( metadata: PubNubUserMetadataBase( metadataId: pubnub.configuration.userId, name: testUser.name, @@ -245,7 +245,7 @@ class PubNubUserInterfaceTests: XCTestCase { // Validate Inputs mockSession.validateRouter = { router in - XCTAssertEqual(testRouterEndpoint, (router as? ObjectsUUIDRouter)?.endpoint) + XCTAssertEqual(testRouterEndpoint, (router as? ObjectsUserRouter)?.endpoint) } // Provide Output @@ -281,13 +281,13 @@ class PubNubUserInterfaceTests: XCTestCase { func testUser_RemoveUser() { let expectation = XCTestExpectation(description: "Fetch User API") - let testRouterEndpoint = ObjectsUUIDRouter.Endpoint.remove( + let testRouterEndpoint = ObjectsUserRouter.Endpoint.remove( metadataId: pubnub.configuration.uuid ) // Validate Inputs mockSession.validateRouter = { router in - XCTAssertEqual(testRouterEndpoint, (router as? ObjectsUUIDRouter)?.endpoint) + XCTAssertEqual(testRouterEndpoint, (router as? ObjectsUserRouter)?.endpoint) } // Provide Output diff --git a/Sources/PubNub/APIs/Objects+PubNub.swift b/Sources/PubNub/APIs/Objects+PubNub.swift index 159ad234..3a106342 100644 --- a/Sources/PubNub/APIs/Objects+PubNub.swift +++ b/Sources/PubNub/APIs/Objects+PubNub.swift @@ -190,6 +190,8 @@ public extension PubNub { } } + // swiftlint:disable:next line_length + @available(*, deprecated, message: "Will be replaced with PubNub.UserIncludeFields and PubNub.ChannelIncludeFields for the User and Channel methods, respectively") /// Fields that include additional data inside the response for Channel or User metadata struct IncludeFields: Hashable { /// The `custom` dictionary for the Object @@ -205,37 +207,99 @@ public extension PubNub { /// /// - Parameters: /// - custom: Whether to include `custom` data in the response + /// - type: Whether to include `type` in the response + /// - status: Whether to include `status` field in the response /// - totalCount: Whether to include `totalCount` in the response - /// - typeField: Whether to include `type` in the response - /// - statusField: Whether to include `status` field in the response public init( custom: Bool = true, type: Bool = true, status: Bool = true, totalCount: Bool = true ) { - customFields = custom - typeField = type - statusField = status + self.customFields = custom + self.typeField = type + self.statusField = status self.totalCount = totalCount } + } - public var userIncludeFields: [ObjectsUUIDRouter.Include]? { - var includes = [ObjectsUUIDRouter.Include]() + /// Fields that include additional data inside the response for User metadata + struct UserIncludeFields: Hashable { + /// The `custom` dictionary for the Object + public var custom: Bool + /// The `type` field for the Object + public var type: Bool + /// The `status` field for the Object + public var status: Bool + /// The `totalCount` of how many Objects are available + public var totalCount: Bool - if customFields { includes.append(.custom) } - if statusField { includes.append(.status) } - if typeField { includes.append(.type) } + /// Default init + /// + /// - Parameters: + /// - custom: Whether to include `custom` data in the response + /// - status: Whether to include `status` field in the response + /// - type: Whether to include `type` in the response + /// - totalCount: Whether to include `totalCount` in the response + public init( + custom: Bool = true, + type: Bool = true, + status: Bool = true, + totalCount: Bool = true + ) { + self.custom = custom + self.type = type + self.status = status + self.totalCount = totalCount + } + + public var includeFields: [ObjectsUserRouter.Include]? { + var includes = [ObjectsUserRouter.Include]() + + if custom { includes.append(.custom) } + if status { includes.append(.status) } + if type { includes.append(.type) } return includes.isEmpty ? nil : includes } + } - public var channelIncludeFields: [ObjectsChannelRouter.Include]? { + /// Fields that include additional data inside the response for Channel metadata + struct ChannelIncludeFields: Hashable { + /// The `custom` dictionary for the Object + public var custom: Bool + /// The `type` field for the Object + public var type: Bool + /// The `status` field for the Object + public var status: Bool + /// The `totalCount` of how many Objects are available + public var totalCount: Bool + + /// Default init + /// + /// - Parameters: + /// - custom: Whether to include `custom` data in the response + /// - status: Whether to include `status` field in the response + /// - type: Whether to include `type` in the response + /// - totalCount: Whether to include `totalCount` in the response + public init( + custom: Bool = true, + type: Bool = true, + status: Bool = true, + totalCount: Bool = true + ) { + self.custom = custom + self.type = type + self.status = status + self.totalCount = totalCount + } + + public var includeFields: [ObjectsChannelRouter.Include]? { var includes = [ObjectsChannelRouter.Include]() - if customFields { includes.append(.custom) } - if statusField { includes.append(.status) } - if typeField { includes.append(.type) } + if custom { includes.append(.custom) } + if status { includes.append(.status) } + if type { includes.append(.type) } return includes.isEmpty ? nil : includes } @@ -288,7 +352,6 @@ extension Array where Element == PubNub.MembershipSortField { // MARK: - User Metadata Objects public extension PubNub { - @available(*, deprecated, renamed: "allUserMetadata(include:filter:sort:limit:page:custom:completion:)") /// Gets metadata for all Users. /// /// Returns a paginated list of User Metadata objects, optionally including the custom data object for each. @@ -303,6 +366,7 @@ public extension PubNub { /// - completion: The async `Result` of the method call /// - **Success**: A `Tuple` containing an `Array` of `PubNubUserMetadata`, and the next pagination `PubNubHashedPage` (if one exists) /// - **Failure**: An `Error` describing the failure + @available(*, deprecated, renamed: "allUserMetadata(include:filter:sort:limit:page:custom:completion:)") func allUUIDMetadata( include: IncludeFields = IncludeFields(), filter: String? = nil, @@ -313,7 +377,12 @@ public extension PubNub { completion: ((Result<(uuids: [PubNubUserMetadata], next: PubNubHashedPage?), Error>) -> Void)? ) { allUserMetadata( - include: include, + include: UserIncludeFields( + custom: include.customFields, + type: include.typeField, + status: include.statusField, + totalCount: include.totalCount + ), filter: filter, sort: sort, limit: limit, @@ -344,7 +413,7 @@ public extension PubNub { /// - **Success**: A `Tuple` containing an `Array` of `PubNubUserMetadata`, and the next pagination `PubNubHashedPage` (if one exists) /// - **Failure**: An `Error` describing the failure func allUserMetadata( - include: IncludeFields = IncludeFields(), + include: UserIncludeFields = UserIncludeFields(), filter: String? = nil, sort: [ObjectSortField] = [], limit: Int? = 100, @@ -352,9 +421,9 @@ public extension PubNub { custom requestConfig: RequestConfiguration = RequestConfiguration(), completion: ((Result<(users: [PubNubUserMetadata], next: PubNubHashedPage?), Error>) -> Void)? ) { - let router = ObjectsUUIDRouter( + let router = ObjectsUserRouter( .all( - include: include.userIncludeFields, + include: include.includeFields, totalCount: include.totalCount, filter: filter, sort: sort.urlValue, @@ -379,7 +448,6 @@ public extension PubNub { } } - @available(*, deprecated, renamed: "fetchUserMetadata(_:include:custom:completion:)") /// Get Metadata for a User. /// /// Returns metadata for the specified User, optionally including the custom data object for each. @@ -391,6 +459,7 @@ public extension PubNub { /// - completion: The async `Result` of the method call /// - **Success**: The `PubNubUserMetadata` object belonging to the identifier /// - **Failure**: An `Error` describing the failure + @available(*, deprecated, renamed: "fetchUserMetadata(_:include:custom:completion:)") func fetch( uuid metadataId: String?, include customFields: Bool = true, @@ -399,7 +468,7 @@ public extension PubNub { ) { fetchUserMetadata( metadataId, - include: IncludeFields(custom: customFields), + include: UserIncludeFields(custom: customFields), custom: requestConfig, completion: completion ) @@ -418,14 +487,14 @@ public extension PubNub { /// - **Failure**: An `Error` describing the failure func fetchUserMetadata( _ metadataId: String?, - include: IncludeFields = IncludeFields(), + include: UserIncludeFields = UserIncludeFields(), custom requestConfig: RequestConfiguration = RequestConfiguration(), completion: ((Result) -> Void)? ) { - let router = ObjectsUUIDRouter( + let router = ObjectsUserRouter( .fetch( metadataId: metadataId ?? (requestConfig.customConfiguration?.uuid ?? configuration.uuid), - include: include.userIncludeFields + include: include.includeFields ), configuration: requestConfig.customConfiguration ?? configuration ) @@ -439,7 +508,6 @@ public extension PubNub { } } - @available(*, deprecated, renamed: "setUserMetadata(_:include:custom:completion:)") /// Set User Metadata. /// /// Set metadata for a User in the database, optionally including the custom data object for each. @@ -450,6 +518,7 @@ public extension PubNub { /// - completion: The async `Result` of the method call /// - **Success**: The `PubNubUserMetadata` containing the set changes /// - **Failure**: An `Error` describing the failure + @available(*, deprecated, renamed: "setUserMetadata(_:include:custom:completion:)") func set( uuid metadata: PubNubUserMetadata, include customFields: Bool = true, @@ -458,7 +527,7 @@ public extension PubNub { ) { setUserMetadata( metadata, - include: IncludeFields(custom: customFields), + include: UserIncludeFields(custom: customFields), custom: requestConfig, completion: completion ) @@ -476,14 +545,14 @@ public extension PubNub { /// - **Failure**: An `Error` describing the failure func setUserMetadata( _ metadata: PubNubUserMetadata, - include: IncludeFields = IncludeFields(), + include: UserIncludeFields = UserIncludeFields(), custom requestConfig: RequestConfiguration = RequestConfiguration(), completion: ((Result) -> Void)? ) { - let router = ObjectsUUIDRouter( + let router = ObjectsUserRouter( .set( metadata: metadata, - include: include.userIncludeFields + include: include.includeFields ), configuration: requestConfig.customConfiguration ?? configuration ) @@ -497,7 +566,6 @@ public extension PubNub { } } - @available(*, deprecated, renamed: "remove(user:custom:completion:)") /// Remove metadata for a specified User. /// /// - Parameters: @@ -506,6 +574,7 @@ public extension PubNub { /// - completion: The async `Result` of the method call /// - **Success**: The User identifier of the removed object /// - **Failure**: An `Error` describing the failure + @available(*, deprecated, renamed: "removeUserMetadata(_:custom:completion:)") func remove( uuid metadataId: String?, custom requestConfig: RequestConfiguration = RequestConfiguration(), @@ -534,7 +603,7 @@ public extension PubNub { // Capture the response or current configuration uuid let metadataId = metadataId ?? (requestConfig.customConfiguration?.uuid ?? configuration.uuid) - let router = ObjectsUUIDRouter( + let router = ObjectsUserRouter( .remove(metadataId: metadataId), configuration: requestConfig.customConfiguration ?? configuration ) @@ -574,9 +643,15 @@ public extension PubNub { custom requestConfig: RequestConfiguration = RequestConfiguration(), completion: ((Result<(channels: [PubNubChannelMetadata], next: PubNubHashedPage?), Error>) -> Void)? ) { + let channelIncludeFields = ChannelIncludeFields( + custom: include.customFields, + type: include.typeField, + status: include.statusField, + totalCount: include.totalCount + ) let router = ObjectsChannelRouter( .all( - include: include.channelIncludeFields, + include: channelIncludeFields.includeFields, totalCount: include.totalCount, filter: filter, sort: sort.map { "\($0.property.rawValue)\($0.ascending ? "" : ":desc")" }, @@ -601,7 +676,6 @@ public extension PubNub { } } - @available(*, deprecated, renamed: "fetchChannelMetadata(_:include:custom:completion:)") /// Returns metadata for the specified channel including the channel's custom data. /// /// - Parameters: @@ -611,6 +685,7 @@ public extension PubNub { /// - completion: The async `Result` of the method call /// - **Success**: The `PubNubChannelMetadata` object belonging to the identifier /// - **Failure**: An `Error` describing the failure + @available(*, deprecated, renamed: "fetchChannelMetadata(_:include:custom:completion:)") func fetch( channel metadataId: String, include customFields: Bool = true, @@ -619,7 +694,7 @@ public extension PubNub { ) { fetchChannelMetadata( metadataId, - include: IncludeFields(custom: customFields), + include: ChannelIncludeFields(custom: customFields), custom: requestConfig, completion: completion ) @@ -636,14 +711,14 @@ public extension PubNub { /// - **Failure**: An `Error` describing the failure func fetchChannelMetadata( _ metadataId: String, - include: IncludeFields = IncludeFields(), + include: ChannelIncludeFields = ChannelIncludeFields(), custom requestConfig: RequestConfiguration = RequestConfiguration(), completion: ((Result) -> Void)? ) { let router = ObjectsChannelRouter( .fetch( metadataId: metadataId, - include: include.channelIncludeFields + include: include.includeFields ), configuration: requestConfig.customConfiguration ?? configuration ) @@ -657,7 +732,6 @@ public extension PubNub { } } - @available(*, deprecated, renamed: "setChannelMetadata(_:include:custom:completion:)") /// Set metadata for a channel in the database. /// /// - Parameters: @@ -667,6 +741,7 @@ public extension PubNub { /// - completion: The async `Result` of the method call /// - **Success**: The `PubNubChannelMetadata` containing the set changes /// - **Failure**: An `Error` describing the failure + @available(*, deprecated, renamed: "setChannelMetadata(_:include:custom:completion:)") func set( channel metadata: PubNubChannelMetadata, include customFields: Bool = true, @@ -675,7 +750,7 @@ public extension PubNub { ) { setChannelMetadata( metadata, - include: IncludeFields(custom: customFields), + include: ChannelIncludeFields(custom: customFields), custom: requestConfig, completion: completion ) @@ -692,15 +767,12 @@ public extension PubNub { /// - **Failure**: An `Error` describing the failure func setChannelMetadata( _ metadata: PubNubChannelMetadata, - include: IncludeFields = IncludeFields(), + include: ChannelIncludeFields = ChannelIncludeFields(), custom requestConfig: RequestConfiguration = RequestConfiguration(), completion: ((Result) -> Void)? ) { let router = ObjectsChannelRouter( - .set( - metadata: metadata, - include: include.channelIncludeFields - ), + .set(metadata: metadata, include: include.includeFields), configuration: requestConfig.customConfiguration ?? configuration ) @@ -1023,8 +1095,6 @@ public extension PubNub { ) } - // swiftlint:disable:next line_length - @available(*, deprecated, renamed: "manageMemberships(userId:setting:removing:include:filter:sort:limit:page:custom:completion:)") /// Modify the Channel membership list for a User. /// /// - Parameters: @@ -1040,6 +1110,8 @@ public extension PubNub { /// - completion: The async `Result` of the method call /// - **Success**: A `Tuple` containing an `Array` of `PubNubMembershipMetadata`, and the next pagination `PubNubHashedPage` (if one exists) /// - **Failure**: An `Error` describing the failure + @available(*, deprecated, renamed: "manageMemberships(userId:setting:removing:include:filter:sort:limit:page:custom:completion:)") + // swiftlint:disable:previous line_length func manageMemberships( uuid: String?, setting channelMembershipSets: [PubNubMembershipMetadata], @@ -1123,7 +1195,6 @@ public extension PubNub { } } - @available(*, deprecated, renamed: "setMembers(channels:users:include:filter:sort:limit:page:custom:completion:)") /// Set the specified user's space memberships. /// /// - Parameters: @@ -1138,6 +1209,7 @@ public extension PubNub { /// - completion: The async `Result` of the method call /// - **Success**: A `Tuple` containing an `Array` of `PubNubMembershipMetadata`, and the next pagination `PubNubHashedPage` (if one exists) /// - **Failure**: An `Error` describing the failure + @available(*, deprecated, renamed: "setMembers(channels:users:include:filter:sort:limit:page:custom:completion:)") func setMembers( channel metadataId: String, uuids members: [PubNubMembershipMetadata], diff --git a/Sources/PubNub/KMP/KMPPubNub+AppContext.swift b/Sources/PubNub/KMP/KMPPubNub+AppContext.swift index 9238446d..a4028002 100644 --- a/Sources/PubNub/KMP/KMPPubNub+AppContext.swift +++ b/Sources/PubNub/KMP/KMPPubNub+AppContext.swift @@ -121,7 +121,7 @@ public extension KMPPubNub { onSuccess: @escaping ((KMPChannelMetadata) -> Void), onFailure: @escaping ((Error) -> Void) ) { - pubnub.fetchChannelMetadata(metadataId, include: PubNub.IncludeFields(custom: includeCustom)) { + pubnub.fetchChannelMetadata(metadataId, include: PubNub.ChannelIncludeFields(custom: includeCustom)) { switch $0 { case .success(let metadata): onSuccess(KMPChannelMetadata(metadata: metadata)) @@ -150,7 +150,7 @@ public extension KMPPubNub { channelDescription: description, custom: convertDictionaryToScalars(custom?.asMap()) ) - pubnub.setChannelMetadata(channelMetadata, include: PubNub.IncludeFields(custom: includeCustom)) { + pubnub.setChannelMetadata(channelMetadata, include: PubNub.ChannelIncludeFields(custom: includeCustom)) { switch $0 { case .success(let metadata): onSuccess(KMPChannelMetadata(metadata: metadata)) @@ -186,7 +186,7 @@ public extension KMPPubNub { onFailure: @escaping ((Error) -> Void) ) { pubnub.allUserMetadata( - include: PubNub.IncludeFields(custom: includeCustom, totalCount: includeCount), + include: PubNub.UserIncludeFields(custom: includeCustom, totalCount: includeCount), filter: filter, sort: objectSortProperties(from: sort), limit: limit?.intValue, @@ -211,7 +211,7 @@ public extension KMPPubNub { onSuccess: @escaping ((KMPUserMetadata) -> Void), onFailure: @escaping ((Error) -> Void) ) { - pubnub.fetchUserMetadata(metadataId, include: PubNub.IncludeFields(custom: includeCustom)) { + pubnub.fetchUserMetadata(metadataId, include: PubNub.UserIncludeFields(custom: includeCustom)) { switch $0 { case .success(let metadata): onSuccess(KMPUserMetadata(metadata: metadata)) @@ -246,7 +246,7 @@ public extension KMPPubNub { ) pubnub.setUserMetadata( userMetadata, - include: PubNub.IncludeFields(custom: includeCustom) + include: PubNub.UserIncludeFields(custom: includeCustom) ) { switch $0 { case .success(let metadata): diff --git a/Sources/PubNub/Models/PubNubMembershipMetadata.swift b/Sources/PubNub/Models/PubNubMembershipMetadata.swift index 78ddf9c4..fc2fc383 100644 --- a/Sources/PubNub/Models/PubNubMembershipMetadata.swift +++ b/Sources/PubNub/Models/PubNubMembershipMetadata.swift @@ -83,7 +83,7 @@ public struct PubNubMembershipMetadataBase: PubNubMembershipMetadata, Hashable { /// The caching identifier for the object public var eTag: String? - var concreteUUID: PubNubUserMetadataBase? + var concreteUser: PubNubUserMetadataBase? var concreteChannel: PubNubChannelMetadataBase? var concreteCustom: [String: JSONCodableScalarType]? @@ -107,8 +107,8 @@ public struct PubNubMembershipMetadataBase: PubNubMembershipMetadata, Hashable { @available(*, deprecated, renamed: "user") public var uuid: PubNubUserMetadata? { - get { concreteUUID } - set { concreteUUID = try? newValue?.transcode() } + get { concreteUser } + set { concreteUser = try? newValue?.transcode() } } public var channel: PubNubChannelMetadata? { @@ -244,12 +244,12 @@ extension PubNubMembershipMetadataBase: Codable { } if let concreteUUID = try? container.decodeIfPresent(PubNubUserMetadataBase.self, forKey: .uuid) { - self.concreteUUID = concreteUUID + self.concreteUser = concreteUUID uuidMetadataId = concreteUUID.metadataId } else { let uuidContainer = try container.nestedContainer(keyedBy: NestedCodingKeys.self, forKey: .uuid) uuidMetadataId = try uuidContainer.decode(String.self, forKey: .id) - concreteUUID = nil + concreteUser = nil } } @@ -268,7 +268,7 @@ extension PubNubMembershipMetadataBase: Codable { try channelContainer.encode(channelMetadataId, forKey: .id) } - if let uuidObject = concreteUUID { + if let uuidObject = concreteUser { try container.encode(uuidObject, forKey: .uuid) } else { var uuidContainer = container.nestedContainer(keyedBy: NestedCodingKeys.self, forKey: .uuid) diff --git a/Sources/PubNub/Networking/Routers/ObjectsChannelRouter.swift b/Sources/PubNub/Networking/Routers/ObjectsChannelRouter.swift index 22f01233..bd126a93 100644 --- a/Sources/PubNub/Networking/Routers/ObjectsChannelRouter.swift +++ b/Sources/PubNub/Networking/Routers/ObjectsChannelRouter.swift @@ -94,18 +94,18 @@ public struct ObjectsChannelRouter: HTTPRouter { var query = defaultQueryItems switch endpoint { - case let .all(customFields, totalCount, filter, sort, limit, start, end): + case let .all(includeFields, totalCount, filter, sort, limit, start, end): query.appendIfPresent(key: .filter, value: filter) query.appendIfNotEmpty(key: .sort, value: sort) query.appendIfPresent(key: .limit, value: limit?.description) - query.appendIfPresent(key: .include, value: Include.includes(from: customFields)) + query.appendIfPresent(key: .include, value: Include.includes(from: includeFields)) query.appendIfPresent(key: .count, value: totalCount ? totalCount.description : nil) query.appendIfPresent(key: .start, value: start?.description) query.appendIfPresent(key: .end, value: end?.description) - case let .fetch(_, customFields): - query.appendIfPresent(key: .include, value: Include.includes(from: customFields)) - case let .set(_, customFields): - query.appendIfPresent(key: .include, value: Include.includes(from: customFields)) + case let .fetch(_, includeFields): + query.appendIfPresent(key: .include, value: Include.includes(from: includeFields)) + case let .set(_, includeFields): + query.appendIfPresent(key: .include, value: Include.includes(from: includeFields)) case .remove: break } diff --git a/Sources/PubNub/Networking/Routers/ObjectsUUIDRouter.swift b/Sources/PubNub/Networking/Routers/ObjectsUserRouter.swift similarity index 97% rename from Sources/PubNub/Networking/Routers/ObjectsUUIDRouter.swift rename to Sources/PubNub/Networking/Routers/ObjectsUserRouter.swift index de7fa256..0a9a8f70 100644 --- a/Sources/PubNub/Networking/Routers/ObjectsUUIDRouter.swift +++ b/Sources/PubNub/Networking/Routers/ObjectsUserRouter.swift @@ -10,7 +10,7 @@ import Foundation -public struct ObjectsUUIDRouter: HTTPRouter { +public struct ObjectsUserRouter: HTTPRouter { public enum Endpoint: CustomStringConvertible { case all(include: [Include]?, totalCount: Bool, filter: String?, sort: [String], limit: Int?, start: String?, end: String?) case fetch(metadataId: String, include: [Include]?) @@ -165,9 +165,9 @@ public struct ObjectsUUIDRouter: HTTPRouter { } } -extension ObjectsUUIDRouter.Endpoint: Equatable { +extension ObjectsUserRouter.Endpoint: Equatable { public static func == ( - lhs: ObjectsUUIDRouter.Endpoint, rhs: ObjectsUUIDRouter.Endpoint + lhs: ObjectsUserRouter.Endpoint, rhs: ObjectsUserRouter.Endpoint ) -> Bool { switch (lhs, rhs) { case let (.all(lhs1, lhs2, lhs3, lhs4, lhs5, lhs6, lhs7), .all(rhs1, rhs2, rhs3, rhs4, rhs5, rhs6, rhs7)): diff --git a/Tests/PubNubTests/Networking/Routers/ObjectsUUIDRouterTests.swift b/Tests/PubNubTests/Networking/Routers/ObjectsUserRouterTests.swift similarity index 97% rename from Tests/PubNubTests/Networking/Routers/ObjectsUUIDRouterTests.swift rename to Tests/PubNubTests/Networking/Routers/ObjectsUserRouterTests.swift index f41cd1d9..b474b54c 100644 --- a/Tests/PubNubTests/Networking/Routers/ObjectsUUIDRouterTests.swift +++ b/Tests/PubNubTests/Networking/Routers/ObjectsUserRouterTests.swift @@ -11,7 +11,7 @@ @testable import PubNubSDK import XCTest -final class ObjectsUUIDRouterTests: XCTestCase { +final class ObjectsUserRouterTests: XCTestCase { let config = PubNubConfiguration(publishKey: "FakeTestString", subscribeKey: "FakeTestString", userId: UUID().uuidString) let testUser = PubNubUserMetadataBase(name: "TestUser") let invalidUser = PubNubUserMetadataBase(name: "") @@ -19,9 +19,9 @@ final class ObjectsUUIDRouterTests: XCTestCase { // MARK: - All Tests -extension ObjectsUUIDRouterTests { +extension ObjectsUserRouterTests { func testAll_Router() { - let router = ObjectsUUIDRouter( + let router = ObjectsUserRouter( .all( include: [.custom], totalCount: true, filter: "filter", sort: ["sort"], limit: 100, start: "start", end: "end" @@ -35,7 +35,7 @@ extension ObjectsUUIDRouterTests { } func testAll_Router_ValidationError() { - let router = ObjectsUUIDRouter( + let router = ObjectsUserRouter( .all( include: [.custom], totalCount: true, filter: "filter", sort: ["sort"], limit: 100, start: "start", end: "end" @@ -198,9 +198,9 @@ extension ObjectsUUIDRouterTests { // MARK: - Fetch Tests -extension ObjectsUUIDRouterTests { +extension ObjectsUserRouterTests { func testFetch_Router() { - let router = ObjectsUUIDRouter( + let router = ObjectsUserRouter( .fetch(metadataId: "OtherUser", include: [.custom]), configuration: config ) @@ -211,7 +211,7 @@ extension ObjectsUUIDRouterTests { } func testFetch_Router_ValidationError() { - let router = ObjectsUUIDRouter(.fetch(metadataId: "", include: [.custom]), configuration: config) + let router = ObjectsUserRouter(.fetch(metadataId: "", include: [.custom]), configuration: config) XCTAssertNotEqual( router.validationError?.pubNubError, @@ -382,9 +382,9 @@ extension ObjectsUUIDRouterTests { // MARK: - Set Tests -extension ObjectsUUIDRouterTests { +extension ObjectsUserRouterTests { func testSet_Router() { - let router = ObjectsUUIDRouter(.set(metadata: testUser, include: [.custom]), configuration: config) + let router = ObjectsUserRouter(.set(metadata: testUser, include: [.custom]), configuration: config) XCTAssertEqual(router.endpoint.description, "Set Metadata for a UUID") XCTAssertEqual(router.category, "Set Metadata for a UUID") @@ -392,7 +392,7 @@ extension ObjectsUUIDRouterTests { } func testSet_Router_ValidationError() { - let router = ObjectsUUIDRouter(.set(metadata: invalidUser, include: [.custom]), configuration: config) + let router = ObjectsUserRouter(.set(metadata: invalidUser, include: [.custom]), configuration: config) XCTAssertNotEqual( router.validationError?.pubNubError, @@ -612,9 +612,9 @@ extension ObjectsUUIDRouterTests { // MARK: - Remove Tests -extension ObjectsUUIDRouterTests { +extension ObjectsUserRouterTests { func testRemove_Router() { - let router = ObjectsUUIDRouter(.remove(metadataId: "TestUser"), configuration: config) + let router = ObjectsUserRouter(.remove(metadataId: "TestUser"), configuration: config) XCTAssertEqual(router.endpoint.description, "Remove Metadata from a UUID") XCTAssertEqual(router.category, "Remove Metadata from a UUID") @@ -622,7 +622,7 @@ extension ObjectsUUIDRouterTests { } func testRemove_Router_ValidationError() { - let router = ObjectsUUIDRouter(.remove(metadataId: ""), configuration: config) + let router = ObjectsUserRouter(.remove(metadataId: ""), configuration: config) XCTAssertNotEqual( router.validationError?.pubNubError,