-
Notifications
You must be signed in to change notification settings - Fork 243
New Adapter: Sevio #4528
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
Open
daniel-gheorghian-sevio
wants to merge
2
commits into
prebid:master
Choose a base branch
from
Sevio:sevioAdapter
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
New Adapter: Sevio #4528
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
96 changes: 96 additions & 0 deletions
96
src/main/java/org/prebid/server/bidder/sevio/SevioBidder.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| package org.prebid.server.bidder.sevio; | ||
|
|
||
| import com.iab.openrtb.request.BidRequest; | ||
| import com.iab.openrtb.response.Bid; | ||
| import com.iab.openrtb.response.BidResponse; | ||
| import com.iab.openrtb.response.SeatBid; | ||
| import io.vertx.core.MultiMap; | ||
| import org.apache.commons.collections4.CollectionUtils; | ||
| import org.prebid.server.bidder.Bidder; | ||
| import org.prebid.server.bidder.model.BidderBid; | ||
| import org.prebid.server.bidder.model.BidderCall; | ||
| import org.prebid.server.bidder.model.BidderError; | ||
| import org.prebid.server.bidder.model.HttpRequest; | ||
| import org.prebid.server.bidder.model.Result; | ||
| import org.prebid.server.exception.PreBidException; | ||
| import org.prebid.server.json.DecodeException; | ||
| import org.prebid.server.json.JacksonMapper; | ||
| import org.prebid.server.proto.openrtb.ext.response.BidType; | ||
| import org.prebid.server.util.BidderUtil; | ||
| import org.prebid.server.util.HttpUtil; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Collection; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Objects; | ||
|
|
||
| public class SevioBidder implements Bidder<BidRequest> { | ||
|
|
||
| private final String endpointUrl; | ||
| private final JacksonMapper mapper; | ||
|
|
||
| public SevioBidder(String endpointUrl, JacksonMapper mapper) { | ||
| this.endpointUrl = HttpUtil.validateUrl(Objects.requireNonNull(endpointUrl)); | ||
| this.mapper = Objects.requireNonNull(mapper); | ||
| } | ||
|
|
||
| @Override | ||
| public Result<List<HttpRequest<BidRequest>>> makeHttpRequests(BidRequest bidRequest) { | ||
| final MultiMap headers = HttpUtil.headers().add(HttpUtil.X_OPENRTB_VERSION_HEADER, "2.6"); | ||
| return Result.withValue(BidderUtil.defaultRequest(bidRequest, headers, endpointUrl, mapper)); | ||
| } | ||
|
|
||
| @Override | ||
| public final Result<List<BidderBid>> makeBids(BidderCall<BidRequest> httpCall, BidRequest bidRequest) { | ||
| try { | ||
| final BidResponse bidResponse = mapper.decodeValue(httpCall.getResponse().getBody(), BidResponse.class); | ||
| final List<BidderError> errors = new ArrayList<>(); | ||
| return Result.of(extractBids(bidResponse, errors), errors); | ||
| } catch (DecodeException e) { | ||
| return Result.withError(BidderError.badServerResponse(e.getMessage())); | ||
| } | ||
| } | ||
|
|
||
| private static List<BidderBid> extractBids(BidResponse bidResponse, List<BidderError> errors) { | ||
| if (bidResponse == null || CollectionUtils.isEmpty(bidResponse.getSeatbid())) { | ||
| return Collections.emptyList(); | ||
| } | ||
| return bidsFromResponse(bidResponse, errors); | ||
| } | ||
|
|
||
| private static List<BidderBid> bidsFromResponse(BidResponse bidResponse, List<BidderError> errors) { | ||
| return bidResponse.getSeatbid().stream() | ||
| .filter(Objects::nonNull) | ||
| .map(SeatBid::getBid) | ||
| .filter(Objects::nonNull) | ||
| .flatMap(Collection::stream) | ||
| .filter(Objects::nonNull) | ||
| .map(bid -> makeBid(bid, bidResponse.getCur(), errors)) | ||
| .filter(Objects::nonNull) | ||
| .toList(); | ||
| } | ||
|
|
||
| private static BidderBid makeBid(Bid bid, String currency, List<BidderError> errors) { | ||
| try { | ||
| return BidderBid.of(bid, getBidType(bid), currency); | ||
| } catch (PreBidException e) { | ||
| errors.add(BidderError.badServerResponse(e.getMessage())); | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| private static BidType getBidType(Bid bid) { | ||
| final Integer mtype = bid.getMtype(); | ||
| if (mtype == null) { | ||
| throw new PreBidException("Missing MType for bid: " + bid.getId()); | ||
| } | ||
|
|
||
| return switch (mtype) { | ||
| case 1 -> BidType.banner; | ||
| case 4 -> BidType.xNative; | ||
| default -> throw new PreBidException( | ||
| "failed to parse bid mtype (%d) for impression id \"%s\"".formatted(mtype, bid.getImpid())); | ||
| }; | ||
| } | ||
| } | ||
41 changes: 41 additions & 0 deletions
41
src/main/java/org/prebid/server/spring/config/bidder/SevioConfiguration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package org.prebid.server.spring.config.bidder; | ||
|
|
||
| import org.prebid.server.bidder.BidderDeps; | ||
| import org.prebid.server.bidder.sevio.SevioBidder; | ||
| import org.prebid.server.json.JacksonMapper; | ||
| import org.prebid.server.spring.config.bidder.model.BidderConfigurationProperties; | ||
| import org.prebid.server.spring.config.bidder.util.BidderDepsAssembler; | ||
| import org.prebid.server.spring.config.bidder.util.UsersyncerCreator; | ||
| import org.prebid.server.spring.env.YamlPropertySourceFactory; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.boot.context.properties.ConfigurationProperties; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.context.annotation.PropertySource; | ||
|
|
||
| import jakarta.validation.constraints.NotBlank; | ||
|
|
||
| @Configuration | ||
| @PropertySource(value = "classpath:/bidder-config/sevio.yaml", factory = YamlPropertySourceFactory.class) | ||
| public class SevioConfiguration { | ||
|
|
||
| private static final String BIDDER_NAME = "sevio"; | ||
|
|
||
| @Bean("sevioConfigurationProperties") | ||
| @ConfigurationProperties("adapters.sevio") | ||
| BidderConfigurationProperties configurationProperties() { | ||
| return new BidderConfigurationProperties(); | ||
| } | ||
|
|
||
| @Bean | ||
| BidderDeps sevioBidderDeps(BidderConfigurationProperties sevioConfigurationProperties, | ||
| @NotBlank @Value("${external-url}") String externalUrl, | ||
| JacksonMapper mapper) { | ||
|
|
||
| return BidderDepsAssembler.forBidder(BIDDER_NAME) | ||
| .withConfig(sevioConfigurationProperties) | ||
| .usersyncerCreator(UsersyncerCreator.create(externalUrl)) | ||
| .bidderCreator(config -> new SevioBidder(config.getEndpoint(), mapper)) | ||
| .assemble(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| adapters: | ||
| sevio: | ||
| endpoint: https://req.adx.ws/rtb | ||
| meta-info: | ||
| maintainer-email: technical@sevio.com | ||
| app-media-types: | ||
| - banner | ||
| - native | ||
| site-media-types: | ||
| - banner | ||
| - native | ||
| supported-vendors: | ||
| vendor-id: 1393 |
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Descriptions differs from GO version |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| { | ||
| "$schema": "http://json-schema.org/draft-04/schema#", | ||
| "title": "Sevio Adapter Params", | ||
| "description": "A schema which validates params accepted by the Sevio adapter", | ||
| "type": "object", | ||
| "properties": { | ||
| "placementId": { | ||
| "type": "string", | ||
| "minLength": 1, | ||
| "description": "Placement Id or Zone Id" | ||
| } | ||
| }, | ||
| "required": [ | ||
| "placementId" | ||
| ] | ||
| } |
219 changes: 219 additions & 0 deletions
219
src/test/java/org/prebid/server/bidder/sevio/SevioBidderTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,219 @@ | ||
| package org.prebid.server.bidder.sevio; | ||
|
|
||
| import com.fasterxml.jackson.core.JsonProcessingException; | ||
| import com.iab.openrtb.request.BidRequest; | ||
| 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 org.junit.jupiter.api.Test; | ||
| import org.prebid.server.VertxTest; | ||
| import org.prebid.server.bidder.model.BidderBid; | ||
| import org.prebid.server.bidder.model.BidderCall; | ||
| import org.prebid.server.bidder.model.BidderError; | ||
| import org.prebid.server.bidder.model.HttpRequest; | ||
| import org.prebid.server.bidder.model.HttpResponse; | ||
| import org.prebid.server.bidder.model.Result; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.util.function.UnaryOperator; | ||
|
|
||
| import static java.util.Collections.singletonList; | ||
| import static java.util.function.UnaryOperator.identity; | ||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; | ||
| import static org.prebid.server.proto.openrtb.ext.response.BidType.banner; | ||
| import static org.prebid.server.proto.openrtb.ext.response.BidType.xNative; | ||
| import static org.prebid.server.util.HttpUtil.ACCEPT_HEADER; | ||
| import static org.prebid.server.util.HttpUtil.APPLICATION_JSON_CONTENT_TYPE; | ||
| import static org.prebid.server.util.HttpUtil.CONTENT_TYPE_HEADER; | ||
| import static org.prebid.server.util.HttpUtil.X_OPENRTB_VERSION_HEADER; | ||
| import static org.springframework.util.MimeTypeUtils.APPLICATION_JSON_VALUE; | ||
|
|
||
| public class SevioBidderTest extends VertxTest { | ||
|
|
||
| private static final String ENDPOINT_URL = "https://req.adx.ws/rtb"; | ||
|
|
||
| private final SevioBidder target = new SevioBidder(ENDPOINT_URL, jacksonMapper); | ||
|
|
||
| @Test | ||
| public void creationShouldFailOnInvalidEndpointUrl() { | ||
| assertThatIllegalArgumentException().isThrownBy(() -> new SevioBidder("invalid_url", jacksonMapper)); | ||
| } | ||
|
|
||
| @Test | ||
| public void makeHttpRequestsShouldReturnExpectedRequestWithAllImps() { | ||
| // given | ||
| final BidRequest bidRequest = givenBidRequest( | ||
| imp -> imp.id("impId1"), | ||
| imp -> imp.id("impId2")); | ||
|
|
||
| // when | ||
| final Result<List<HttpRequest<BidRequest>>> result = target.makeHttpRequests(bidRequest); | ||
|
|
||
| // then | ||
| assertThat(result.getErrors()).isEmpty(); | ||
| assertThat(result.getValue()).hasSize(1).first() | ||
| .satisfies(request -> assertThat(request.getBody()) | ||
| .isEqualTo(jacksonMapper.encodeToBytes(bidRequest))) | ||
| .satisfies(request -> assertThat(request.getPayload()) | ||
| .isEqualTo(bidRequest)) | ||
| .satisfies(request -> assertThat(request.getImpIds()) | ||
| .containsExactlyInAnyOrder("impId1", "impId2")); | ||
| } | ||
|
|
||
| @Test | ||
| public void makeHttpRequestsShouldReturnExpectedHeaders() { | ||
| // given | ||
| final BidRequest bidRequest = givenBidRequest( | ||
| imp -> imp.id("impId1"), | ||
| imp -> imp.id("impId2")); | ||
|
|
||
| // when | ||
| final Result<List<HttpRequest<BidRequest>>> result = target.makeHttpRequests(bidRequest); | ||
|
|
||
| // then | ||
| assertThat(result.getErrors()).isEmpty(); | ||
| assertThat(result.getValue()).hasSize(1).first() | ||
| .extracting(HttpRequest::getHeaders) | ||
| .satisfies(headers -> assertThat(headers.get(CONTENT_TYPE_HEADER)) | ||
| .isEqualTo(APPLICATION_JSON_CONTENT_TYPE)) | ||
| .satisfies(headers -> assertThat(headers.get(ACCEPT_HEADER)) | ||
| .isEqualTo(APPLICATION_JSON_VALUE)) | ||
| .satisfies(headers -> assertThat(headers.get(X_OPENRTB_VERSION_HEADER)) | ||
| .isEqualTo("2.6")); | ||
| } | ||
|
|
||
| @Test | ||
| public void makeHttpRequestsShouldUseCorrectUri() { | ||
| // given | ||
| final BidRequest bidRequest = givenBidRequest(identity()); | ||
|
|
||
| // when | ||
| final Result<List<HttpRequest<BidRequest>>> result = target.makeHttpRequests(bidRequest); | ||
|
|
||
| // then | ||
| assertThat(result.getErrors()).isEmpty(); | ||
| assertThat(result.getValue()).hasSize(1).first() | ||
| .extracting(HttpRequest::getUri) | ||
| .isEqualTo(ENDPOINT_URL); | ||
| } | ||
|
|
||
| @Test | ||
| public void makeBidsShouldReturnErrorIfResponseBodyCouldNotBeParsed() { | ||
| // given | ||
| final BidderCall<BidRequest> httpCall = givenHttpCall("invalid"); | ||
|
|
||
| // when | ||
| final Result<List<BidderBid>> result = target.makeBids(httpCall, null); | ||
|
|
||
| // then | ||
| assertThat(result.getValue()).isEmpty(); | ||
| assertThat(result.getErrors()).hasSize(1) | ||
| .allSatisfy(error -> { | ||
| assertThat(error.getType()).isEqualTo(BidderError.Type.bad_server_response); | ||
| assertThat(error.getMessage()).startsWith("Failed to decode: Unrecognized token"); | ||
| }); | ||
| } | ||
|
|
||
| @Test | ||
| public void makeBidsShouldReturnEmptyListIfBidResponseSeatBidIsNull() throws JsonProcessingException { | ||
| // given | ||
| final BidderCall<BidRequest> httpCall = givenHttpCall(mapper.writeValueAsString(BidResponse.builder().build())); | ||
|
|
||
| // when | ||
| final Result<List<BidderBid>> result = target.makeBids(httpCall, null); | ||
|
|
||
| // then | ||
| assertThat(result.getErrors()).isEmpty(); | ||
| assertThat(result.getValue()).isEmpty(); | ||
| } | ||
|
|
||
| @Test | ||
| public void makeBidsShouldReturnBannerBidWhenMtypeIsBanner() throws JsonProcessingException { | ||
| // given | ||
| final Bid bannerBid = Bid.builder().impid("1").mtype(1).build(); | ||
|
|
||
| final BidderCall<BidRequest> httpCall = givenHttpCall(givenBidResponse(bannerBid)); | ||
|
|
||
| // when | ||
| final Result<List<BidderBid>> result = target.makeBids(httpCall, null); | ||
|
|
||
| // then | ||
| assertThat(result.getErrors()).isEmpty(); | ||
| assertThat(result.getValue()).containsOnly(BidderBid.of(bannerBid, banner, "USD")); | ||
| } | ||
|
|
||
| @Test | ||
| public void makeBidsShouldReturnNativeBidWhenMtypeIsNative() throws JsonProcessingException { | ||
| // given | ||
| final Bid nativeBid = Bid.builder().impid("4").mtype(4).build(); | ||
|
|
||
| final BidderCall<BidRequest> httpCall = givenHttpCall(givenBidResponse(nativeBid)); | ||
|
|
||
| // when | ||
| final Result<List<BidderBid>> result = target.makeBids(httpCall, null); | ||
|
|
||
| // then | ||
| assertThat(result.getErrors()).isEmpty(); | ||
| assertThat(result.getValue()).containsOnly(BidderBid.of(nativeBid, xNative, "USD")); | ||
| } | ||
|
|
||
| @Test | ||
| public void makeBidsShouldReturnErrorWhenMtypeIsNotSupported() throws JsonProcessingException { | ||
| // given | ||
| final Bid bannerBid = Bid.builder().impid("id").mtype(1).build(); | ||
| final Bid audioBid = Bid.builder().impid("id").mtype(3).build(); | ||
|
|
||
| final BidderCall<BidRequest> httpCall = givenHttpCall(givenBidResponse(bannerBid, audioBid)); | ||
|
|
||
| // when | ||
| final Result<List<BidderBid>> result = target.makeBids(httpCall, null); | ||
|
|
||
| // then | ||
| assertThat(result.getErrors()).containsExactly( | ||
| BidderError.badServerResponse("failed to parse bid mtype (3) for impression id \"id\"")); | ||
| assertThat(result.getValue()).containsOnly(BidderBid.of(bannerBid, banner, "USD")); | ||
| } | ||
|
|
||
| @Test | ||
| public void makeBidsShouldReturnErrorWhenMtypeIsMissing() throws JsonProcessingException { | ||
| // given | ||
| final Bid bid = Bid.builder().id("bidId").impid("1").build(); | ||
|
|
||
| final BidderCall<BidRequest> httpCall = givenHttpCall(givenBidResponse(bid)); | ||
|
|
||
| // when | ||
| final Result<List<BidderBid>> result = target.makeBids(httpCall, null); | ||
|
|
||
| // then | ||
| assertThat(result.getValue()).isEmpty(); | ||
| assertThat(result.getErrors()).containsExactly( | ||
| BidderError.badServerResponse("Missing MType for bid: bidId")); | ||
| } | ||
|
|
||
| private static BidRequest givenBidRequest(UnaryOperator<Imp.ImpBuilder>... impCustomizers) { | ||
| return BidRequest.builder() | ||
| .imp(Arrays.stream(impCustomizers).map(SevioBidderTest::givenImp).toList()) | ||
| .build(); | ||
| } | ||
|
|
||
| private static Imp givenImp(UnaryOperator<Imp.ImpBuilder> impCustomizer) { | ||
| return impCustomizer.apply(Imp.builder().id("impId")).build(); | ||
| } | ||
|
|
||
| private static String givenBidResponse(Bid... bids) throws JsonProcessingException { | ||
| return mapper.writeValueAsString(BidResponse.builder() | ||
| .cur("USD") | ||
| .seatbid(singletonList(SeatBid.builder().bid(List.of(bids)).build())) | ||
| .build()); | ||
| } | ||
|
|
||
| private static BidderCall<BidRequest> givenHttpCall(String body) { | ||
| return BidderCall.succeededHttp( | ||
| HttpRequest.<BidRequest>builder().build(), | ||
| HttpResponse.of(200, null, body), | ||
| null); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add
.filter(Objects::nonNull)before.map(bid -> ...)