Skip to content

Commit 3fce84a

Browse files
authored
Adding support for odp fsc testing. (#476)
1 parent a374eed commit 3fce84a

File tree

9 files changed

+54
-49
lines changed

9 files changed

+54
-49
lines changed

Sources/Extensions/OptimizelyClient+Extension.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2019-2021, Optimizely, Inc. and contributors
2+
// Copyright 2019-2021,2023 Optimizely, Inc. and contributors
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -62,6 +62,7 @@ extension OptimizelyClient {
6262
eventDispatcher: OPTEventDispatcher? = nil,
6363
datafileHandler: OPTDatafileHandler? = nil,
6464
userProfileService: OPTUserProfileService? = nil,
65+
odpManager: OdpManager? = nil,
6566
periodicDownloadInterval: Int?,
6667
defaultLogLevel: OptimizelyLogLevel? = nil,
6768
defaultDecideOptions: [OptimizelyDecideOption]? = nil,
@@ -72,6 +73,7 @@ extension OptimizelyClient {
7273
eventDispatcher: eventDispatcher,
7374
datafileHandler: datafileHandler,
7475
userProfileService: userProfileService,
76+
odpManager: odpManager,
7577
defaultLogLevel: defaultLogLevel,
7678
defaultDecideOptions: defaultDecideOptions,
7779
settings: settings)

Sources/ODP/OdpEvent.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2022, Optimizely, Inc. and contributors
2+
// Copyright 2022-2023, Optimizely, Inc. and contributors
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -16,7 +16,7 @@
1616

1717
import Foundation
1818

19-
struct OdpEvent: Codable {
19+
public struct OdpEvent: Codable {
2020
let type: String
2121
let action: String
2222
let identifiers: [String: String]
@@ -25,7 +25,7 @@ struct OdpEvent: Codable {
2525
let data: [String: Any?]
2626
let dataSerial: Data
2727

28-
init(type: String, action: String, identifiers: [String: String], data: [String: Any?]) {
28+
public init(type: String, action: String, identifiers: [String: String], data: [String: Any?]) {
2929
self.type = type
3030
self.action = action
3131
self.identifiers = identifiers
@@ -44,7 +44,7 @@ struct OdpEvent: Codable {
4444
case dataSerial
4545
}
4646

47-
init(from decoder: Decoder) throws {
47+
public init(from decoder: Decoder) throws {
4848
let values = try decoder.container(keyedBy: CodingKeys.self)
4949

5050
self.type = try values.decode(String.self, forKey: .type)
@@ -57,7 +57,7 @@ struct OdpEvent: Codable {
5757

5858
// For JSON encoding (POST request body)
5959

60-
var dict: [String: Any] {
60+
public var dict: [String: Any] {
6161
return [
6262
"type": type,
6363
"action": action,

Sources/ODP/OdpEventApiManager.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2022, Optimizely, Inc. and contributors
2+
// Copyright 2022-2023, Optimizely, Inc. and contributors
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -30,13 +30,13 @@ import Foundation
3030
{"title":"Accepted","status":202,"timestamp":"2022-06-30T20:59:52.046Z"}
3131
*/
3232

33-
class OdpEventApiManager {
33+
public class OdpEventApiManager {
3434
let resourceTimeoutInSecs: Int?
3535

3636
/// OdpEventApiManager init
3737
/// - Parameters:
3838
/// - timeout: timeout for segment fetch
39-
init(timeout: Int? = nil) {
39+
public init(timeout: Int? = nil) {
4040
self.resourceTimeoutInSecs = timeout
4141
}
4242

Sources/ODP/OdpEventManager.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2022-2023, Optimizely, Inc. and contributors
2+
// Copyright 2022-2023, Optimizely, Inc. and contributors
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -17,7 +17,7 @@
1717
import Foundation
1818
import UIKit
1919

20-
class OdpEventManager {
20+
open class OdpEventManager {
2121
var odpConfig = OdpConfig()
2222
var apiMgr: OdpEventApiManager
2323

@@ -33,9 +33,9 @@ class OdpEventManager {
3333
/// - sdkKey: datafile sdkKey
3434
/// - apiManager: OdpEventApiManager
3535
/// - resourceTimeoutInSecs: timeout for event dispatch
36-
init(sdkKey: String,
37-
apiManager: OdpEventApiManager? = nil,
38-
resourceTimeoutInSecs: Int? = nil) {
36+
public init(sdkKey: String,
37+
apiManager: OdpEventApiManager? = nil,
38+
resourceTimeoutInSecs: Int? = nil) {
3939
self.apiMgr = apiManager ?? OdpEventApiManager(timeout: resourceTimeoutInSecs)
4040

4141
self.queueLock = DispatchQueue(label: "event")
@@ -101,7 +101,7 @@ class OdpEventManager {
101101

102102
// MARK: - dispatch
103103

104-
func dispatch(_ event: OdpEvent) {
104+
open func dispatch(_ event: OdpEvent) {
105105
if eventQueue.count < maxQueueSize {
106106
eventQueue.save(item: event)
107107
} else {

Sources/ODP/OdpManager.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import Foundation
1818

19-
class OdpManager {
19+
public class OdpManager {
2020
var enabled: Bool
2121
var vuidManager: OdpVuidManager
2222

@@ -40,14 +40,14 @@ class OdpManager {
4040
/// - timeoutForEventDispatchInSecs: timeout for event dispatch
4141
/// - segmentManager: ODPSegmentManager
4242
/// - eventManager: ODPEventManager
43-
init(sdkKey: String,
44-
disable: Bool,
45-
cacheSize: Int,
46-
cacheTimeoutInSecs: Int,
47-
timeoutForSegmentFetchInSecs: Int? = nil,
48-
timeoutForEventDispatchInSecs: Int? = nil,
49-
segmentManager: OdpSegmentManager? = nil,
50-
eventManager: OdpEventManager? = nil) {
43+
public init(sdkKey: String,
44+
disable: Bool,
45+
cacheSize: Int,
46+
cacheTimeoutInSecs: Int,
47+
timeoutForSegmentFetchInSecs: Int? = nil,
48+
timeoutForEventDispatchInSecs: Int? = nil,
49+
segmentManager: OdpSegmentManager? = nil,
50+
eventManager: OdpEventManager? = nil) {
5151

5252
self.enabled = !disable
5353
self.vuidManager = OdpVuidManager.shared

Sources/ODP/OdpSegmentApiManager.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2022, Optimizely, Inc. and contributors
2+
// Copyright 2022-2023, Optimizely, Inc. and contributors
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -95,23 +95,23 @@ import Foundation
9595
}
9696
*/
9797

98-
class OdpSegmentApiManager {
98+
open class OdpSegmentApiManager {
9999
let logger = OPTLoggerFactory.getLogger()
100100
let resourceTimeoutInSecs: Int?
101101

102102
/// OdpSegmentApiManager init
103103
/// - Parameters:
104104
/// - timeout: timeout for segment fetch
105-
init(timeout: Int? = nil) {
105+
public init(timeout: Int? = nil) {
106106
self.resourceTimeoutInSecs = timeout
107107
}
108108

109-
func fetchSegments(apiKey: String,
110-
apiHost: String,
111-
userKey: String,
112-
userValue: String,
113-
segmentsToCheck: [String],
114-
completionHandler: @escaping ([String]?, OptimizelyError?) -> Void) {
109+
open func fetchSegments(apiKey: String,
110+
apiHost: String,
111+
userKey: String,
112+
userValue: String,
113+
segmentsToCheck: [String],
114+
completionHandler: @escaping ([String]?, OptimizelyError?) -> Void) {
115115

116116
let query = makeQuery(userKey: userKey, userValue: userValue, segmentsToCheck: segmentsToCheck)
117117
guard let httpBody = try? JSONSerialization.data(withJSONObject: query) else {

Sources/ODP/OdpSegmentManager.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import Foundation
1818

19-
class OdpSegmentManager {
19+
public class OdpSegmentManager {
2020
var odpConfig = OdpConfig()
2121
var segmentsCache: LruCache<String, [String]>
2222
var apiMgr: OdpSegmentApiManager
@@ -29,10 +29,11 @@ class OdpSegmentManager {
2929
/// - cacheTimeoutInSecs: segment cache timeout
3030
/// - apiManager: OdpSegmentApiManager
3131
/// - resourceTimeoutInSecs: timeout for segment fetch
32-
init(cacheSize: Int,
33-
cacheTimeoutInSecs: Int,
34-
apiManager: OdpSegmentApiManager? = nil,
35-
resourceTimeoutInSecs: Int? = nil) {
32+
public init(cacheSize: Int,
33+
cacheTimeoutInSecs: Int,
34+
apiManager: OdpSegmentApiManager? = nil,
35+
resourceTimeoutInSecs: Int? = nil) {
36+
self.odpConfig = odpConfig ?? OdpConfig()
3637
self.apiMgr = apiManager ?? OdpSegmentApiManager(timeout: resourceTimeoutInSecs)
3738

3839
self.segmentsCache = LruCache<String, [String]>(size: cacheSize,

Sources/Optimizely/OptimizelyClient.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2019-2022, Optimizely, Inc. and contributors
2+
// Copyright 2019-2023, Optimizely, Inc. and contributors
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -59,7 +59,7 @@ open class OptimizelyClient: NSObject {
5959

6060
var decisionService: OPTDecisionService!
6161
public var notificationCenter: OPTNotificationCenter?
62-
var odpManager: OdpManager
62+
var odpManager: OdpManager!
6363
let sdkSettings: OptimizelySdkSettings
6464

6565
// MARK: - Public interfaces
@@ -80,23 +80,23 @@ open class OptimizelyClient: NSObject {
8080
eventDispatcher: OPTEventDispatcher? = nil,
8181
datafileHandler: OPTDatafileHandler? = nil,
8282
userProfileService: OPTUserProfileService? = nil,
83+
odpManager: OdpManager? = nil,
8384
defaultLogLevel: OptimizelyLogLevel? = nil,
8485
defaultDecideOptions: [OptimizelyDecideOption]? = nil,
8586
settings: OptimizelySdkSettings? = nil) {
8687

8788
self.sdkKey = sdkKey
8889
self.sdkSettings = settings ?? OptimizelySdkSettings()
8990
self.defaultDecideOptions = defaultDecideOptions ?? []
90-
91-
self.odpManager = OdpManager(sdkKey: sdkKey,
92-
disable: sdkSettings.disableOdp,
93-
cacheSize: sdkSettings.segmentsCacheSize,
94-
cacheTimeoutInSecs: sdkSettings.segmentsCacheTimeoutInSecs,
95-
timeoutForSegmentFetchInSecs: sdkSettings.timeoutForSegmentFetchInSecs,
96-
timeoutForEventDispatchInSecs: sdkSettings.timeoutForOdpEventInSecs)
97-
91+
9892
super.init()
9993

94+
self.odpManager = odpManager ?? OdpManager(sdkKey: sdkKey,
95+
disable: sdkSettings.disableOdp,
96+
cacheSize: sdkSettings.segmentsCacheSize,
97+
cacheTimeoutInSecs: sdkSettings.segmentsCacheTimeoutInSecs,
98+
timeoutForSegmentFetchInSecs: sdkSettings.timeoutForSegmentFetchInSecs,
99+
timeoutForEventDispatchInSecs: sdkSettings.timeoutForOdpEventInSecs)
100100
let userProfileService = userProfileService ?? DefaultUserProfileService()
101101
let logger = logger ?? DefaultLogger()
102102
type(of: logger).logLevel = defaultLogLevel ?? .info

Tests/OptimizelyTests-Common/DecisionListenerTests.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2019-2021, Optimizely, Inc. and contributors
2+
// Copyright 2019-2021,2023 Optimizely, Inc. and contributors
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -1212,6 +1212,7 @@ class FakeManager: OptimizelyClient {
12121212
eventDispatcher: OPTEventDispatcher? = nil,
12131213
datafileHandler: OPTDatafileHandler? = nil,
12141214
userProfileService: OPTUserProfileService? = nil,
1215+
odpManager: OdpManager? = nil,
12151216
defaultLogLevel: OptimizelyLogLevel? = nil,
12161217
defaultDecideOptions: [OptimizelyDecideOption]? = nil,
12171218
settings: OptimizelySdkSettings? = nil) {
@@ -1224,6 +1225,7 @@ class FakeManager: OptimizelyClient {
12241225
eventDispatcher: eventDispatcher,
12251226
datafileHandler: datafileHandler,
12261227
userProfileService: userProfileService,
1228+
odpManager: odpManager,
12271229
defaultLogLevel: defaultLogLevel,
12281230
defaultDecideOptions: defaultDecideOptions,
12291231
settings: settings)

0 commit comments

Comments
 (0)