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

Retrieve bid type from bid.ext.mediatype in Yieldmo bid response #2759

Merged
merged 7 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions src/main/java/org/prebid/server/bidder/yieldmo/YieldmoBidder.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.prebid.server.bidder.model.BidderError;
import org.prebid.server.bidder.model.HttpRequest;
import org.prebid.server.bidder.model.Result;
import org.prebid.server.bidder.yieldmo.proto.YieldmoBidExt;
import org.prebid.server.bidder.yieldmo.proto.YieldmoImpExt;
import org.prebid.server.exception.PreBidException;
import org.prebid.server.json.DecodeException;
Expand Down Expand Up @@ -97,13 +98,13 @@ private HttpRequest<BidRequest> makeRequest(BidRequest bidRequest) {
public Result<List<BidderBid>> makeBids(BidderCall<BidRequest> httpCall, BidRequest bidRequest) {
try {
final BidResponse bidResponse = mapper.decodeValue(httpCall.getResponse().getBody(), BidResponse.class);
return Result.withValues(extractBids(httpCall.getRequest().getPayload(), bidResponse));
return Result.withValues(extractBids(bidResponse));
} catch (DecodeException e) {
return Result.withError(BidderError.badServerResponse(e.getMessage()));
}
}

private static List<BidderBid> extractBids(BidRequest bidRequest, BidResponse bidResponse) {
private List<BidderBid> extractBids(BidResponse bidResponse) {
if (bidResponse == null || CollectionUtils.isEmpty(bidResponse.getSeatbid())) {
return Collections.emptyList();
}
Expand All @@ -114,16 +115,20 @@ private static List<BidderBid> extractBids(BidRequest bidRequest, BidResponse bi
.filter(Objects::nonNull)
.flatMap(Collection::stream)
.filter(Objects::nonNull)
.map(bid -> BidderBid.of(bid, resolveBidType(bid, bidRequest.getImp()), bidResponse.getCur()))
.map(bid -> {
final BidType bidType = resolveBidType(bid);
return bidType != null ? BidderBid.of(bid, bidType, bidResponse.getCur()) : null;
})
.filter(Objects::nonNull)
.toList();
}

private static BidType resolveBidType(Bid bid, List<Imp> imps) {
for (Imp imp : imps) {
if (Objects.equals(imp.getId(), bid.getImpid())) {
return imp.getBanner() != null ? BidType.banner : BidType.video;
}
private BidType resolveBidType(Bid bid) {
try {
final YieldmoBidExt bidExt = mapper.mapper().treeToValue(bid.getExt(), YieldmoBidExt.class);
return BidType.fromString(bidExt.getMediaType());
} catch (Exception e) {
return null;
}
return BidType.video;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.prebid.server.bidder.yieldmo.proto;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Value;

/**
* Defines the contract for bidresponse.seatbid[i].bid[i].ext
*/
@Value(staticConstructor = "of")
public class YieldmoBidExt {

@JsonProperty("mediatype")
String mediaType;
}

Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.prebid.server.bidder.yieldmo;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.node.TextNode;
import com.iab.openrtb.request.Banner;
Expand Down Expand Up @@ -199,7 +201,7 @@ public void makeBidsShouldReturnEmptyListIfBidResponseSeatBidIsNull() throws Jso
}

@Test
public void makeBidsShouldReturnVideoBidByDefault() throws JsonProcessingException {
public void makeBidsShouldReturnEmptyListIfBidExtHasNoMediaType() throws JsonProcessingException {
// given
final BidderCall<BidRequest> httpCall = givenHttpCall(
BidRequest.builder()
Expand All @@ -213,8 +215,7 @@ public void makeBidsShouldReturnVideoBidByDefault() throws JsonProcessingExcepti

// then
assertThat(result.getErrors()).isEmpty();
assertThat(result.getValue())
.containsExactly(BidderBid.of(Bid.builder().impid("123").build(), video, "USD"));
assertThat(result.getValue()).isEmpty();
}

@Test
Expand All @@ -225,15 +226,16 @@ public void makeBidsShouldReturnBannerBidIfBannerIsPresentInRequestImp() throws
.imp(singletonList(Imp.builder().banner(Banner.builder().build()).id("123").build()))
.build(),
mapper.writeValueAsString(
givenBidResponse(bidBuilder -> bidBuilder.impid("123"))));
givenBidResponse(bidBuilder -> bidBuilder.impid("123").ext(toObjectNode("banner")))));

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

// then
assertThat(result.getErrors()).isEmpty();
assertThat(result.getValue())
.containsExactly(BidderBid.of(Bid.builder().impid("123").build(), banner, "USD"));
.containsExactly(BidderBid.of(Bid.builder().impid("123").ext(toObjectNode("banner")).build(),
banner, "USD"));
}

@Test
Expand All @@ -244,15 +246,16 @@ public void makeBidsShouldReturnVideoBidIfVideoIsPresentInRequestImp() throws Js
.imp(singletonList(Imp.builder().video(Video.builder().build()).id("123").build()))
.build(),
mapper.writeValueAsString(
givenBidResponse(bidBuilder -> bidBuilder.impid("123"))));
givenBidResponse(bidBuilder -> bidBuilder.impid("123").ext(toObjectNode("video")))));

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

// then
assertThat(result.getErrors()).isEmpty();
assertThat(result.getValue())
.containsExactly(BidderBid.of(Bid.builder().impid("123").build(), video, "USD"));
.containsExactly(BidderBid.of(Bid.builder().impid("123").ext(toObjectNode("video")).build(),
video, "USD"));
}

private static BidRequest givenBidRequest(
Expand Down Expand Up @@ -291,4 +294,11 @@ private static BidderCall<BidRequest> givenHttpCall(BidRequest bidRequest, Strin
HttpResponse.of(200, null, body),
null);
}

private ObjectNode toObjectNode(String mediaType) {
final ObjectMapper mapper = new ObjectMapper();
final ObjectNode root = mapper.createObjectNode();
root.set("mediatype", mapper.convertValue(mediaType, JsonNode.class));
return root;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"prebid": {
"type": "banner"
},
"origbidcpm": 3.33
"origbidcpm": 3.33,
"mediatype": "banner"
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
"cid": "cid",
"adm": "adm001",
"h": 250,
"w": 300
"w": 300,
"ext" : {
"mediatype" : "banner"
}
}
]
}
]
}
}
Loading