Skip to content

Commit

Permalink
Update pulsepoint adapter (#1140)
Browse files Browse the repository at this point in the history
* Update pulsepoint adapter

* Fix test
  • Loading branch information
BraslavskiyAndrey authored and nickluck8 committed Aug 10, 2021
1 parent bee049e commit 7b84d11
Show file tree
Hide file tree
Showing 8 changed files with 230 additions and 174 deletions.
10 changes: 9 additions & 1 deletion src/main/java/org/prebid/server/bidder/OpenrtbBidder.java
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,18 @@ private List<BidderBid> bidsFromResponse(BidRequest bidRequest, BidResponse bidR
.map(SeatBid::getBid)
.filter(Objects::nonNull)
.flatMap(Collection::stream)
.map(bid -> BidderBid.of(bid, getBidType(bid, bidRequest.getImp()), bidResponse.getCur()))
.map(bid -> makeBidderBid(bidRequest, bidResponse, bid))
.filter(Objects::nonNull)
.collect(Collectors.toList());
}

private BidderBid makeBidderBid(BidRequest bidRequest, BidResponse bidResponse, Bid bid) {
final BidType bidType = getBidType(bid, bidRequest.getImp());
return bidType != null
? BidderBid.of(bid, bidType, bidResponse.getCur())
: null;
}

/**
* A hook for resolving bidder-specific bid type.
* <p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.prebid.server.bidder.pulsepoint;

import com.iab.openrtb.request.App;
import com.iab.openrtb.request.Banner;
import com.iab.openrtb.request.BidRequest;
import com.iab.openrtb.request.Imp;
import com.iab.openrtb.request.Publisher;
Expand All @@ -26,65 +25,33 @@ public PulsepointBidder(String endpointUrl, JacksonMapper mapper) {

@Override
protected Imp modifyImp(Imp imp, ExtImpPulsepoint extImpPulsepoint) throws PreBidException {
// imp validation
if (imp.getBanner() == null) {
throw new PreBidException(String.format("Invalid MediaType. Pulsepoint supports only Banner type. "
+ "Ignoring ImpID=%s", imp.getId()));
}

// imp.ext validation
final Integer publisherId = extImpPulsepoint.getPublisherId();
if (publisherId == null || publisherId == 0) {
throw new PreBidException("Missing PublisherId param cp");
}
final Integer tagId = extImpPulsepoint.getTagId();
if (tagId == null || tagId == 0) {
throw new PreBidException("Missing TagId param ct");
}
final String adSize = extImpPulsepoint.getAdSize();
if (StringUtils.isEmpty(adSize)) {
throw new PreBidException("Missing AdSize param cf");
}
if (adSize.toLowerCase().split("x").length != 2) {
throw new PreBidException(String.format("Invalid AdSize param %s", adSize));
}

// impression modifications and additional validation
final String[] sizes = extImpPulsepoint.getAdSize().toLowerCase().split("x");
final int width;
final int height;
try {
width = Integer.parseInt(sizes[0]);
height = Integer.parseInt(sizes[1]);
} catch (NumberFormatException e) {
throw new PreBidException(String.format("Invalid Width or Height param %s x %s", sizes[0], sizes[1]));
}
final Banner modifiedBanner = imp.getBanner().toBuilder().w(width).h(height).build();

return imp.toBuilder()
.tagid(String.valueOf(extImpPulsepoint.getTagId()))
.banner(modifiedBanner)
.build();
return imp.toBuilder().tagid(Objects.toString(extImpPulsepoint.getTagId())).build();
}

@Override
protected void modifyRequest(BidRequest bidRequest, BidRequest.BidRequestBuilder requestBuilder,
List<ImpWithExt<ExtImpPulsepoint>> impsWithExts) {
final Integer pubId = impsWithExts.stream()
final String pubId = impsWithExts.stream()
.map(ImpWithExt::getImpExt)
.map(ExtImpPulsepoint::getPublisherId)
.filter(Objects::nonNull)
.reduce((first, second) -> second)
.orElse(null);
.filter(this::isValidPublisherId)
.findFirst()
.map(Objects::toString)
.orElse(StringUtils.EMPTY);

final Site site = bidRequest.getSite();
final App app = bidRequest.getApp();
if (site != null) {
requestBuilder.site(modifySite(site, String.valueOf(pubId)));
requestBuilder.site(modifySite(site, pubId));
} else if (app != null) {
requestBuilder.app(modifyApp(app, String.valueOf(pubId)));
requestBuilder.app(modifyApp(app, pubId));
}
}

private boolean isValidPublisherId(Integer publisherId) {
return publisherId != null && publisherId > 0;
}

private static Site modifySite(Site site, String publisherId) {
return site.toBuilder()
.publisher(site.getPublisher() == null
Expand All @@ -101,8 +68,22 @@ private static App modifyApp(App app, String publisherId) {
.build();
}

@Override
protected BidType getBidType(Bid bid, List<Imp> imps) {
return BidType.banner;
final String impId = bid.getImpid();
BidType bidType = null;
for (Imp imp : imps) {
if (imp.getId().equals(impId)) {
if (imp.getBanner() != null) {
bidType = BidType.banner;
} else if (imp.getVideo() != null) {
bidType = BidType.video;
} else if (imp.getAudio() != null) {
bidType = BidType.audio;
} else if (imp.getXNative() != null) {
bidType = BidType.xNative;
}
}
}
return bidType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,4 @@ public class ExtImpPulsepoint {

@JsonProperty("ct")
Integer tagId;

@JsonProperty("cf")
String adSize;
}
6 changes: 6 additions & 0 deletions src/main/resources/bidder-config/pulsepoint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@ adapters:
maintainer-email: ExchangeTeam@pulsepoint.com
app-media-types:
- banner
- video
- audio
- native
site-media-types:
- banner
- video
- audio
- native
supported-vendors:
vendor-id: 81
usersync:
Expand Down
8 changes: 1 addition & 7 deletions src/main/resources/static/bidder-params/pulsepoint.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,10 @@
"ct": {
"type": "integer",
"description": "An ID which identifies the ad slot being sold"
},
"cf": {
"type": "string",
"pattern": "^[0-9]+[xX][0-9]+$",
"description": "The size of the ad slot being sold. This should be a string like 300X250"
}
},
"required": [
"cp",
"ct",
"cf"
"ct"
]
}
Loading

0 comments on commit 7b84d11

Please sign in to comment.