From b80c9d3301e135803b6e66bca607506a253683dd Mon Sep 17 00:00:00 2001 From: denysdanyliukboosters Date: Fri, 6 Oct 2023 13:11:54 +0300 Subject: [PATCH] Release: 2.0.2 WIP WIP --- .../ConfiguredPanda/ConfiguredPanda.swift | 25 ++++++++++++++++++ Sources/PandaSDK/Models/PandaFacebookId.swift | 26 +++++++++++++++++++ .../PandaSDK/Networking/NetworkClient.swift | 13 ++++++++++ Sources/PandaSDK/PandaProtocol.swift | 2 ++ Sources/PandaSDK/UnconfiguredPanda.swift | 3 ++- 5 files changed, 68 insertions(+), 1 deletion(-) diff --git a/Sources/PandaSDK/ConfiguredPanda/ConfiguredPanda.swift b/Sources/PandaSDK/ConfiguredPanda/ConfiguredPanda.swift index 904374b..8ee72a6 100644 --- a/Sources/PandaSDK/ConfiguredPanda/ConfiguredPanda.swift +++ b/Sources/PandaSDK/ConfiguredPanda/ConfiguredPanda.swift @@ -589,6 +589,31 @@ final public class Panda: PandaProtocol, ObserverSupport { } } } + + public func forceUpdateUser(completion: @escaping (Result) -> Void) { + let data = deviceStorage.fetch() + guard let data else { + return + } + let pandaUserInfo = PandaUserInfo( + pushNotificationToken: data.pushToken, + customUserId: data.customUserId, + appsFlyerId: data.appsFlyerId, + fbc: data.pandaFacebookId.fbc ?? "", + fbp: data.pandaFacebookId.fbp ?? "", + email: data.capiConfig.email ?? "", + facebookLoginId: data.capiConfig.facebookLoginId ?? "", + firstName: data.capiConfig.firstName ?? "", + lastName: data.capiConfig.lastName ?? "", + username: data.capiConfig.username ?? "", + phone: data.capiConfig.phone ?? "", + gender: data.capiConfig.gender, + userProperties: data.userProperties.reduce(into: [String: String]()) { $0[$1.key] = $1.value } + ) + networkClient.updateUser(user: self.user, pandaUserInfo: pandaUserInfo) { result in + completion(result.map { $0.id }) + } + } } extension PandaProtocol where Self: ObserverSupport { diff --git a/Sources/PandaSDK/Models/PandaFacebookId.swift b/Sources/PandaSDK/Models/PandaFacebookId.swift index b906a5b..0280889 100644 --- a/Sources/PandaSDK/Models/PandaFacebookId.swift +++ b/Sources/PandaSDK/Models/PandaFacebookId.swift @@ -29,4 +29,30 @@ public enum PandaFacebookId: Codable, Equatable { return .empty } + + var fbc: String? { + switch self { + case let .fbc(fbc): + return fbc + case .fbp: + return nil + case let .fbpAndFbc(_, fbc): + return fbc + case .empty: + return nil + } + } + + var fbp: String? { + switch self { + case .fbc: + return nil + case let .fbp(fbp): + return fbp + case let .fbpAndFbc(fbp, _): + return fbp + case .empty: + return nil + } + } } diff --git a/Sources/PandaSDK/Networking/NetworkClient.swift b/Sources/PandaSDK/Networking/NetworkClient.swift index 8d79ae5..df14d84 100644 --- a/Sources/PandaSDK/Networking/NetworkClient.swift +++ b/Sources/PandaSDK/Networking/NetworkClient.swift @@ -175,6 +175,19 @@ extension NetworkClient { networkLoader.loadData(with: request, timeout: nil, completion: callback) } + func updateUser( + user: PandaUser, + pandaUserInfo: PandaUserInfo, + callback: @escaping (Result) -> Void + ) { + let request = createRequest( + path: "/v1/users/\(user.id)", + method: .put, + body: pandaUserInfo + ) + networkLoader.loadData(with: request, timeout: nil, completion: callback) + } + func updateUser( pushToken: String, user: PandaUser, diff --git a/Sources/PandaSDK/PandaProtocol.swift b/Sources/PandaSDK/PandaProtocol.swift index 28f60a0..004f907 100644 --- a/Sources/PandaSDK/PandaProtocol.swift +++ b/Sources/PandaSDK/PandaProtocol.swift @@ -254,6 +254,8 @@ public protocol PandaProtocol: AnyObject { func getUserProperties() -> [PandaUserProperty] /// Fetch All User Properties From Remote or local in case of failure. Returns on main thread func fetchRemoteUserProperties(completion: @escaping((Set) -> Void)) + + func forceUpdateUser(completion: @escaping (Result) -> Void) } public extension PandaProtocol { diff --git a/Sources/PandaSDK/UnconfiguredPanda.swift b/Sources/PandaSDK/UnconfiguredPanda.swift index 229d833..139274b 100644 --- a/Sources/PandaSDK/UnconfiguredPanda.swift +++ b/Sources/PandaSDK/UnconfiguredPanda.swift @@ -351,5 +351,6 @@ final class UnconfiguredPanda: PandaProtocol, ObserverSupport { func fetchRemoteUserProperties(completion: @escaping((Set) -> Void)) { completion(.init()) } + + public func forceUpdateUser(completion: @escaping (Result) -> Void) { } } -