From e2cd013d362fb336c6ddbae05ce7bf1f7929eadf Mon Sep 17 00:00:00 2001 From: Dmytro Date: Wed, 16 Oct 2024 13:37:07 +0200 Subject: [PATCH 1/5] Add `PvData` request and response class --- .../network/requests/PvDataRequest.kt | 57 +++++++++++++++++++ .../network/responses/PvDataResponse.kt | 15 +++++ 2 files changed, 72 insertions(+) create mode 100644 core/src/commonMain/kotlin/com/sourcepoint/mobile_core/network/requests/PvDataRequest.kt create mode 100644 core/src/commonMain/kotlin/com/sourcepoint/mobile_core/network/responses/PvDataResponse.kt diff --git a/core/src/commonMain/kotlin/com/sourcepoint/mobile_core/network/requests/PvDataRequest.kt b/core/src/commonMain/kotlin/com/sourcepoint/mobile_core/network/requests/PvDataRequest.kt new file mode 100644 index 0000000..14a6e2d --- /dev/null +++ b/core/src/commonMain/kotlin/com/sourcepoint/mobile_core/network/requests/PvDataRequest.kt @@ -0,0 +1,57 @@ +package com.sourcepoint.mobile_core.network.requests + +import com.sourcepoint.mobile_core.models.consents.ConsentStatus +import kotlinx.serialization.Contextual +import kotlinx.serialization.Serializable + +typealias SPPublisherData = Map + +@Serializable +data class PvDataRequest ( + val gdpr: GDPR?, + val ccpa: CCPA?, + val usnat: USNat? +) { + @Serializable + data class GDPR ( + val applies: Boolean, + val uuid: String?, + val accountId: Int, + val siteId: Int, + val consentStatus: ConsentStatus, + val pubData: SPPublisherData?, + val sampleRate: Float?, + val euconsent: String?, + val msgId: Int?, + val categoryId: Int?, + val subCategoryId: Int?, + val prtnUUID: String? + ) + + @Serializable + data class CCPA ( + val applies: Boolean, + val uuid: String?, + val accountId: Int, + val siteId: Int, + val consentStatus: ConsentStatus, + val pubData: SPPublisherData?, + val messageId: Int?, + val sampleRateval : Float? + ) + + @Serializable + data class USNat ( + val applies: Boolean, + val uuid: String?, + val accountId: Int, + val siteId: Int, + val consentStatus: ConsentStatus, + val pubData: SPPublisherData?, + val sampleRate: Float?, + val msgId: Int?, + val categoryId: Int?, + val subCategoryId: Int?, + val prtnUUIDval : String? + ) +} \ No newline at end of file diff --git a/core/src/commonMain/kotlin/com/sourcepoint/mobile_core/network/responses/PvDataResponse.kt b/core/src/commonMain/kotlin/com/sourcepoint/mobile_core/network/responses/PvDataResponse.kt new file mode 100644 index 0000000..02e4a0c --- /dev/null +++ b/core/src/commonMain/kotlin/com/sourcepoint/mobile_core/network/responses/PvDataResponse.kt @@ -0,0 +1,15 @@ +package com.sourcepoint.mobile_core.network.responses + +import kotlinx.serialization.Serializable + +@Serializable +data class PvDataResponse ( + val gdpr: Campaign?, + val ccpa: Campaign?, + val usnat: Campaign? +) { + @Serializable + data class Campaign ( + val uuid: String + ) +} \ No newline at end of file From 119cc7e80861bb7ca83a3f771efa0f9b8f01d17f Mon Sep 17 00:00:00 2001 From: Dmytro Date: Wed, 16 Oct 2024 13:38:30 +0200 Subject: [PATCH 2/5] Add `getPvData` post method and update `ConsentStatus` --- .../mobile_core/models/consents/ConsentStatus.kt | 4 +++- .../mobile_core/network/SourcepointClient.kt | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/core/src/commonMain/kotlin/com/sourcepoint/mobile_core/models/consents/ConsentStatus.kt b/core/src/commonMain/kotlin/com/sourcepoint/mobile_core/models/consents/ConsentStatus.kt index 47eb936..400b7af 100644 --- a/core/src/commonMain/kotlin/com/sourcepoint/mobile_core/models/consents/ConsentStatus.kt +++ b/core/src/commonMain/kotlin/com/sourcepoint/mobile_core/models/consents/ConsentStatus.kt @@ -13,7 +13,9 @@ data class ConsentStatus ( val hasConsentData: Boolean? = null, val vendorListAdditions: Boolean? = null, val legalBasisChanges: Boolean? = null, - val granularStatus: ConsentStatusGranularStatus? = null + val granularStatus: ConsentStatusGranularStatus? = null, + val rejectedVendors: List? = emptyList(), + val rejectedCategories: List? = emptyList() ) { @Serializable data class ConsentStatusGranularStatus ( diff --git a/core/src/commonMain/kotlin/com/sourcepoint/mobile_core/network/SourcepointClient.kt b/core/src/commonMain/kotlin/com/sourcepoint/mobile_core/network/SourcepointClient.kt index 6b88f0e..fa77a35 100644 --- a/core/src/commonMain/kotlin/com/sourcepoint/mobile_core/network/SourcepointClient.kt +++ b/core/src/commonMain/kotlin/com/sourcepoint/mobile_core/network/SourcepointClient.kt @@ -13,10 +13,12 @@ import com.sourcepoint.mobile_core.network.requests.CustomConsentRequest import com.sourcepoint.mobile_core.network.requests.DefaultRequest import com.sourcepoint.mobile_core.network.requests.MetaDataRequest import com.sourcepoint.mobile_core.network.requests.MessagesRequest +import com.sourcepoint.mobile_core.network.requests.PvDataRequest import com.sourcepoint.mobile_core.network.requests.toQueryParams import com.sourcepoint.mobile_core.network.responses.ConsentStatusResponse import com.sourcepoint.mobile_core.network.responses.MessagesResponse import com.sourcepoint.mobile_core.network.responses.MetaDataResponse +import com.sourcepoint.mobile_core.network.responses.PvDataResponse import io.ktor.client.HttpClient import io.ktor.client.HttpClientConfig import io.ktor.client.call.body @@ -45,6 +47,8 @@ import kotlin.reflect.KSuspendFunction1 interface SPClient { suspend fun getMetaData(campaigns: MetaDataRequest.Campaigns): MetaDataResponse + suspend fun getPvData(request: PvDataRequest): PvDataResponse + suspend fun getConsentStatus(authId: String?, metadata: ConsentStatusRequest.MetaData): ConsentStatusResponse suspend fun getMessages(request: MessagesRequest): MessagesResponse @@ -150,6 +154,15 @@ class SourcepointClient( }.build() ).bodyOr(::reportErrorAndThrow) + override suspend fun getPvData(request: PvDataRequest): PvDataResponse = + http.post(URLBuilder(baseWrapperUrl).apply { + path("wrapper", "v2", "pv-data") + withParams(DefaultRequest()) + }.build()) { + contentType(ContentType.Application.Json) + setBody(request) + }.bodyOr(::reportErrorAndThrow) + override suspend fun getConsentStatus(authId: String?, metadata: ConsentStatusRequest.MetaData): ConsentStatusResponse = http.get(URLBuilder(baseWrapperUrl).apply { path("wrapper", "v2", "consent-status") From 03f0f32114e53e693f6ca13e2471c13a7c9af0e8 Mon Sep 17 00:00:00 2001 From: Dmytro Date: Tue, 22 Oct 2024 14:18:55 +0200 Subject: [PATCH 3/5] Fix `pubData` --- .../kotlin/com/sourcepoint/mobile_core/network/Json.kt | 6 ++++++ .../sourcepoint/mobile_core/network/SourcepointClient.kt | 4 ++-- .../mobile_core/network/requests/PvDataRequest.kt | 9 +++++---- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/core/src/commonMain/kotlin/com/sourcepoint/mobile_core/network/Json.kt b/core/src/commonMain/kotlin/com/sourcepoint/mobile_core/network/Json.kt index 2b7de63..a368538 100644 --- a/core/src/commonMain/kotlin/com/sourcepoint/mobile_core/network/Json.kt +++ b/core/src/commonMain/kotlin/com/sourcepoint/mobile_core/network/Json.kt @@ -2,6 +2,8 @@ package com.sourcepoint.mobile_core.network import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.json.Json +import kotlinx.serialization.json.Json.Default.decodeFromString +import kotlinx.serialization.json.JsonObject @OptIn(ExperimentalSerializationApi::class) val json = Json { @@ -16,3 +18,7 @@ val jsonWithNulls = Json { ignoreUnknownKeys = true explicitNulls = true } + +fun StringToJsonObject(str: String): JsonObject { + return decodeFromString(str) +} \ No newline at end of file diff --git a/core/src/commonMain/kotlin/com/sourcepoint/mobile_core/network/SourcepointClient.kt b/core/src/commonMain/kotlin/com/sourcepoint/mobile_core/network/SourcepointClient.kt index 00b7fc1..128ed49 100644 --- a/core/src/commonMain/kotlin/com/sourcepoint/mobile_core/network/SourcepointClient.kt +++ b/core/src/commonMain/kotlin/com/sourcepoint/mobile_core/network/SourcepointClient.kt @@ -46,7 +46,7 @@ import kotlin.reflect.KSuspendFunction1 interface SPClient { suspend fun getMetaData(campaigns: MetaDataRequest.Campaigns): MetaDataResponse - suspend fun getPvData(request: PvDataRequest): PvDataResponse + suspend fun postPvData(request: PvDataRequest): PvDataResponse suspend fun getConsentStatus(authId: String?, metadata: ConsentStatusRequest.MetaData): ConsentStatusResponse @@ -153,7 +153,7 @@ class SourcepointClient( }.build() ).bodyOr(::reportErrorAndThrow) - override suspend fun getPvData(request: PvDataRequest): PvDataResponse = + override suspend fun postPvData(request: PvDataRequest): PvDataResponse = http.post(URLBuilder(baseWrapperUrl).apply { path("wrapper", "v2", "pv-data") withParams(DefaultRequest()) diff --git a/core/src/commonMain/kotlin/com/sourcepoint/mobile_core/network/requests/PvDataRequest.kt b/core/src/commonMain/kotlin/com/sourcepoint/mobile_core/network/requests/PvDataRequest.kt index 14a6e2d..21271db 100644 --- a/core/src/commonMain/kotlin/com/sourcepoint/mobile_core/network/requests/PvDataRequest.kt +++ b/core/src/commonMain/kotlin/com/sourcepoint/mobile_core/network/requests/PvDataRequest.kt @@ -3,8 +3,9 @@ package com.sourcepoint.mobile_core.network.requests import com.sourcepoint.mobile_core.models.consents.ConsentStatus import kotlinx.serialization.Contextual import kotlinx.serialization.Serializable +import kotlinx.serialization.json.JsonObject + -typealias SPPublisherData = Map @Serializable data class PvDataRequest ( @@ -19,7 +20,7 @@ data class PvDataRequest ( val accountId: Int, val siteId: Int, val consentStatus: ConsentStatus, - val pubData: SPPublisherData?, + val pubData: JsonObject?, val sampleRate: Float?, val euconsent: String?, val msgId: Int?, @@ -35,7 +36,7 @@ data class PvDataRequest ( val accountId: Int, val siteId: Int, val consentStatus: ConsentStatus, - val pubData: SPPublisherData?, + val pubData: JsonObject?, val messageId: Int?, val sampleRateval : Float? ) @@ -47,7 +48,7 @@ data class PvDataRequest ( val accountId: Int, val siteId: Int, val consentStatus: ConsentStatus, - val pubData: SPPublisherData?, + val pubData: JsonObject?, val sampleRate: Float?, val msgId: Int?, val categoryId: Int?, From 8605b99b3a7b5be66ba5cfabcedc48ce8a841a6e Mon Sep 17 00:00:00 2001 From: Dmytro Date: Wed, 23 Oct 2024 12:12:01 +0200 Subject: [PATCH 4/5] Code review fix --- .../com/sourcepoint/mobile_core/network/Json.kt | 4 +--- .../mobile_core/network/SourcepointClient.kt | 2 +- .../mobile_core/network/requests/PvDataRequest.kt | 13 +++++++------ .../mobile_core/network/responses/PvDataResponse.kt | 2 +- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/core/src/commonMain/kotlin/com/sourcepoint/mobile_core/network/Json.kt b/core/src/commonMain/kotlin/com/sourcepoint/mobile_core/network/Json.kt index a368538..cf8fff4 100644 --- a/core/src/commonMain/kotlin/com/sourcepoint/mobile_core/network/Json.kt +++ b/core/src/commonMain/kotlin/com/sourcepoint/mobile_core/network/Json.kt @@ -19,6 +19,4 @@ val jsonWithNulls = Json { explicitNulls = true } -fun StringToJsonObject(str: String): JsonObject { - return decodeFromString(str) -} \ No newline at end of file +fun String.encodeToJsonObject() = decodeFromString(this) diff --git a/core/src/commonMain/kotlin/com/sourcepoint/mobile_core/network/SourcepointClient.kt b/core/src/commonMain/kotlin/com/sourcepoint/mobile_core/network/SourcepointClient.kt index 128ed49..5e53f68 100644 --- a/core/src/commonMain/kotlin/com/sourcepoint/mobile_core/network/SourcepointClient.kt +++ b/core/src/commonMain/kotlin/com/sourcepoint/mobile_core/network/SourcepointClient.kt @@ -46,7 +46,7 @@ import kotlin.reflect.KSuspendFunction1 interface SPClient { suspend fun getMetaData(campaigns: MetaDataRequest.Campaigns): MetaDataResponse - suspend fun postPvData(request: PvDataRequest): PvDataResponse + @Throws(Exception::class) suspend fun postPvData(request: PvDataRequest): PvDataResponse suspend fun getConsentStatus(authId: String?, metadata: ConsentStatusRequest.MetaData): ConsentStatusResponse diff --git a/core/src/commonMain/kotlin/com/sourcepoint/mobile_core/network/requests/PvDataRequest.kt b/core/src/commonMain/kotlin/com/sourcepoint/mobile_core/network/requests/PvDataRequest.kt index 21271db..4d14d6a 100644 --- a/core/src/commonMain/kotlin/com/sourcepoint/mobile_core/network/requests/PvDataRequest.kt +++ b/core/src/commonMain/kotlin/com/sourcepoint/mobile_core/network/requests/PvDataRequest.kt @@ -2,6 +2,7 @@ package com.sourcepoint.mobile_core.network.requests import com.sourcepoint.mobile_core.models.consents.ConsentStatus import kotlinx.serialization.Contextual +import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import kotlinx.serialization.json.JsonObject @@ -18,7 +19,7 @@ data class PvDataRequest ( val applies: Boolean, val uuid: String?, val accountId: Int, - val siteId: Int, + @SerialName("siteId") val propertyId: Int, val consentStatus: ConsentStatus, val pubData: JsonObject?, val sampleRate: Float?, @@ -34,11 +35,11 @@ data class PvDataRequest ( val applies: Boolean, val uuid: String?, val accountId: Int, - val siteId: Int, + @SerialName("siteId") val propertyId: Int, val consentStatus: ConsentStatus, val pubData: JsonObject?, val messageId: Int?, - val sampleRateval : Float? + val sampleRate : Float? ) @Serializable @@ -46,13 +47,13 @@ data class PvDataRequest ( val applies: Boolean, val uuid: String?, val accountId: Int, - val siteId: Int, + @SerialName("siteId") val propertyId: Int, val consentStatus: ConsentStatus, val pubData: JsonObject?, val sampleRate: Float?, val msgId: Int?, val categoryId: Int?, val subCategoryId: Int?, - val prtnUUIDval : String? + val prtnUUID : String? ) -} \ No newline at end of file +} diff --git a/core/src/commonMain/kotlin/com/sourcepoint/mobile_core/network/responses/PvDataResponse.kt b/core/src/commonMain/kotlin/com/sourcepoint/mobile_core/network/responses/PvDataResponse.kt index 02e4a0c..c1ea6d3 100644 --- a/core/src/commonMain/kotlin/com/sourcepoint/mobile_core/network/responses/PvDataResponse.kt +++ b/core/src/commonMain/kotlin/com/sourcepoint/mobile_core/network/responses/PvDataResponse.kt @@ -12,4 +12,4 @@ data class PvDataResponse ( data class Campaign ( val uuid: String ) -} \ No newline at end of file +} From 05d5dffb241e3f0e9bdaaf0f479fdd8cafe6d223 Mon Sep 17 00:00:00 2001 From: Dmytro Date: Wed, 23 Oct 2024 14:15:32 +0200 Subject: [PATCH 5/5] Make `encodeToJsonObject` nullable --- .../kotlin/com/sourcepoint/mobile_core/network/Json.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/commonMain/kotlin/com/sourcepoint/mobile_core/network/Json.kt b/core/src/commonMain/kotlin/com/sourcepoint/mobile_core/network/Json.kt index 7140630..4701e1b 100644 --- a/core/src/commonMain/kotlin/com/sourcepoint/mobile_core/network/Json.kt +++ b/core/src/commonMain/kotlin/com/sourcepoint/mobile_core/network/Json.kt @@ -21,4 +21,4 @@ val jsonWithNulls = Json { explicitNulls = true } -fun String.encodeToJsonObject() = decodeFromString(this) +fun String?.encodeToJsonObject() = this?.let { decodeFromString(it) }