-
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.
refactor: Add Confidence Library scaffolding (#83)
* chore: Update ignore * Remove xcscheme file from repo * Fix test script used in CI * feat: First Confidence Scaffolding * Basic EvaluationContext wiring in events * More Builder and constructor refactoring * Update README * Move enum to standalone files * Remove temporary code
- Loading branch information
1 parent
1bd9525
commit 2e49e23
Showing
15 changed files
with
241 additions
and
188 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
100 changes: 0 additions & 100 deletions
100
...enceDemoApp/ConfidenceDemoApp.xcodeproj/xcshareddata/xcschemes/ConfidenceDemoApp.xcscheme
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
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,24 +4,33 @@ | |
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"), | ||
], | ||
targets: [ | ||
.target( | ||
name: "Confidence", | ||
dependencies: [], | ||
plugins: [] | ||
), | ||
.target( | ||
name: "ConfidenceProvider", | ||
dependencies: [ | ||
.product(name: "OpenFeature", package: "swift-sdk"), | ||
"Confidence" | ||
], | ||
plugins: [] | ||
), | ||
|
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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import Foundation | ||
|
||
public class Confidence: ConfidenceEventSender { | ||
public var context: [String: String] | ||
public let clientSecret: String | ||
public var timeout: TimeInterval | ||
public var region: ConfidenceRegion | ||
public var initializationStrategy: InitializationStrategy | ||
|
||
init( | ||
clientSecret: String, | ||
timeout: TimeInterval, | ||
region: ConfidenceRegion, | ||
initializationStrategy: InitializationStrategy | ||
) { | ||
self.context = [:] | ||
self.clientSecret = clientSecret | ||
self.timeout = timeout | ||
self.region = region | ||
self.initializationStrategy = initializationStrategy | ||
} | ||
|
||
// TODO: Implement actual event uploading to the backend | ||
public func send(eventName: String) { | ||
print("Sending \(eventName) - Targeting key: \(context["targeting_key"] ?? "UNKNOWN")") | ||
} | ||
|
||
public func updateContextEntry(key: String, value: String) { | ||
context[key] = value | ||
} | ||
|
||
public func removeContextEntry(key: String) { | ||
context.removeValue(forKey: key) | ||
} | ||
|
||
public func clearContext() { | ||
context = [:] | ||
} | ||
|
||
// TODO: Implement creation of child instances | ||
public func withContext(_ context: [String: String]) -> Self { | ||
return self | ||
} | ||
} | ||
|
||
extension Confidence { | ||
public class Builder { | ||
let clientSecret: String | ||
var timeout: TimeInterval = 10.0 | ||
var region: ConfidenceRegion = .global | ||
var initializationStrategy: InitializationStrategy = .fetchAndActivate | ||
|
||
public init(clientSecret: String) { | ||
self.clientSecret = clientSecret | ||
} | ||
|
||
public func withTimeout(timeout: TimeInterval) -> Builder { | ||
self.timeout = timeout | ||
return self | ||
} | ||
|
||
|
||
public func withRegion(region: ConfidenceRegion) -> Builder { | ||
self.region = region | ||
return self | ||
} | ||
|
||
public func withInitializationstrategy(initializationStrategy: InitializationStrategy) -> Builder { | ||
self.initializationStrategy = initializationStrategy | ||
return self | ||
} | ||
|
||
public func build() -> Confidence { | ||
return Confidence( | ||
clientSecret: clientSecret, | ||
timeout: timeout, | ||
region: region, | ||
initializationStrategy: initializationStrategy | ||
) | ||
} | ||
} | ||
} |
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,7 @@ | ||
import Foundation | ||
|
||
/// Sends events to Confidence. Contextual data is appended to each event | ||
// TODO: Add functions for sending events with payload | ||
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,9 @@ | ||
import Foundation | ||
|
||
/// Sets the region for the network request to the Confidence backend. | ||
/// This is applied for both sending events as well as fetching flag's data. | ||
public enum ConfidenceRegion { | ||
case global | ||
case europe | ||
case usa | ||
} |
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,15 @@ | ||
import Foundation | ||
|
||
/// A Contextual implementer maintains context data and can create child instances | ||
/// that can still access their parent's data | ||
public protocol Contextual { | ||
// TODO: Add complex type to the context Dictionary | ||
var context: [String: String] { get set } | ||
|
||
func updateContextEntry(key: String, value: String) | ||
func removeContextEntry(key: String) | ||
func clearContext() | ||
/// Creates a child Contextual instance that still has access | ||
/// to its parent context | ||
func withContext(_ context: [String: String]) -> Self | ||
} |
1 change: 1 addition & 0 deletions
1
...enceProvider/InitializationStrategy.swift → ...s/Confidence/InitializationStrategy.swift
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import Foundation | ||
|
||
/// Flag resolve configuration related to how to refresh flags at startup | ||
public enum InitializationStrategy { | ||
case fetchAndActivate, activateAndFetchAsync | ||
} |
32 changes: 32 additions & 0 deletions
32
Sources/ConfidenceProvider/ConfidenceClient/ConfidenceClientOptions.swift
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,32 @@ | ||
import Foundation | ||
import Confidence | ||
|
||
public struct ConfidenceClientOptions { | ||
public var credentials: ConfidenceClientCredentials | ||
public var timeout: TimeInterval | ||
public var region: ConfidenceRegion | ||
public var initializationStrategy: InitializationStrategy | ||
|
||
public init( | ||
credentials: ConfidenceClientCredentials, | ||
timeout: TimeInterval? = nil, | ||
region: ConfidenceRegion? = nil, | ||
initializationStrategy: InitializationStrategy = .fetchAndActivate | ||
) { | ||
self.credentials = credentials | ||
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 | ||
} | ||
} | ||
} |
Oops, something went wrong.