Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose bulk setTraits #26

Merged
merged 1 commit into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions FlagsmithClient/Classes/Flagsmith+Concurrency.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,25 @@ public extension Flagsmith {
}
})
}

/// Set user traits in bulk for provided identity
///
/// - Parameters:
/// - trait: Traits to be created or updated
/// - identity: ID of the user
/// - returns: The Traits requested to be set.
@discardableResult func setTraits(_ traits: [Trait], forIdentity identity: String) async throws -> [Trait] {
try await withCheckedThrowingContinuation({ continuation in
setTraits(traits, forIdentity: identity) { result in
switch result {
case .failure(let error):
continuation.resume(throwing: error)
case .success(let value):
continuation.resume(returning: value)
}
}
})
}

/// Get both feature flags and user traits for the provided identity
///
Expand Down
14 changes: 14 additions & 0 deletions FlagsmithClient/Classes/Flagsmith.swift
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,20 @@ public class Flagsmith {
completion(result)
}
}

/// Set user traits in bulk for provided identity
///
/// - Parameters:
/// - traits: Traits to be created or updated
/// - identity: ID of the user
/// - completion: Closure with Result which contains Traits in case of success or Error in case of failure
public func setTraits(_ traits: [Trait],
forIdentity identity: String,
completion: @escaping (Result<[Trait], Error>) -> Void) {
apiManager.request(.postTraits(identity: identity, traits: traits)) { (result: Result<[Trait], Error>) in
completion(result)
}
}

/// Get both feature flags and user traits for the provided identity
///
Expand Down