Skip to content

Commit

Permalink
feat: Add ConfidenceValue (#84)
Browse files Browse the repository at this point in the history
* Add ConfidenceValue

* Add ConfidenceValueTests

* Remove DateComponents

* Simplify and finalize ConfidenceValue

* Test fix

* Update demo app

* Variable renaming

* ConfidenceValue is only Codable

* Add Confidence-OF converstions

* refactor: Restrict heterogeneous ConfidenceValue lists (#86)

* Change ConfidenceValue constructors for more control

* Setup for list restrictions

* Remove unused converters

* Change time-related arg labels

* Fix date format

* Explicit UTC settings and TZ tests

* Best effort convert OF lists

* Rename bool to boolean

* Rename TZ offset from timestamps

* Add swiftpm back
  • Loading branch information
fabriziodemaria authored Apr 9, 2024
1 parent 2e49e23 commit 8de4b78
Show file tree
Hide file tree
Showing 21 changed files with 888 additions and 16 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ DerivedData/
.netrc
.build
.mockingbird
project.json
.swiftpm
project.json
123 changes: 123 additions & 0 deletions .swiftpm/xcode/xcshareddata/xcschemes/Confidence-Package.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1510"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "Confidence"
BuildableName = "Confidence"
BlueprintName = "Confidence"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "ConfidenceProvider"
BuildableName = "ConfidenceProvider"
BlueprintName = "ConfidenceProvider"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "NO"
buildForArchiving = "NO"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "ConfidenceProviderTests"
BuildableName = "ConfidenceProviderTests"
BlueprintName = "ConfidenceProviderTests"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "ConfidenceProviderTests"
BuildableName = "ConfidenceProviderTests"
BlueprintName = "ConfidenceProviderTests"
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "ConfidenceTests"
BuildableName = "ConfidenceTests"
BlueprintName = "ConfidenceTests"
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<EnvironmentVariables>
<EnvironmentVariable
key = "CLIENT_TOKEN"
value = "5GdaBq79NMVrMGXRVhN9g1pBKtG9cNK8"
isEnabled = "YES">
</EnvironmentVariable>
</EnvironmentVariables>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "Confidence"
BuildableName = "Confidence"
BlueprintName = "Confidence"
ReferencedContainer = "container:">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
66 changes: 66 additions & 0 deletions .swiftpm/xcode/xcshareddata/xcschemes/Confidence.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1510"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "Confidence"
BuildableName = "Confidence"
BlueprintName = "Confidence"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "Confidence"
BuildableName = "Confidence"
BlueprintName = "Confidence"
ReferencedContainer = "container:">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
92 changes: 92 additions & 0 deletions .swiftpm/xcode/xcshareddata/xcschemes/ConfidenceProvider.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1510"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "ConfidenceProvider"
BuildableName = "ConfidenceProvider"
BlueprintName = "ConfidenceProvider"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "NO"
buildForArchiving = "NO"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "ConfidenceProviderTests"
BuildableName = "ConfidenceProviderTests"
BlueprintName = "ConfidenceProviderTests"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "ConfidenceProviderTests"
BuildableName = "ConfidenceProviderTests"
BlueprintName = "ConfidenceProviderTests"
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "ConfidenceProvider"
BuildableName = "ConfidenceProvider"
BlueprintName = "ConfidenceProvider"
ReferencedContainer = "container:">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ extension ConfidenceDemoApp {
let ctx = MutableContext(targetingKey: UUID.init().uuidString, structure: MutableStructure())
Task {
await OpenFeatureAPI.shared.setProviderAndWait(provider: provider, initialContext: ctx)
confidence.send(eventName: "my_event")
confidence.send(definition: "my_event", payload: ConfidenceStruct())
}
}
}
8 changes: 7 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ let package = Package(
dependencies: [
"ConfidenceProvider",
]
)
),
.testTarget(
name: "ConfidenceTests",
dependencies: [
"Confidence"
]
),
]
)
10 changes: 5 additions & 5 deletions Sources/Confidence/Confidence.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation

public class Confidence: ConfidenceEventSender {
public var context: [String: String]
public var context: ConfidenceStruct
public let clientSecret: String
public var timeout: TimeInterval
public var region: ConfidenceRegion
Expand All @@ -21,11 +21,11 @@ public class Confidence: ConfidenceEventSender {
}

// TODO: Implement actual event uploading to the backend
public func send(eventName: String) {
print("Sending \(eventName) - Targeting key: \(context["targeting_key"] ?? "UNKNOWN")")
public func send(definition: String, payload: ConfidenceStruct) {
print("Sending \(definition) - Targeting key: \(payload)")
}

public func updateContextEntry(key: String, value: String) {
public func updateContextEntry(key: String, value: ConfidenceValue) {
context[key] = value
}

Expand All @@ -38,7 +38,7 @@ public class Confidence: ConfidenceEventSender {
}

// TODO: Implement creation of child instances
public func withContext(_ context: [String: String]) -> Self {
public func withContext(_ context: ConfidenceStruct) -> Self {
return self
}
}
Expand Down
File renamed without changes.
3 changes: 1 addition & 2 deletions Sources/Confidence/ConfidenceEventSender.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
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)
func send(definition: String, payload: ConfidenceStruct)
}
Loading

0 comments on commit 8de4b78

Please sign in to comment.