Skip to content

Commit a374eed

Browse files
authored
remove odpConfig from init params (#477)
1 parent 1259931 commit a374eed

8 files changed

+27
-44
lines changed

Sources/ODP/OdpEventManager.swift

Lines changed: 3 additions & 6 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.
@@ -18,9 +18,9 @@ import Foundation
1818
import UIKit
1919

2020
class OdpEventManager {
21-
var odpConfig: OdpConfig
21+
var odpConfig = OdpConfig()
2222
var apiMgr: OdpEventApiManager
23-
23+
2424
var maxQueueSize = 100
2525
let maxBatchEvents = 10
2626
let queueLock: DispatchQueue
@@ -31,14 +31,11 @@ class OdpEventManager {
3131
/// OdpEventManager init
3232
/// - Parameters:
3333
/// - sdkKey: datafile sdkKey
34-
/// - odpConfig: ODP config (apiKey, apiHost, ...)
3534
/// - apiManager: OdpEventApiManager
3635
/// - resourceTimeoutInSecs: timeout for event dispatch
3736
init(sdkKey: String,
38-
odpConfig: OdpConfig? = nil,
3937
apiManager: OdpEventApiManager? = nil,
4038
resourceTimeoutInSecs: Int? = nil) {
41-
self.odpConfig = odpConfig ?? OdpConfig()
4239
self.apiMgr = apiManager ?? OdpEventApiManager(timeout: resourceTimeoutInSecs)
4340

4441
self.queueLock = DispatchQueue(label: "event")

Sources/ODP/OdpManager.swift

Lines changed: 8 additions & 20 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.
@@ -57,26 +57,14 @@ class OdpManager {
5757
return
5858
}
5959

60+
self.segmentManager = segmentManager ?? OdpSegmentManager(cacheSize: cacheSize,
61+
cacheTimeoutInSecs: cacheTimeoutInSecs,
62+
resourceTimeoutInSecs: timeoutForSegmentFetchInSecs)
63+
self.eventManager = eventManager ?? OdpEventManager(sdkKey: sdkKey,
64+
resourceTimeoutInSecs: timeoutForEventDispatchInSecs)
6065
self.odpConfig = OdpConfig()
61-
62-
if let segmentManager = segmentManager {
63-
segmentManager.odpConfig = odpConfig
64-
self.segmentManager = segmentManager
65-
} else {
66-
self.segmentManager = OdpSegmentManager(cacheSize: cacheSize,
67-
cacheTimeoutInSecs: cacheTimeoutInSecs,
68-
odpConfig: odpConfig,
69-
resourceTimeoutInSecs: timeoutForSegmentFetchInSecs)
70-
}
71-
72-
if let eventManager = eventManager {
73-
eventManager.odpConfig = odpConfig
74-
self.eventManager = eventManager
75-
} else {
76-
self.eventManager = OdpEventManager(sdkKey: sdkKey,
77-
odpConfig: odpConfig,
78-
resourceTimeoutInSecs: timeoutForEventDispatchInSecs)
79-
}
66+
self.segmentManager.odpConfig = odpConfig
67+
self.eventManager.odpConfig = odpConfig
8068

8169
self.eventManager.registerVUID(vuid: self.vuidManager.vuid)
8270
}

Sources/ODP/OdpSegmentManager.swift

Lines changed: 2 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.
@@ -17,7 +17,7 @@
1717
import Foundation
1818

1919
class OdpSegmentManager {
20-
var odpConfig: OdpConfig
20+
var odpConfig = OdpConfig()
2121
var segmentsCache: LruCache<String, [String]>
2222
var apiMgr: OdpSegmentApiManager
2323

@@ -27,15 +27,12 @@ class OdpSegmentManager {
2727
/// - Parameters:
2828
/// - cacheSize: segment cache size
2929
/// - cacheTimeoutInSecs: segment cache timeout
30-
/// - odpConfig: ODP config (apiKey, apiHost, ...)
3130
/// - apiManager: OdpSegmentApiManager
3231
/// - resourceTimeoutInSecs: timeout for segment fetch
3332
init(cacheSize: Int,
3433
cacheTimeoutInSecs: Int,
35-
odpConfig: OdpConfig? = nil,
3634
apiManager: OdpSegmentApiManager? = nil,
3735
resourceTimeoutInSecs: Int? = nil) {
38-
self.odpConfig = odpConfig ?? OdpConfig()
3936
self.apiMgr = apiManager ?? OdpSegmentApiManager(timeout: resourceTimeoutInSecs)
4037

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

Tests/OptimizelyTests-Common/OdpEventApiManagerTests.swift

Lines changed: 1 addition & 1 deletion
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.

Tests/OptimizelyTests-Common/OdpEventManagerTests.swift

Lines changed: 8 additions & 6 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.
@@ -38,8 +38,8 @@ class OdpEventManagerTests: XCTestCase {
3838
odpConfig = OdpConfig()
3939

4040
manager = OdpEventManager(sdkKey: "any",
41-
odpConfig: odpConfig,
4241
apiManager: apiManager)
42+
manager.odpConfig = odpConfig
4343
}
4444

4545
override func tearDown() {
@@ -126,8 +126,9 @@ class OdpEventManagerTests: XCTestCase {
126126
_ = odpConfig.update(apiKey: "valid", apiHost: "host", segmentsToCheck: [])
127127

128128
manager = OdpEventManager(sdkKey: "any",
129-
odpConfig: odpConfig,
130129
apiManager: apiManager)
130+
manager.odpConfig = odpConfig
131+
131132
manager.sendEvent(type: "t1",
132133
action: "a1",
133134
identifiers: ["id-key-1": "id-value-1"],
@@ -301,11 +302,12 @@ class OdpEventManagerTests: XCTestCase {
301302
let odpConfig2 = OdpConfig()
302303

303304
let manager1 = OdpEventManager(sdkKey: "sdkKey-1",
304-
odpConfig: odpConfig1,
305305
apiManager: apiManager1)
306+
manager1.odpConfig = odpConfig1
307+
306308
let manager2 = OdpEventManager(sdkKey: "sdkKey-2",
307-
odpConfig: odpConfig2,
308309
apiManager: apiManager2)
310+
manager2.odpConfig = odpConfig2
309311

310312
let event1 = OdpEvent(type: "t1", action: "a1", identifiers: [:], data: [:])
311313
let event2 = OdpEvent(type: "t2", action: "a2", identifiers: [:], data: [:])
@@ -395,8 +397,8 @@ class OdpEventManagerTests: XCTestCase {
395397
_ = odpConfig.update(apiKey: "test-key", apiHost: "test-host", segmentsToCheck: [])
396398

397399
manager = OdpEventManager(sdkKey: "any",
398-
odpConfig: odpConfig,
399400
apiManager: apiManager)
401+
manager.odpConfig = odpConfig
400402

401403
let event = OdpEvent(type: "t1", action: "a1", identifiers: [:], data: [:])
402404
manager.dispatch(event)

Tests/OptimizelyTests-Common/OdpManagerTests.swift

Lines changed: 2 additions & 2 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.
@@ -106,7 +106,7 @@ class OdpManagerTests: XCTestCase {
106106
}
107107

108108
func testRegisterVUIDCalledAutomatically_odpDisabled() {
109-
let newEventManager = MockOdpEventManager(sdkKey: sdkKey, odpConfig: OdpConfig())
109+
let newEventManager = MockOdpEventManager(sdkKey: sdkKey)
110110

111111
_ = OdpManager(sdkKey: sdkKey,
112112
disable: true,

Tests/OptimizelyTests-Common/OdpSegmentManagerTests.swift

Lines changed: 2 additions & 2 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.
@@ -31,8 +31,8 @@ class OdpSegmentManagerTests: XCTestCase {
3131

3232
manager = OdpSegmentManager(cacheSize: 10,
3333
cacheTimeoutInSecs: 10,
34-
odpConfig: odpConfig,
3534
apiManager: apiManager)
35+
manager.odpConfig = odpConfig
3636
}
3737

3838
func testFetchSegmentsSuccess_cacheMiss() {

Tests/OptimizelyTests-Common/OptimizelyUserContextTests_ODP_2.swift

Lines changed: 1 addition & 2 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.
@@ -39,7 +39,6 @@ class OptimizelyUserContextTests_ODP_2: XCTestCase {
3939
cacheSize: 10,
4040
cacheTimeoutInSecs: 10,
4141
eventManager: OdpEventManager(sdkKey: sdkKey,
42-
odpConfig: nil,
4342
apiManager: odpEventApiManager))
4443

4544
// identified event will sent but wait in the queue until project config is ready

0 commit comments

Comments
 (0)