Skip to content

Commit

Permalink
RTB House: Resolve oRTB AUCTION_PRICE macro (#3421)
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrj-rtbh authored Sep 9, 2024
1 parent 509d2a4 commit 1e02fc4
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class RtbhouseBidder implements Bidder<BidRequest> {
new TypeReference<>() {
};
private static final String BIDDER_CURRENCY = "USD";
private static final String PRICE_MACRO = "${AUCTION_PRICE}";

private final String endpointUrl;
private final JacksonMapper mapper;
Expand Down Expand Up @@ -127,7 +128,7 @@ private BidderBid resolveBidderBid(Bid bid,
.build();

return BidderBid.builder()
.bid(updatedBid)
.bid(resolveMacros(updatedBid))
.type(bidType)
.bidCurrency(currency)
.build();
Expand Down Expand Up @@ -212,4 +213,14 @@ private Price convertBidFloor(Price bidFloorPrice, String impId, BidRequest bidR
}
}

private static Bid resolveMacros(Bid bid) {
final BigDecimal price = bid.getPrice();
final String priceAsString = price != null ? price.toPlainString() : "0";

return bid.toBuilder()
.nurl(StringUtils.replace(bid.getNurl(), PRICE_MACRO, priceAsString))
.adm(StringUtils.replace(bid.getAdm(), PRICE_MACRO, priceAsString))
.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,28 @@ public void makeBidsShouldParseNativeAdmData() throws JsonProcessingException {
.containsExactly("{\"property1\":\"value1\"}");
}

@Test
public void makeBidsShouldReturnBidWithResolvedMacros() throws JsonProcessingException {
// given
final BidRequest bidRequest = givenBidRequest(impBuilder -> impBuilder.banner(null));
final BidderCall<BidRequest> httpCall = givenHttpCall(null,
mapper.writeValueAsString(givenBidResponse(
bidBuilder -> bidBuilder
.nurl("nurl:${AUCTION_PRICE}")
.adm("adm:${AUCTION_PRICE}")
.price(BigDecimal.valueOf(12.34)))));

// when
final Result<List<BidderBid>> result = target.makeBids(httpCall, bidRequest);

// then
assertThat(result.getErrors()).isEmpty();
assertThat(result.getValue())
.extracting(BidderBid::getBid)
.extracting(Bid::getNurl, Bid::getAdm)
.containsExactly(tuple("nurl:12.34", "adm:12.34"));
}

private static BidResponse givenBidResponse(Function<Bid.BidBuilder, Bid.BidBuilder> bidCustomizer) {
return BidResponse.builder()
.cur("USD")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"id": "bid_id",
"impid": "imp_id",
"price": 0.5,
"adm": "some-test-ad",
"adm": "some-test-ad_0.5",
"adid": "12345678",
"cid": "987",
"crid": "12345678",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"impid": "imp_id",
"price": 0.500000,
"adid": "12345678",
"adm": "some-test-ad",
"adm": "some-test-ad_${AUCTION_PRICE}",
"cid": "987",
"crid": "12345678",
"h": 250,
Expand Down

0 comments on commit 1e02fc4

Please sign in to comment.