Skip to content

Commit

Permalink
Add App support for Smaato (#1221)
Browse files Browse the repository at this point in the history
  • Loading branch information
RodionOrets authored Apr 21, 2021
1 parent 32407f0 commit 9c45b2d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
10 changes: 9 additions & 1 deletion src/main/java/org/prebid/server/bidder/smaato/SmaatoBidder.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.Format;
Expand Down Expand Up @@ -60,7 +61,7 @@ public class SmaatoBidder implements Bidder<BidRequest> {
new TypeReference<ExtPrebid<?, ExtImpSmaato>>() {
};

private static final String CLIENT_VERSION = "prebid_server_0.1";
private static final String CLIENT_VERSION = "prebid_server_0.2";
private static final String SMT_ADTYPE_HEADER = "X-SMT-ADTYPE";
private static final String SMT_AD_TYPE_IMG = "Img";
private static final String SMT_ADTYPE_RICHMEDIA = "Richmedia";
Expand Down Expand Up @@ -96,6 +97,7 @@ public Result<List<HttpRequest<BidRequest>>> makeHttpRequests(BidRequest request
outgoingRequest = request.toBuilder()
.imp(imps)
.site(modifySite(request.getSite(), firstPublisherId))
.app(modifyApp(request.getApp(), firstPublisherId))
.user(modifyUser(request.getUser()))
.ext(mapper.fillExtension(ExtRequest.empty(), SmaatoBidRequestExt.of(CLIENT_VERSION)))
.build();
Expand Down Expand Up @@ -166,6 +168,12 @@ private Site modifySite(Site site, String firstPublisherId) {
return siteBuilder.build();
}

private App modifyApp(App app, String publishedId) {
return app != null
? app.toBuilder().publisher(Publisher.builder().id(publishedId).build()).build()
: null;
}

private User modifyUser(User user) {
if (user == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.prebid.server.bidder.smaato;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.iab.openrtb.request.App;
import com.iab.openrtb.request.Banner;
import com.iab.openrtb.request.BidRequest;
import com.iab.openrtb.request.Format;
Expand Down Expand Up @@ -184,6 +185,25 @@ public void makeHttpRequestsShouldModifyRequestSite() {
.containsOnly("keywords");
}

@Test
public void makeHttpRequestsShouldModifyRequestAppPublisherId() {
// given
final BidRequest bidRequest = givenBidRequest(bidRequestBuilder ->
bidRequestBuilder.app(App.builder().build()), identity());

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

// then
assertThat(result.getErrors()).isEmpty();
assertThat(result.getValue()).hasSize(1)
.extracting(HttpRequest::getPayload)
.extracting(BidRequest::getApp)
.extracting(App::getPublisher)
.extracting(Publisher::getId)
.containsOnly("publisherId");
}

@Test
public void makeHttpRequestsShouldModifyRequestUser() {
// given
Expand Down Expand Up @@ -476,8 +496,12 @@ private static BidRequest givenBidRequest(Function<Imp.ImpBuilder, Imp.ImpBuilde
private static Imp givenImp(Function<Imp.ImpBuilder, Imp.ImpBuilder> impCustomizer) {
return impCustomizer.apply(Imp.builder()
.id("123")
.banner(Banner.builder().id("banner_id").build()).ext(mapper.valueToTree(ExtPrebid.of(null,
ExtImpSmaato.of("publisherId", "adspaceId")))))
.banner(Banner.builder()
.id("banner_id")
.w(300)
.h(500)
.build())
.ext(mapper.valueToTree(ExtPrebid.of(null, ExtImpSmaato.of("publisherId", "adspaceId")))))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@
}
},
"ext": {
"client": "prebid_server_0.1"
"client": "prebid_server_0.2"
}
}

0 comments on commit 9c45b2d

Please sign in to comment.