Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Silvermob: Use mtype and add global host #3602 #3664

Merged
merged 3 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.iab.openrtb.request.BidRequest;
import com.iab.openrtb.request.Device;
import com.iab.openrtb.request.Imp;
import com.iab.openrtb.response.Bid;
import com.iab.openrtb.response.BidResponse;
import com.iab.openrtb.response.SeatBid;
import io.vertx.core.MultiMap;
Expand Down Expand Up @@ -98,7 +99,7 @@ private ExtImpSilvermob parseImpExt(Imp imp) {
}

private static Boolean isInvalidHost(String host) {
return !StringUtils.equalsAny(host, "eu", "us", "apac");
return !StringUtils.equalsAny(host, "eu", "us", "apac", "global");
}

private String resolveEndpoint(ExtImpSilvermob extImp) {
Expand Down Expand Up @@ -142,30 +143,31 @@ private List<BidderBid> extractBids(BidderCall<BidRequest> httpCall) {
if (CollectionUtils.isEmpty(bidResponse.getSeatbid())) {
throw new PreBidException("Empty SeatBid array");
}
return bidsFromResponse(bidResponse, httpCall.getRequest().getPayload());
return bidsFromResponse(bidResponse);
}

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

private static BidType getBidType(String impId, List<Imp> imps) {
for (Imp imp : imps) {
if (imp.getId().equals(impId)) {
if (imp.getVideo() != null) {
return BidType.video;
}
if (imp.getXNative() != null) {
return BidType.xNative;
}
}
private static BidType getBidType(Bid bid) {
final Integer markupType = bid.getMtype();
if (markupType == null) {
throw new PreBidException("Missing MType for bid: " + bid.getId());
}
return BidType.banner;

return switch (markupType) {
case 1 -> BidType.banner;
case 2 -> BidType.video;
case 4 -> BidType.xNative;
default -> throw new PreBidException("Unable to fetch mediaType in multi-format: %s"
.formatted(bid.getImpid()));
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -192,40 +192,40 @@ public void makeBidsShouldReturnErrorIfBidResponseSeatBidIsNullOrEmpty() throws
}

@Test
public void makeBidsShouldReturnBannerBidIfBannerIsPresentInRequestImp() throws JsonProcessingException {
public void makeBidsShouldReturnBannerBidIfMTypeIsBanner() throws JsonProcessingException {
// given
final BidderCall<BidRequest> httpCall = givenHttpCall(
BidRequest.builder()
.imp(singletonList(Imp.builder().id("123").banner(Banner.builder().build()).build()))
.build(),
mapper.writeValueAsString(
givenBidResponse(bidBuilder -> bidBuilder.impid("123"))));
givenBidResponse(bidBuilder -> bidBuilder.impid("123").mtype(1))));

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

// then
assertThat(result.getErrors()).isEmpty();
assertThat(result.getValue())
.containsOnly(BidderBid.of(Bid.builder().impid("123").build(), banner, "USD"));
.containsOnly(BidderBid.of(Bid.builder().impid("123").mtype(1).build(), banner, "USD"));
}

@Test
public void makeBidsShouldReturnVideoBidIfVideoIsPresentInRequestImp() throws JsonProcessingException {
public void makeBidsShouldReturnVideoBidIfMTypeIsVideo() throws JsonProcessingException {
// given
final BidderCall<BidRequest> httpCall = givenHttpCall(BidRequest.builder()
.imp(singletonList(Imp.builder().id("123").video(Video.builder().build()).build()))
.build(),
mapper.writeValueAsString(
givenBidResponse(bidBuilder -> bidBuilder.impid("123"))));
givenBidResponse(bidBuilder -> bidBuilder.impid("123").mtype(2))));

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

// then
assertThat(result.getErrors()).isEmpty();
assertThat(result.getValue())
.containsOnly(BidderBid.of(Bid.builder().impid("123").build(), video, "USD"));
.containsOnly(BidderBid.of(Bid.builder().impid("123").mtype(2).build(), video, "USD"));
}

@Test
Expand Down Expand Up @@ -254,22 +254,43 @@ public void makeHttpRequestsShouldSetAdditionalHeadersIfDeviceFieldsAreNotEmpty(
}

@Test
public void makeBidsShouldReturnNativeBidIfNativeIsPresentInRequestImp() throws JsonProcessingException {
public void makeBidsShouldReturnNativeBidIfMTypeIsNative() throws JsonProcessingException {
// given
final BidderCall<BidRequest> httpCall = givenHttpCall(
BidRequest.builder()
.imp(singletonList(Imp.builder().id("123").xNative(Native.builder().build()).build()))
.build(),
mapper.writeValueAsString(
givenBidResponse(bidBuilder -> bidBuilder.impid("123"))));
givenBidResponse(bidBuilder -> bidBuilder.impid("123").mtype(4))));

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

// then
assertThat(result.getErrors()).isEmpty();
assertThat(result.getValue())
.containsOnly(BidderBid.of(Bid.builder().impid("123").build(), xNative, "USD"));
.containsOnly(BidderBid.of(Bid.builder().impid("123").mtype(4).build(), xNative, "USD"));
}

@Test
public void makeBidsShouldThrowErrorWhenMediaTypeIsMissing() throws JsonProcessingException {
// given
final BidderCall<BidRequest> httpCall = givenHttpCall(BidRequest.builder()
.imp(singletonList(Imp.builder().id("123").build()))
.build(),
mapper.writeValueAsString(
givenBidResponse(bidBuilder -> bidBuilder.impid("123"))));

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

// then
assertThat(result.getValue()).isEmpty();
assertThat(result.getErrors()).hasSize(1)
.allSatisfy(error -> {
assertThat(error.getMessage()).startsWith("Missing MType for bid: null");
assertThat(error.getType()).isEqualTo(BidderError.Type.bad_server_response);
});
}

private static BidRequest givenBidRequest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"silvermob": {
"zoneid": "testZoneId",
"host": "eu"
}
},
"mtype": 1
},
"tagid": "tag_id"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
"prebid": {
"type": "banner"
},
"origbidcpm": 0.01
}
"origbidcpm": 0.01,
"origbidcur": "USD"
},
"mtype": 1
}
],
"seat": "silvermob",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"bidder": {
"zoneid": "testZoneId",
"host": "eu"
}
},
"mtype": 1
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
"price": 0.01,
"id": "bid_id",
"impid": "imp_id",
"cid": "cid"
"cid": "cid",
"mtype": 1
}
],
"type": "banner"
"seat": "silvermob"
}
]
],
"cur": "USD"
}
Loading