Skip to content

Commit

Permalink
Merge pull request #86 from AppSci/release/2.0.2
Browse files Browse the repository at this point in the history
Release: 2.0.2
  • Loading branch information
denysdanyliukboosters authored Oct 17, 2023
2 parents caddc0a + b80c9d3 commit 81f7f45
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 1 deletion.
25 changes: 25 additions & 0 deletions Sources/PandaSDK/ConfiguredPanda/ConfiguredPanda.swift
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,31 @@ final public class Panda: PandaProtocol, ObserverSupport {
}
}
}

public func forceUpdateUser(completion: @escaping (Result<String, Error>) -> 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 {
Expand Down
26 changes: 26 additions & 0 deletions Sources/PandaSDK/Models/PandaFacebookId.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
13 changes: 13 additions & 0 deletions Sources/PandaSDK/Networking/NetworkClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,19 @@ extension NetworkClient {
networkLoader.loadData(with: request, timeout: nil, completion: callback)
}

func updateUser(
user: PandaUser,
pandaUserInfo: PandaUserInfo,
callback: @escaping (Result<PandaUser, Error>) -> 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,
Expand Down
2 changes: 2 additions & 0 deletions Sources/PandaSDK/PandaProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<PandaUserProperty>) -> Void))

func forceUpdateUser(completion: @escaping (Result<String, Error>) -> Void)
}

public extension PandaProtocol {
Expand Down
3 changes: 2 additions & 1 deletion Sources/PandaSDK/UnconfiguredPanda.swift
Original file line number Diff line number Diff line change
Expand Up @@ -351,5 +351,6 @@ final class UnconfiguredPanda: PandaProtocol, ObserverSupport {
func fetchRemoteUserProperties(completion: @escaping((Set<PandaUserProperty>) -> Void)) {
completion(.init())
}

public func forceUpdateUser(completion: @escaping (Result<String, Error>) -> Void) { }
}

0 comments on commit 81f7f45

Please sign in to comment.