Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DIA-3500 post pv data call #13

Merged
merged 9 commits into from
Oct 23, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -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<String?>? = emptyList(),
val rejectedCategories: List<String?>? = emptyList()
) {
@Serializable
data class ConsentStatusGranularStatus (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -18,3 +20,5 @@ val jsonWithNulls = Json {
ignoreUnknownKeys = true
explicitNulls = true
}

fun String?.encodeToJsonObject() = this?.let { decodeFromString<JsonObject>(it) }
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,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
Expand Down Expand Up @@ -44,6 +46,8 @@ import kotlin.reflect.KSuspendFunction1
interface SPClient {
@Throws(Exception::class) suspend fun getMetaData(campaigns: MetaDataRequest.Campaigns): MetaDataResponse

@Throws(Exception::class) suspend fun postPvData(request: PvDataRequest): PvDataResponse

@Throws(Exception::class) suspend fun getConsentStatus(authId: String?, metadata: ConsentStatusRequest.MetaData): ConsentStatusResponse

@Throws(Exception::class) suspend fun getMessages(request: MessagesRequest): MessagesResponse
Expand Down Expand Up @@ -149,6 +153,15 @@ class SourcepointClient(
}.build()
).bodyOr(::reportErrorAndThrow)

override suspend fun postPvData(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")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
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



@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,
@SerialName("siteId") val propertyId: Int,
val consentStatus: ConsentStatus,
val pubData: JsonObject?,
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,
@SerialName("siteId") val propertyId: Int,
val consentStatus: ConsentStatus,
val pubData: JsonObject?,
val messageId: Int?,
val sampleRate : Float?
)

@Serializable
data class USNat (
val applies: Boolean,
val uuid: String?,
val accountId: 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 prtnUUID : String?
)
}
Original file line number Diff line number Diff line change
@@ -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
)
}