diff --git a/kotlin/src/commonMain/kotlin/com/adsbynimbus/openrtb/response/BidResponse.kt b/kotlin/src/commonMain/kotlin/com/adsbynimbus/openrtb/response/BidResponse.kt index 9f8c5fc..0eba05e 100644 --- a/kotlin/src/commonMain/kotlin/com/adsbynimbus/openrtb/response/BidResponse.kt +++ b/kotlin/src/commonMain/kotlin/com/adsbynimbus/openrtb/response/BidResponse.kt @@ -55,7 +55,7 @@ public class BidResponse( @JvmField @SerialName("duration") public val duration: Int = 0, @JvmField @SerialName("exp") public val exp: Int = -1, @JvmField @SerialName("external_notifications") public val external_notifications: Map = emptyMap(), - @JvmField @SerialName("ext") public val ext: Map = emptyMap(), + @JvmField @SerialName("ext") public val ext: Extension = Extension(), ) { /** Urls to fire a request to when an impression is registered */ public val impression_trackers: Array? get() = trackers["impression_trackers"] @@ -66,9 +66,6 @@ public class BidResponse( /** Url to fire a request to when this bid loses an auction */ public val loss_response: String? get() = external_notifications["loss_response"] - public val useNewRenderer: Boolean - get() = ext["use_new_renderer"].toBoolean() - public companion object { /** Decodes a BidResponse from a Json string using the built in serializer */ @JvmStatic @JvmOverloads @@ -84,4 +81,14 @@ public class BidResponse( jsonSerializer: Json = BidRequest.lenientSerializer, ): String = jsonSerializer.encodeToString(serializer(), response) } + + /** + * BidResponse Extension object from Nimbus + * + * @property use_new_renderer Set to false if Nimbus has determined the creative should be rendered using IMA SDK + */ + @Serializable + public class Extension( + @JvmField @SerialName("use_new_renderer") public val use_new_renderer: Boolean = false, + ) } diff --git a/kotlin/src/commonTest/kotlin/com/adsbynimbus/openrtb/response/DeserializationTest.kt b/kotlin/src/commonTest/kotlin/com/adsbynimbus/openrtb/response/DeserializationTest.kt index 1fe4ce1..22d5c2f 100644 --- a/kotlin/src/commonTest/kotlin/com/adsbynimbus/openrtb/response/DeserializationTest.kt +++ b/kotlin/src/commonTest/kotlin/com/adsbynimbus/openrtb/response/DeserializationTest.kt @@ -6,7 +6,7 @@ import io.kotest.matchers.shouldBe import io.kotest.matchers.string.shouldContain import io.kotest.matchers.string.shouldStartWith -const val testJson = """ +private fun testJson(ext: String = "") = """ { "type": "native", "auction_id": "d07668d6-35ba-4870-a3cd-02b18fec1a12", @@ -33,12 +33,13 @@ const val testJson = """ "win_response": "https://test.adsbynimbus.com/win_response/", "loss_response": "https://test.adsbynimbus.com/loss_response/auctionPrice=[AUCTION_PRICE]&auctionMinToWin=[AUCTION_MIN_TO_WIN]&winningSource=[WINNING_SOURCE]" } + $ext } """ class DeserializationTest : StringSpec({ - val response = BidResponse.fromJson(testJson) + val response = BidResponse.fromJson(testJson()) "BidResponse fromJson deserializes the type field" { response.type shouldBe "native" @@ -104,6 +105,20 @@ class DeserializationTest : StringSpec({ response.win_response shouldBe "https://test.adsbynimbus.com/win_response/" } + "BidResponse fromJson deserializes use_new_renderer" { + response.ext.use_new_renderer shouldBe false + BidResponse.fromJson(testJson(""" + ,"ext": { + "use_new_renderer": true + } + """.trimIndent())).ext.use_new_renderer shouldBe true + BidResponse.fromJson(testJson(""" + ,"ext": { + "use_new_renderer": false + } + """.trimIndent())).ext.use_new_renderer shouldBe false + } + "BidResponse fromJson deserializes loss urls" { response.loss_response shouldStartWith "https://test.adsbynimbus.com/loss_response/" response.loss_response shouldContain "auctionPrice=[AUCTION_PRICE]"