Skip to content

Commit 23c23d5

Browse files
fix(Sources/CMAB): Fix default prediction endpoint assignment and trailing slash sanitization in CmabClient and CmabConfig files
1 parent 975bf37 commit 23c23d5

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

Sources/CMAB/CmabClient.swift

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616

1717
import Foundation
1818

19-
let DEFAULT_CMAB_CACHE_TIMEOUT = 30 * 60 // 30 minutes
20-
let DEFAULT_CMAB_CACHE_SIZE = 100
21-
2219
enum CmabClientError: Error, Equatable {
2320
case fetchFailed(String)
2421
case invalidResponse
@@ -51,8 +48,6 @@ protocol CmabClient {
5148
)
5249
}
5350

54-
let CMAB_END_POINT = "https://prediction.cmab.optimizely.com/predict"
55-
5651
class DefaultCmabClient: CmabClient {
5752
let session: URLSession
5853
let retryConfig: CmabRetryConfig
@@ -69,7 +64,7 @@ class DefaultCmabClient: CmabClient {
6964
self.session = session
7065
self.retryConfig = retryConfig
7166
self.maxWaitTime = maxWaitTime
72-
self.predictionEndpoint = predictionEndpoint ?? CMAB_END_POINT
67+
self.predictionEndpoint = predictionEndpoint ?? CMAB_PREDICTION_END_POINT
7368
}
7469

7570
func fetchDecision(

Sources/CMAB/CmabConfig.swift

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

1717
import Foundation
1818

19+
let DEFAULT_CMAB_CACHE_TIMEOUT = 30 * 60 // 30 minutes
20+
let DEFAULT_CMAB_CACHE_SIZE = 100
21+
let CMAB_PREDICTION_END_POINT = "https://prediction.cmab.optimizely.com/predict"
22+
1923
/// Configuration for CMAB (Contextual Multi-Armed Bandit) service
2024
public struct CmabConfig {
2125
/// The maximum size of CMAB decision cache
@@ -37,14 +41,14 @@ public struct CmabConfig {
3741
self.cacheTimeoutInSecs = cacheTimeoutInSecs
3842
// Sanitize and validate endpoint
3943
if let endpoint = predictionEndpoint?.trimmingCharacters(in: .whitespaces), !endpoint.isEmpty {
40-
// Remove all trailing slashes
44+
// Remove trailing slashes
4145
var sanitized = endpoint
42-
while sanitized.hasSuffix("/") {
46+
if sanitized.hasSuffix("/") {
4347
sanitized = String(sanitized.dropLast())
4448
}
4549
self.predictionEndpoint = sanitized
4650
} else {
47-
self.predictionEndpoint = CMAB_END_POINT
51+
self.predictionEndpoint = CMAB_PREDICTION_END_POINT
4852
}
4953
}
5054
}

0 commit comments

Comments
 (0)