From 8c29c183d416251e82a4bb59b3430617b9cfc1a3 Mon Sep 17 00:00:00 2001 From: duyhungtnn Date: Wed, 27 Sep 2023 12:30:17 +0700 Subject: [PATCH] chore: add sdk_version to the network requests (#48) --- Bucketeer/Sources/Internal/Remote/ApiClientImpl.swift | 10 +++++++--- .../Remote/RequestBody/GetEvaluationsRequestBody.swift | 1 + .../Remote/RequestBody/RegisterEventsRequestBody.swift | 1 + BucketeerTests/ApiClientTests.swift | 8 ++++++-- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Bucketeer/Sources/Internal/Remote/ApiClientImpl.swift b/Bucketeer/Sources/Internal/Remote/ApiClientImpl.swift index 2d13af4e..874d22d9 100644 --- a/Bucketeer/Sources/Internal/Remote/ApiClientImpl.swift +++ b/Bucketeer/Sources/Internal/Remote/ApiClientImpl.swift @@ -49,8 +49,11 @@ final class ApiClientImpl: ApiClient { user: user, userEvaluationsId: userEvaluationsId, sourceId: .ios, - userEvaluationCondition: UserEvaluationCondition(evaluatedAt: condition.evaluatedAt, - userAttributesUpdated: condition.userAttributesUpdated) + userEvaluationCondition: UserEvaluationCondition( + evaluatedAt: condition.evaluatedAt, + userAttributesUpdated: condition.userAttributesUpdated + ), + sdkVersion: Version.current ) let featureTag = self.featureTag let timeoutMillisValue = timeoutMillis ?? defaultRequestTimeoutMills @@ -78,7 +81,8 @@ final class ApiClientImpl: ApiClient { func registerEvents(events: [Event], completion: ((Result) -> Void)?) { let requestBody = RegisterEventsRequestBody( - events: events + events: events, + sdkVersion: Version.current ) logger?.debug(message: "[API] Register events: \(requestBody)") let encoder = JSONEncoder() diff --git a/Bucketeer/Sources/Internal/Remote/RequestBody/GetEvaluationsRequestBody.swift b/Bucketeer/Sources/Internal/Remote/RequestBody/GetEvaluationsRequestBody.swift index abc818e4..573f67b9 100644 --- a/Bucketeer/Sources/Internal/Remote/RequestBody/GetEvaluationsRequestBody.swift +++ b/Bucketeer/Sources/Internal/Remote/RequestBody/GetEvaluationsRequestBody.swift @@ -6,4 +6,5 @@ struct GetEvaluationsRequestBody: Codable { let userEvaluationsId: String let sourceId: SourceID let userEvaluationCondition: UserEvaluationCondition + let sdkVersion: String } diff --git a/Bucketeer/Sources/Internal/Remote/RequestBody/RegisterEventsRequestBody.swift b/Bucketeer/Sources/Internal/Remote/RequestBody/RegisterEventsRequestBody.swift index 9cf0268d..1fffc5fa 100644 --- a/Bucketeer/Sources/Internal/Remote/RequestBody/RegisterEventsRequestBody.swift +++ b/Bucketeer/Sources/Internal/Remote/RequestBody/RegisterEventsRequestBody.swift @@ -2,4 +2,5 @@ import Foundation struct RegisterEventsRequestBody: Codable { let events: [Event] + let sdkVersion: String } diff --git a/BucketeerTests/ApiClientTests.swift b/BucketeerTests/ApiClientTests.swift index 87edfe60..fc42b7e3 100644 --- a/BucketeerTests/ApiClientTests.swift +++ b/BucketeerTests/ApiClientTests.swift @@ -37,6 +37,7 @@ class ApiClientTests: XCTestCase { let jsonString = String(data: data, encoding: .utf8) ?? "" let expected = """ { + "sdkVersion" : "\(Version.current)", "sourceId" : 2, "tag" : "tag1", "user" : { @@ -114,6 +115,7 @@ class ApiClientTests: XCTestCase { let jsonString = String(data: data, encoding: .utf8) ?? "" let expected = """ { + "sdkVersion" : "\(Version.current)", "sourceId" : 2, "tag" : "tag1", "user" : { @@ -247,7 +249,8 @@ class ApiClientTests: XCTestCase { "id" : "evaluation_event1", "type" : 3 } - ] + ], + "sdkVersion" : "\(Version.current)" } """ XCTAssertEqual(jsonString, expected) @@ -356,7 +359,8 @@ class ApiClientTests: XCTestCase { "id" : "evaluation_event1", "type" : 3 } - ] + ], + "sdkVersion" : "\(Version.current)" } """ XCTAssertEqual(jsonString, expected)