-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e529cc8
commit a5ec0d5
Showing
12 changed files
with
166 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,15 +4,18 @@ | |
import PackageDescription | ||
|
||
let package = Package( | ||
name: "ConfidenceProvider", | ||
name: "Confidence", | ||
platforms: [ | ||
.iOS(.v14), | ||
.macOS(.v12) | ||
], | ||
products: [ | ||
.library( | ||
name: "ConfidenceProvider", | ||
targets: ["ConfidenceProvider"]) | ||
targets: ["ConfidenceProvider"]), | ||
.library( | ||
name: "Confidence", | ||
targets: ["Confidence"]) | ||
], | ||
dependencies: [ | ||
.package(url: "[email protected]:open-feature/swift-sdk.git", from: "0.1.0"), | ||
|
@@ -22,9 +25,15 @@ let package = Package( | |
name: "ConfidenceProvider", | ||
dependencies: [ | ||
.product(name: "OpenFeature", package: "swift-sdk"), | ||
"Confidence" | ||
], | ||
plugins: [] | ||
), | ||
.target( | ||
name: "Confidence", | ||
dependencies: [], | ||
plugins: [] | ||
), | ||
.testTarget( | ||
name: "ConfidenceProviderTests", | ||
dependencies: [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import Foundation | ||
|
||
public class Confidence: ConfidenceEventSender { | ||
public var context: [String: String] | ||
public let clientSecret: String | ||
public let options: ConfidenceClientOptions | ||
|
||
init(clientSecret: String, options: ConfidenceClientOptions) { | ||
self.clientSecret = clientSecret | ||
self.options = options | ||
self.context = [:] | ||
} | ||
|
||
public func send(eventName: String) { | ||
print("Sending \(eventName)") | ||
} | ||
|
||
public func updateContextEntry(key: String, value: String) { | ||
context[key] = value | ||
} | ||
|
||
public func removeContextEntry(key: String) { | ||
context.removeValue(forKey: key) | ||
} | ||
|
||
public func clearContext() { | ||
context = [:] | ||
} | ||
|
||
public func withContext(_ context: [String: String]) -> Self { | ||
// TODO | ||
return self | ||
} | ||
} | ||
|
||
extension Confidence { | ||
public struct Builder { | ||
let clientSecret: String | ||
var options: ConfidenceClientOptions | ||
|
||
public init(clientSecret: String) { | ||
self.clientSecret = clientSecret | ||
self.options = ConfidenceClientOptions( | ||
credentials: ConfidenceClientCredentials.clientSecret(secret: (clientSecret))) | ||
} | ||
|
||
init(clientSecret: String, options: ConfidenceClientOptions) { | ||
self.clientSecret = clientSecret | ||
self.options = options | ||
} | ||
|
||
public func withOptions(options: ConfidenceClientOptions) -> Builder { | ||
return Builder( | ||
clientSecret: clientSecret, | ||
options: options | ||
) | ||
} | ||
|
||
public func build() -> Confidence { | ||
return Confidence(clientSecret: clientSecret, options: ConfidenceClientOptions()) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import Foundation | ||
|
||
public struct ConfidenceClientOptions { | ||
public var credentials: ConfidenceClientCredentials // DEPRECATED | ||
public var timeout: TimeInterval | ||
public var region: ConfidenceRegion | ||
public var initializationStrategy: InitializationStrategy | ||
|
||
public init( | ||
credentials: ConfidenceClientCredentials? = nil, | ||
timeout: TimeInterval? = nil, | ||
region: ConfidenceRegion? = nil, | ||
initializationStrategy: InitializationStrategy = .fetchAndActivate | ||
) { | ||
self.credentials = credentials ?? ConfidenceClientCredentials.clientSecret(secret: "") | ||
self.timeout = timeout ?? 10.0 | ||
self.region = region ?? .global | ||
self.initializationStrategy = initializationStrategy | ||
} | ||
} | ||
|
||
public enum ConfidenceClientCredentials { | ||
case clientSecret(secret: String) | ||
|
||
public func getSecret() -> String { | ||
switch self { | ||
case .clientSecret(let secret): | ||
return secret | ||
} | ||
} | ||
} | ||
|
||
public enum ConfidenceRegion { | ||
case global | ||
case europe | ||
case usa | ||
} | ||
|
||
public enum InitializationStrategy { | ||
case fetchAndActivate, activateAndFetchAsync | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import Foundation | ||
|
||
public protocol ConfidenceEventSender: Contextual { | ||
func send(eventName: String) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import Foundation | ||
|
||
public protocol Contextual { | ||
var context: [String: String] { get set } // TODO Introdue complex types | ||
|
||
func updateContextEntry(key: String, value: String) | ||
func removeContextEntry(key: String) | ||
func clearContext() | ||
|
||
func withContext(_ context: [String: String]) -> Self | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters