-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_collector_string_hook.swift
73 lines (65 loc) · 2.17 KB
/
data_collector_string_hook.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import Foundation
import OpenFeature
import OFREP
class StringHook: Hook {
typealias HookValue = String
let dataCollectorMngr: DataCollectorManager
init(dataCollectorMngr: DataCollectorManager) {
self.dataCollectorMngr = dataCollectorMngr
}
func before<HookValue>(ctx: HookContext<HookValue>, hints: [String: Any]) {
return
}
func after<HookValue>(
ctx: HookContext<HookValue>,
details: FlagEvaluationDetails<HookValue>,
hints: [String: Any]) {
let contextKind = "user"
let userKey = ctx.ctx?.getTargetingKey() ?? ""
let key = ctx.flagKey
guard let value = details.value as? String else {
NSLog("Default value is not of type String")
return
}
let event = FeatureEvent(
kind: "feature",
contextKind: contextKind,
userKey: userKey,
creationDate: Int64(Date().timeIntervalSince1970),
key: key,
variation: details.variant ?? "SdkDefault",
value: JSONValue.string(value),
default: false,
source: "PROVIDER_CACHE"
)
self.dataCollectorMngr.appendFeatureEvent(event: event)
}
func error<HookValue>(
ctx: HookContext<HookValue>,
error: Error,
hints: [String: Any]) {
let contextKind = "user"
let userKey = ctx.ctx?.getTargetingKey() ?? ""
let key = ctx.flagKey
guard let value = ctx.defaultValue as? String else {
NSLog("Default value is not of type String")
return
}
let event = FeatureEvent(
kind: "feature",
contextKind: contextKind,
userKey: userKey,
creationDate: Int64(Date().timeIntervalSince1970),
key: key,
variation: "SdkDefault",
value: JSONValue.string(value),
default: true,
source: "PROVIDER_CACHE"
)
self.dataCollectorMngr.appendFeatureEvent(event: event)
}
func finally<HookValue>(
ctx: HookContext<HookValue>, details: FlagEvaluationDetails<HookValue>, hints: [String: Any]) {
return
}
}