Skip to content
This repository has been archived by the owner on Sep 13, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1 from foresightmobile/feature/get-identity-flags
Browse files Browse the repository at this point in the history
Implemented getting flags by identity and setting traits at the same
  • Loading branch information
jackforesightmobile authored May 31, 2024
2 parents 1104787 + af668ac commit f6a4e64
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
15 changes: 15 additions & 0 deletions FlagsmithClient/Classes/Flagsmith.swift
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,21 @@ public final class Flagsmith: @unchecked Sendable {
completion(result.map(\.traits))
}
}

/// Get flags for an identity and set traits in the same call
///
/// - Parameters:
/// - traits: Traits to be created or updated
/// - identity: ID of the user
/// - completion: Closure with Result which contains a list of Flags in case of success or Error in case of failure
public func getIdentityFlags(_ traits: [Trait],
forIdentity identity: String,
completion: @Sendable @escaping (Result<[Flag], any Error>) -> Void)
{
apiManager.request(.postTraits(identity: identity, traits: traits)) { (result: Result<Traits, Error>) in
completion(result.map(\.flags))
}
}

/// Get both feature flags and user traits for the provided identity
///
Expand Down
7 changes: 7 additions & 0 deletions FlagsmithClient/Classes/Traits.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,11 @@ import Foundation
public struct Traits: Codable, Sendable {
public let traits: [Trait]
public let identifier: String?
public let flags: [Flag]

init(traits: [Trait], identifier: String?, flags: [Flag] = []) {
self.traits = traits
self.identifier = identifier
self.flags = flags
}
}
3 changes: 2 additions & 1 deletion FlagsmithClient/Tests/RouterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ final class RouterTests: FlagsmithClientTestCase {
"trait_value" : 42
}
],
"identifier" : "A1B2C3D4"
"identifier" : "A1B2C3D4",
"flags": []
}
""".json(using: .utf8)
let body = try request.httpBody.json()
Expand Down

0 comments on commit f6a4e64

Please sign in to comment.