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 19, 2021
1 parent 378d0dc commit 49ae4bb
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 16 deletions.
64 changes: 50 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,9 +26,12 @@
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;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
Expand All @@ -46,6 +51,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 +201,48 @@ 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());

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

final ExtBidPrebid bidExt = parseBidExt(bid.getExt());
if (bidExt != null && bidExt.getVideo() != null) {
final ExtBidPrebidVideo video = bidExt.getVideo();
bid = bid.toBuilder()
.ext(toBidderBidExt(video))
.build();
if (bid.getCat().size() == 0) {
bid = bid.toBuilder()
.cat(Arrays.asList(video.getPrimaryCategory()))
.build();
}
}

return BidderBid.of(bid, 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 +260,18 @@ 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 toBidderBidExt(ExtBidPrebidVideo extBidVideo) {
return mapper.mapper().valueToTree(ExtBidPrebidVideo.of(extBidVideo.getDuration(), null));
}

}
4 changes: 2 additions & 2 deletions src/main/resources/bidder-config/ix.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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=improvedigital&gdpr={{gdpr}}&gdpr_consent={{gdpr_consent}}&us_privacy={{us_privacy}}&uid={{uid}}
cookie-family-name: ix
type: redirect
support-cors: false

0 comments on commit 49ae4bb

Please sign in to comment.