Skip to content

Commit

Permalink
chore: add the sdkVersion in the requests
Browse files Browse the repository at this point in the history
  • Loading branch information
duyhungtnn committed Sep 27, 2023
1 parent 5378908 commit a173c80
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
6 changes: 4 additions & 2 deletions Bucketeer/Sources/Internal/Remote/ApiClientImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ final class ApiClientImpl: ApiClient {
userEvaluationsId: userEvaluationsId,
sourceId: .ios,
userEvaluationCondition: UserEvaluationCondition(evaluatedAt: condition.evaluatedAt,
userAttributesUpdated: condition.userAttributesUpdated)
userAttributesUpdated: condition.userAttributesUpdated),
sdkVersion: Version.current
)
let featureTag = self.featureTag
let timeoutMillisValue = timeoutMillis ?? defaultRequestTimeoutMills
Expand Down Expand Up @@ -78,7 +79,8 @@ final class ApiClientImpl: ApiClient {

func registerEvents(events: [Event], completion: ((Result<RegisterEventsResponse, BKTError>) -> Void)?) {
let requestBody = RegisterEventsRequestBody(
events: events
events: events,
sdkVersion: Version.current
)
logger?.debug(message: "[API] Register events: \(requestBody)")
let encoder = JSONEncoder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ struct GetEvaluationsRequestBody: Codable {
let userEvaluationsId: String
let sourceId: SourceID
let userEvaluationCondition: UserEvaluationCondition
// noted: we didn't set the default value to prevent the warning about Decodeable will not work
// error message "Immutable property will not be decoded because it is declared with an initial value which cannot be overwritten"
let sdkVersion: String
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ import Foundation

struct RegisterEventsRequestBody: Codable {
let events: [Event]
let sdkVersion: String
}
8 changes: 6 additions & 2 deletions BucketeerTests/ApiClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class ApiClientTests: XCTestCase {
let jsonString = String(data: data, encoding: .utf8) ?? ""
let expected = """
{
"sdkVersion" : "\(Version.current)",
"sourceId" : 2,
"tag" : "tag1",
"user" : {
Expand Down Expand Up @@ -114,6 +115,7 @@ class ApiClientTests: XCTestCase {
let jsonString = String(data: data, encoding: .utf8) ?? ""
let expected = """
{
"sdkVersion" : "\(Version.current)",
"sourceId" : 2,
"tag" : "tag1",
"user" : {
Expand Down Expand Up @@ -247,7 +249,8 @@ class ApiClientTests: XCTestCase {
"id" : "evaluation_event1",
"type" : 3
}
]
],
"sdkVersion" : "\(Version.current)"
}
"""
XCTAssertEqual(jsonString, expected)
Expand Down Expand Up @@ -356,7 +359,8 @@ class ApiClientTests: XCTestCase {
"id" : "evaluation_event1",
"type" : 3
}
]
],
"sdkVersion" : "\(Version.current)"
}
"""
XCTAssertEqual(jsonString, expected)
Expand Down

0 comments on commit a173c80

Please sign in to comment.