Skip to content

Commit a56520b

Browse files
author
Renam Philippi Antunes
authored
change BidResponse.ext to be a JsonElement (#155)
* change BidResponse.ext to a class, updates tests
1 parent e087abb commit a56520b

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

kotlin/src/commonMain/kotlin/com/adsbynimbus/openrtb/response/BidResponse.kt

+11-4
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public class BidResponse(
5555
@JvmField @SerialName("duration") public val duration: Int = 0,
5656
@JvmField @SerialName("exp") public val exp: Int = -1,
5757
@JvmField @SerialName("external_notifications") public val external_notifications: Map<String, String> = emptyMap(),
58-
@JvmField @SerialName("ext") public val ext: Map<String, String> = emptyMap(),
58+
@JvmField @SerialName("ext") public val ext: Extension = Extension(),
5959
) {
6060
/** Urls to fire a request to when an impression is registered */
6161
public val impression_trackers: Array<String>? get() = trackers["impression_trackers"]
@@ -66,9 +66,6 @@ public class BidResponse(
6666
/** Url to fire a request to when this bid loses an auction */
6767
public val loss_response: String? get() = external_notifications["loss_response"]
6868

69-
public val useNewRenderer: Boolean
70-
get() = ext["use_new_renderer"].toBoolean()
71-
7269
public companion object {
7370
/** Decodes a BidResponse from a Json string using the built in serializer */
7471
@JvmStatic @JvmOverloads
@@ -84,4 +81,14 @@ public class BidResponse(
8481
jsonSerializer: Json = BidRequest.lenientSerializer,
8582
): String = jsonSerializer.encodeToString(serializer(), response)
8683
}
84+
85+
/**
86+
* BidResponse Extension object from Nimbus
87+
*
88+
* @property use_new_renderer Set to false if Nimbus has determined the creative should be rendered using IMA SDK
89+
*/
90+
@Serializable
91+
public class Extension(
92+
@JvmField @SerialName("use_new_renderer") public val use_new_renderer: Boolean = false,
93+
)
8794
}

kotlin/src/commonTest/kotlin/com/adsbynimbus/openrtb/response/DeserializationTest.kt

+17-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import io.kotest.matchers.shouldBe
66
import io.kotest.matchers.string.shouldContain
77
import io.kotest.matchers.string.shouldStartWith
88

9-
const val testJson = """
9+
private fun testJson(ext: String = "") = """
1010
{
1111
"type": "native",
1212
"auction_id": "d07668d6-35ba-4870-a3cd-02b18fec1a12",
@@ -33,12 +33,13 @@ const val testJson = """
3333
"win_response": "https://test.adsbynimbus.com/win_response/",
3434
"loss_response": "https://test.adsbynimbus.com/loss_response/auctionPrice=[AUCTION_PRICE]&auctionMinToWin=[AUCTION_MIN_TO_WIN]&winningSource=[WINNING_SOURCE]"
3535
}
36+
$ext
3637
}
3738
"""
3839

3940
class DeserializationTest : StringSpec({
4041

41-
val response = BidResponse.fromJson(testJson)
42+
val response = BidResponse.fromJson(testJson())
4243

4344
"BidResponse fromJson deserializes the type field" {
4445
response.type shouldBe "native"
@@ -104,6 +105,20 @@ class DeserializationTest : StringSpec({
104105
response.win_response shouldBe "https://test.adsbynimbus.com/win_response/"
105106
}
106107

108+
"BidResponse fromJson deserializes use_new_renderer" {
109+
response.ext.use_new_renderer shouldBe false
110+
BidResponse.fromJson(testJson("""
111+
,"ext": {
112+
"use_new_renderer": true
113+
}
114+
""".trimIndent())).ext.use_new_renderer shouldBe true
115+
BidResponse.fromJson(testJson("""
116+
,"ext": {
117+
"use_new_renderer": false
118+
}
119+
""".trimIndent())).ext.use_new_renderer shouldBe false
120+
}
121+
107122
"BidResponse fromJson deserializes loss urls" {
108123
response.loss_response shouldStartWith "https://test.adsbynimbus.com/loss_response/"
109124
response.loss_response shouldContain "auctionPrice=[AUCTION_PRICE]"

0 commit comments

Comments
 (0)