Skip to content

Commit

Permalink
Taboola: App Support (prebid#3407)
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoxaAntoxic authored and sergseven committed Dec 23, 2024
1 parent db72a00 commit 95c15a5
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 23 deletions.
31 changes: 24 additions & 7 deletions src/main/java/org/prebid/server/bidder/taboola/TaboolaBidder.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.iab.openrtb.request.App;
import com.iab.openrtb.request.Banner;
import com.iab.openrtb.request.BidRequest;
import com.iab.openrtb.request.Imp;
Expand Down Expand Up @@ -151,13 +152,24 @@ private BidRequest createRequest(BidRequest request, List<Imp> imps, ExtImpTaboo
final List<String> impExtBCat = impExt.getBCat();
final String impExtPageType = impExt.getPageType();

final Site site = Optional.ofNullable(request.getSite())
.map(Site::toBuilder)
.orElseGet(Site::builder)
final Publisher publisher = Publisher.builder().id(impExtPublisherId).build();

final Site site = request.getSite();
final Site modifiedSite = site == null
? null
: site.toBuilder()
.id(impExtPublisherId)
.name(impExtPublisherId)
.domain(resolveDomain(impExt.getPublisherDomain(), request))
.publisher(Publisher.builder().id(impExtPublisherId).build())
.publisher(publisher)
.build();

final App app = request.getApp();
final App modifiedApp = app == null
? null
: app.toBuilder()
.id(impExtPublisherId)
.publisher(publisher)
.build();

final ExtRequest extRequest = StringUtils.isNotEmpty(impExtPageType)
Expand All @@ -166,7 +178,8 @@ private BidRequest createRequest(BidRequest request, List<Imp> imps, ExtImpTaboo

return request.toBuilder()
.imp(imps)
.site(site)
.site(modifiedSite)
.app(modifiedApp)
.badv(CollectionUtils.isNotEmpty(impExtBAdv) ? impExtBAdv : request.getBadv())
.bcat(CollectionUtils.isNotEmpty(impExtBCat) ? impExtBCat : request.getBcat())
.ext(extRequest)
Expand All @@ -189,11 +202,11 @@ private ExtRequest createExtRequest(String pageType) {

private HttpRequest<BidRequest> createHttpRequest(MediaType type, BidRequest outgoingRequest) {
return BidderUtil.defaultRequest(outgoingRequest,
buildEndpointUrl(outgoingRequest.getSite().getId(), type),
buildEndpointUrl(outgoingRequest, type),
mapper);
}

private String buildEndpointUrl(String publisherId, MediaType mediaType) {
private String buildEndpointUrl(BidRequest bidRequest, MediaType mediaType) {
final String type = switch (mediaType) {
case BANNER -> DISPLAY_ENDPOINT_PREFIX;
case NATIVE -> NATIVE_ENDPOINT_PREFIX;
Expand All @@ -202,6 +215,10 @@ private String buildEndpointUrl(String publisherId, MediaType mediaType) {
default -> throw new AssertionError();
};

final String publisherId = Optional.ofNullable(bidRequest.getSite()).map(Site::getId)
.or(() -> Optional.ofNullable(bidRequest.getApp()).map(App::getId))
.orElse(StringUtils.EMPTY);

return endpointTemplate
.replace("{{GvlID}}", gvlId)
.replace("{{MediaType}}", type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.TextNode;
import com.iab.openrtb.request.App;
import com.iab.openrtb.request.Audio;
import com.iab.openrtb.request.Banner;
import com.iab.openrtb.request.BidRequest;
Expand Down Expand Up @@ -337,6 +338,7 @@ public void makeHttpRequestsShouldModifyExtIfImpExtPageTypeIsNotEmpty() {
public void makeHttpRequestShouldContainProperUriWhenTypeIsBanner() {
// given
final BidRequest bidRequest = givenBidRequest(
request -> request.site(Site.builder().build()),
givenBannerImp(identity(), ext -> ext.publisherId("publisherId")));

// when
Expand All @@ -353,6 +355,7 @@ public void makeHttpRequestShouldContainProperUriWhenTypeIsBanner() {
public void makeHttpRequestShouldContainProperUriWithEncodedPublisherId() {
// given
final BidRequest bidRequest = givenBidRequest(
request -> request.app(App.builder().build()),
givenBannerImp(identity(), extImp -> extImp.publisherId("not/encoded")));

// when
Expand All @@ -369,6 +372,7 @@ public void makeHttpRequestShouldContainProperUriWithEncodedPublisherId() {
public void makeHttpRequestShouldContainProperUriWhenTypeIsNative() {
// given
final BidRequest bidRequest = givenBidRequest(
request -> request.app(App.builder().build()),
givenImp(imp -> imp.xNative(Native.builder().build()), ext -> ext.publisherId("publisherId")));

// when
Expand Down Expand Up @@ -411,30 +415,38 @@ public void makeHttpRequestShouldModifySiteDependsOnExtPublisherId() {
}

@Test
public void makeHttpRequestShouldModifySiteDomainIfExtPublisherDomainIsNotEmpty() {
public void makeHttpRequestShouldModifyAppDependsOnExtPublisherId() {
// given
final App givenApp = App.builder()
.id("id")
.publisher(Publisher.builder().id("id").build())
.build();

final BidRequest bidRequest = givenBidRequest(
request -> request.site(Site.builder().domain("domain").build()),
givenBannerImp(identity(), ext -> ext.publisherDomain("extDomain")));
request -> request.app(givenApp),
givenBannerImp(identity(), ext -> ext.publisherId("extPublisherId")));

// when
final Result<List<HttpRequest<BidRequest>>> result = target.makeHttpRequests(bidRequest);

// then
final App expectedApp = givenApp.toBuilder()
.publisher(Publisher.builder().id("extPublisherId").build())
.id("extPublisherId")
.build();
assertThat(result.getErrors()).isEmpty();
assertThat(result.getValue())
.extracting(HttpRequest::getPayload)
.extracting(BidRequest::getSite)
.extracting(Site::getDomain)
.containsExactly("extDomain");
.extracting(BidRequest::getApp)
.containsOnly(expectedApp);
}

@Test
public void makeHttpRequestShouldNotModifySiteDomainIfExtPublisherDomainIsEmpty() {
public void makeHttpRequestShouldModifySiteDomainIfExtPublisherDomainIsNotEmpty() {
// given
final BidRequest bidRequest = givenBidRequest(
request -> request.site(Site.builder().domain("domain").build()),
givenBannerImp(identity(), ext -> ext.publisherDomain("")));
givenBannerImp(identity(), ext -> ext.publisherDomain("extDomain")));

// when
final Result<List<HttpRequest<BidRequest>>> result = target.makeHttpRequests(bidRequest);
Expand All @@ -445,15 +457,15 @@ public void makeHttpRequestShouldNotModifySiteDomainIfExtPublisherDomainIsEmpty(
.extracting(HttpRequest::getPayload)
.extracting(BidRequest::getSite)
.extracting(Site::getDomain)
.containsExactly("domain");
.containsExactly("extDomain");
}

@Test
public void makeHttpRequestShouldAddEmptyDomainIfNoOtherSources() {
public void makeHttpRequestShouldNotModifySiteDomainIfExtPublisherDomainIsEmpty() {
// given
final BidRequest bidRequest = givenBidRequest(
request -> request.site(Site.builder().build()),
givenBannerImp(identity(), identity()));
request -> request.site(Site.builder().domain("domain").build()),
givenBannerImp(identity(), ext -> ext.publisherDomain("")));

// when
final Result<List<HttpRequest<BidRequest>>> result = target.makeHttpRequests(bidRequest);
Expand All @@ -464,13 +476,15 @@ public void makeHttpRequestShouldAddEmptyDomainIfNoOtherSources() {
.extracting(HttpRequest::getPayload)
.extracting(BidRequest::getSite)
.extracting(Site::getDomain)
.containsExactly("");
.containsExactly("domain");
}

@Test
public void makeHttpRequestShouldCreateSiteIfNotPresent() {
public void makeHttpRequestShouldAddEmptyDomainIfNoOtherSources() {
// given
final BidRequest bidRequest = givenBidRequest(givenBannerImp(identity(), identity()));
final BidRequest bidRequest = givenBidRequest(
request -> request.site(Site.builder().build()),
givenBannerImp(identity(), identity()));

// when
final Result<List<HttpRequest<BidRequest>>> result = target.makeHttpRequests(bidRequest);
Expand All @@ -480,13 +494,15 @@ public void makeHttpRequestShouldCreateSiteIfNotPresent() {
assertThat(result.getValue())
.extracting(HttpRequest::getPayload)
.extracting(BidRequest::getSite)
.doesNotContainNull();
.extracting(Site::getDomain)
.containsExactly("");
}

@Test
public void makeHttpRequestShouldUseDataFromLastImpExtForRequest() {
// given
final BidRequest bidRequest = givenBidRequest(
request -> request.site(Site.builder().build()),
givenBannerImp(identity(), ext -> ext.publisherId("1")),
givenBannerImp(identity(), ext -> ext.publisherId("2")));

Expand Down

0 comments on commit 95c15a5

Please sign in to comment.