Skip to content

Commit

Permalink
Expose bulk setTraits (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
ctreffs authored Feb 21, 2023
1 parent 587ca3e commit 806ec70
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
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

0 comments on commit 806ec70

Please sign in to comment.