Skip to content

Commit

Permalink
IX: Set bidVideo when category and duration is available
Browse files Browse the repository at this point in the history
  • Loading branch information
RodionOrets committed May 20, 2021
1 parent cb62ab3 commit 819aa87
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 17 deletions.
59 changes: 45 additions & 14 deletions src/main/java/org/prebid/server/bidder/ix/IxBidder.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.prebid.server.bidder.ix;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.iab.openrtb.request.Banner;
import com.iab.openrtb.request.BidRequest;
import com.iab.openrtb.request.Format;
Expand All @@ -24,6 +26,8 @@
import org.prebid.server.proto.openrtb.ext.ExtPrebid;
import org.prebid.server.proto.openrtb.ext.request.ix.ExtImpIx;
import org.prebid.server.proto.openrtb.ext.response.BidType;
import org.prebid.server.proto.openrtb.ext.response.ExtBidPrebid;
import org.prebid.server.proto.openrtb.ext.response.ExtBidPrebidVideo;
import org.prebid.server.util.HttpUtil;

import java.util.ArrayList;
Expand All @@ -46,6 +50,8 @@ public class IxBidder implements Bidder<BidRequest> {
// maximum number of bid requests
private static final int REQUEST_LIMIT = 20;

private static final String PREBID = "prebid";

private final String endpointUrl;
private final JacksonMapper mapper;

Expand Down Expand Up @@ -194,21 +200,46 @@ public Result<List<BidderBid>> makeBids(HttpCall<BidRequest> httpCall, BidReques
}
}

private static List<BidderBid> extractBids(BidResponse bidResponse, BidRequest bidRequest) {
private List<BidderBid> extractBids(BidResponse bidResponse, BidRequest bidRequest) {
return bidResponse == null || CollectionUtils.isEmpty(bidResponse.getSeatbid())
? Collections.emptyList()
: bidsFromResponse(bidResponse, bidRequest);
}

private static List<BidderBid> bidsFromResponse(BidResponse bidResponse, BidRequest bidRequest) {
private List<BidderBid> bidsFromResponse(BidResponse bidResponse, BidRequest bidRequest) {
return bidResponse.getSeatbid().stream()
.map(SeatBid::getBid)
.flatMap(Collection::stream)
.map(bid -> prepareBid(bid, bidRequest))
.map(bid -> BidderBid.of(bid, getBidType(bid.getImpid(), bidRequest.getImp()), bidResponse.getCur()))
.map(bid -> toBidderBid(bid, bidRequest, bidResponse))
.collect(Collectors.toList());
}

private BidderBid toBidderBid(Bid bid, BidRequest bidRequest, BidResponse bidResponse) {
final BidType bidType = getBidType(bid.getImpid(), bidRequest.getImp());

Bid.BidBuilder bidBuilder = bid.toBuilder();

final boolean bidHasNoSizes = bid.getH() == null || bid.getW() == null;
final Banner banner = bidRequest.getImp().get(0).getBanner();
if (bidHasNoSizes && banner != null) {
bidBuilder
.w(banner.getW())
.h(banner.getH())
.build();
}

final ExtBidPrebid bidExt = parseBidExt(bid.getExt());
if (bidExt != null && bidExt.getVideo() != null) {
final ExtBidPrebidVideo video = bidExt.getVideo();
bidBuilder.ext(toBidExt(video));
if (bid.getCat().size() == 0) {
bidBuilder.cat(Collections.singletonList(video.getPrimaryCategory())).build();
}
}

return BidderBid.of(bidBuilder.build(), bidType, bidResponse.getCur());
}

private static BidType getBidType(String impId, List<Imp> imps) {
for (Imp imp : imps) {
if (imp.getId().equals(impId)) {
Expand All @@ -226,16 +257,16 @@ private static BidType getBidType(String impId, List<Imp> imps) {
throw new PreBidException(String.format("Unmatched impression id %s", impId));
}

private static Bid prepareBid(Bid bid, BidRequest bidRequest) {
// Current implementation ensure that we have at least one imp in request
final boolean bidHasNoSizes = bid.getH() == null || bid.getW() == null;
final Banner banner = bidRequest.getImp().get(0).getBanner();
if (bidHasNoSizes && banner != null) {
return bid.toBuilder()
.w(banner.getW())
.h(banner.getH())
.build();
private ExtBidPrebid parseBidExt(ObjectNode bidExt) {
try {
return bidExt == null ? null : mapper.mapper().treeToValue(bidExt, ExtBidPrebid.class);
} catch (JsonProcessingException e) {
throw new PreBidException(e.getMessage());
}
return bid;
}

private ObjectNode toBidExt(ExtBidPrebidVideo extBidVideo) {
return mapper.mapper().valueToTree(ExtBidPrebidVideo.of(extBidVideo.getDuration(), null));
}

}
6 changes: 3 additions & 3 deletions src/main/resources/bidder-config/ix.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
adapters:
ix:
enabled: false
endpoint: http://rubicon-us-east.lb.indexww.com/transbidder?p=189517
endpoint: https://
pbs-enforces-gdpr: true
pbs-enforces-ccpa: true
modifying-vast-xml-allowed: true
Expand All @@ -22,8 +22,8 @@ adapters:
supported-vendors:
vendor-id: 10
usersync:
url:
redirect-url:
url: https://ssum.casalemedia.com/usermatchredir?gdpr={{gdpr}}&gdpr_consent={{gdpr_consent}}&us_privacy={{us_privacy}}&r=
redirect-url: /setuid?bidder=ix&gdpr={{gdpr}}&gdpr_consent={{gdpr_consent}}&us_privacy={{us_privacy}}&uid={{uid}}
cookie-family-name: ix
type: redirect
support-cors: false
31 changes: 31 additions & 0 deletions src/test/java/org/prebid/server/bidder/ix/IxBidderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.prebid.server.proto.openrtb.ext.ExtPrebid;
import org.prebid.server.proto.openrtb.ext.request.ix.ExtImpIx;
import org.prebid.server.proto.openrtb.ext.response.BidType;
import org.prebid.server.proto.openrtb.ext.response.ExtBidPrebidVideo;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -374,6 +375,36 @@ public void makeBidsShouldReturnBannerBidWithRequestImpSizeWhenBidSizeIsEmpty()
.containsOnly(BidderBid.of(Bid.builder().impid("123").w(300).h(200).build(), BidType.banner, "EUR"));
}

@Test
public void makeBidsShouldReturnBidWithVideoExt() throws JsonProcessingException {
// given
final Video video = Video.builder().build();
final HttpCall<BidRequest> httpCall = givenHttpCall(
BidRequest.builder()
.imp(singletonList(Imp.builder().id("123").video(video).build()))
.build(),
mapper.writeValueAsString(
givenBidResponse(
bidBuilder -> bidBuilder
.impid("123")
.w(300).h(200)
.ext(mapper.valueToTree(ExtPrebid.of(null, ExtBidPrebidVideo.of(1, "cat")))))));

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

// then
assertThat(result.getErrors()).isEmpty();
assertThat(result.getValue())
.containsOnly(
BidderBid.of(Bid.builder()
.impid("123")
.w(300)
.h(200)
.ext(mapper.valueToTree(ExtPrebid.of(null, ExtBidPrebidVideo.of(1, "cat"))))
.build(), BidType.video, "EUR"));
}

private static BidRequest givenBidRequest(
Function<BidRequest.BidRequestBuilder, BidRequest.BidRequestBuilder> bidRequestCustomizer,
Function<Imp.ImpBuilder, Imp.ImpBuilder> impCustomizer) {
Expand Down

0 comments on commit 819aa87

Please sign in to comment.