-
Notifications
You must be signed in to change notification settings - Fork 223
Teal: new adapter #4350
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
ollyburns
wants to merge
6
commits into
prebid:master
Choose a base branch
from
ollyburns:add-teal-bidder
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
Teal: new adapter #4350
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ecba19c
teal bidder - initial commit
ollyburns 3c32333
fix integration test
ollyburns 03fd561
review feedback changes
ollyburns bb726c3
three missed review improvements
ollyburns 9a2dc79
tests: review feedback changes
ollyburns d999a2c
tests: additional feedback changes
ollyburns 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
200 changes: 200 additions & 0 deletions
200
src/main/java/org/prebid/server/bidder/teal/TealBidder.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,200 @@ | ||
| package org.prebid.server.bidder.teal; | ||
|
|
||
| import com.fasterxml.jackson.core.type.TypeReference; | ||
| import com.fasterxml.jackson.databind.JsonNode; | ||
| import com.fasterxml.jackson.databind.node.ObjectNode; | ||
| import com.iab.openrtb.request.App; | ||
| import com.iab.openrtb.request.BidRequest; | ||
| import com.iab.openrtb.request.Imp; | ||
| import com.iab.openrtb.request.Publisher; | ||
| import com.iab.openrtb.request.Site; | ||
| import com.iab.openrtb.response.BidResponse; | ||
| import com.iab.openrtb.response.SeatBid; | ||
| import org.apache.commons.collections4.CollectionUtils; | ||
| import org.apache.commons.lang3.ObjectUtils; | ||
| import org.apache.commons.lang3.StringUtils; | ||
| 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.ExtPrebid; | ||
| import org.prebid.server.proto.openrtb.ext.request.ExtRequest; | ||
| import org.prebid.server.proto.openrtb.ext.request.teal.ExtImpTeal; | ||
| 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; | ||
| import java.util.Optional; | ||
|
|
||
| public class TealBidder implements Bidder<BidRequest> { | ||
|
|
||
| private static final TypeReference<ExtPrebid<?, ExtImpTeal>> TYPE_REFERENCE = new TypeReference<>() { | ||
| }; | ||
|
|
||
| private final String endpointUrl; | ||
| private final JacksonMapper mapper; | ||
|
|
||
| public TealBidder(String endpointUrl, JacksonMapper mapper) { | ||
| this.endpointUrl = HttpUtil.validateUrl(Objects.requireNonNull(endpointUrl)); | ||
| this.mapper = Objects.requireNonNull(mapper); | ||
| } | ||
CTMBNara marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @Override | ||
| public Result<List<HttpRequest<BidRequest>>> makeHttpRequests(BidRequest request) { | ||
| final List<Imp> modifiedImps = new ArrayList<>(); | ||
| final List<BidderError> errors = new ArrayList<>(); | ||
| String account = null; | ||
|
|
||
| for (Imp imp : request.getImp()) { | ||
| final ExtImpTeal extImpTeal; | ||
| try { | ||
| extImpTeal = parseImpExt(imp); | ||
| validateImpExt(extImpTeal); | ||
| } catch (PreBidException e) { | ||
| errors.add(BidderError.badInput(e.getMessage())); | ||
| continue; | ||
| } | ||
|
|
||
| account = account == null ? extImpTeal.getAccount() : account; | ||
| modifiedImps.add(modifyImp(imp, extImpTeal.getPlacement())); | ||
| } | ||
|
|
||
| if (modifiedImps.isEmpty()) { | ||
| return Result.withErrors(errors); | ||
| } | ||
|
|
||
| final BidRequest modifiedRequest = modifyBidRequest(request, account, modifiedImps); | ||
| return Result.of( | ||
| Collections.singletonList(BidderUtil.defaultRequest(modifiedRequest, endpointUrl, mapper)), | ||
| errors); | ||
| } | ||
|
|
||
| private ExtImpTeal parseImpExt(Imp imp) { | ||
| try { | ||
| return mapper.mapper().convertValue(imp.getExt(), TYPE_REFERENCE).getBidder(); | ||
| } catch (IllegalArgumentException e) { | ||
| throw new PreBidException("Error parsing imp.ext for impression " + imp.getId()); | ||
| } | ||
| } | ||
|
|
||
| private static void validateImpExt(ExtImpTeal extImpTeal) { | ||
| if (StringUtils.isBlank(extImpTeal.getAccount())) { | ||
| throw new PreBidException("account parameter failed validation"); | ||
| } | ||
|
|
||
| final String placement = extImpTeal.getPlacement(); | ||
| if (placement != null && StringUtils.isBlank(placement)) { | ||
| throw new PreBidException("placement parameter failed validation"); | ||
| } | ||
| } | ||
|
|
||
| private static Imp modifyImp(Imp imp, String placement) { | ||
| if (placement == null) { | ||
| return imp; | ||
| } | ||
|
|
||
| final ObjectNode modifiedExt = imp.getExt().deepCopy(); | ||
| getOrCreate(getOrCreate(modifiedExt, "prebid"), "storedrequest") | ||
| .put("id", placement); | ||
|
|
||
| return imp.toBuilder().ext(modifiedExt).build(); | ||
| } | ||
|
|
||
| private static ObjectNode getOrCreate(ObjectNode parent, String field) { | ||
| final JsonNode child = parent.get(field); | ||
| return child != null && child.isObject() | ||
| ? (ObjectNode) child | ||
| : parent.putObject(field); | ||
| } | ||
|
|
||
| private BidRequest modifyBidRequest(BidRequest request, String account, List<Imp> modifiedImps) { | ||
| final ExtRequest ext = ObjectUtils.defaultIfNull(request.getExt(), ExtRequest.empty()); | ||
| ext.addProperty("bids", mapper.mapper().createObjectNode().put("pbs", 1)); | ||
|
|
||
| return request.toBuilder() | ||
| .site(modifySite(request.getSite(), account)) | ||
| .app(modifyApp(request.getApp(), account)) | ||
| .imp(modifiedImps) | ||
| .ext(ext) | ||
| .build(); | ||
| } | ||
|
|
||
| private static Site modifySite(Site site, String account) { | ||
| return site != null | ||
| ? site.toBuilder() | ||
| .publisher(modifyPublisher(site.getPublisher(), account)) | ||
| .build() | ||
| : null; | ||
| } | ||
|
|
||
| private static App modifyApp(App app, String account) { | ||
| return app != null | ||
| ? app.toBuilder() | ||
| .publisher(modifyPublisher(app.getPublisher(), account)) | ||
| .build() | ||
| : null; | ||
| } | ||
CTMBNara marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| private static Publisher modifyPublisher(Publisher publisher, String account) { | ||
| return Optional.ofNullable(publisher) | ||
| .map(Publisher::toBuilder) | ||
| .orElseGet(Publisher::builder) | ||
| .id(account) | ||
| .build(); | ||
| } | ||
CTMBNara marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @Override | ||
| public final Result<List<BidderBid>> makeBids(BidderCall<BidRequest> httpCall, BidRequest bidRequest) { | ||
| try { | ||
| final BidResponse bidResponse = mapper.decodeValue(httpCall.getResponse().getBody(), BidResponse.class); | ||
| return Result.withValues(extractBids(httpCall.getRequest().getPayload(), bidResponse)); | ||
| } catch (DecodeException e) { | ||
| return Result.withError(BidderError.badServerResponse(e.getMessage())); | ||
| } | ||
| } | ||
|
|
||
| private static List<BidderBid> extractBids(BidRequest bidRequest, BidResponse bidResponse) { | ||
| if (bidResponse == null || CollectionUtils.isEmpty(bidResponse.getSeatbid())) { | ||
| return Collections.emptyList(); | ||
| } | ||
| return bidsFromResponse(bidRequest, bidResponse); | ||
| } | ||
|
|
||
| private static List<BidderBid> bidsFromResponse(BidRequest bidRequest, BidResponse bidResponse) { | ||
| return bidResponse.getSeatbid().stream() | ||
| .filter(Objects::nonNull) | ||
| .map(SeatBid::getBid) | ||
| .filter(Objects::nonNull) | ||
| .flatMap(Collection::stream) | ||
| .filter(Objects::nonNull) | ||
| .map(bid -> BidderBid.of(bid, getBidType(bid.getImpid(), bidRequest.getImp()), bidResponse.getCur())) | ||
CTMBNara marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| .toList(); | ||
| } | ||
|
|
||
| private static BidType getBidType(String impId, List<Imp> imps) { | ||
| for (Imp imp : imps) { | ||
| if (imp.getId().equals(impId)) { | ||
| if (imp.getBanner() != null) { | ||
| return BidType.banner; | ||
| } else if (imp.getVideo() != null) { | ||
| return BidType.video; | ||
| } else if (imp.getAudio() != null) { | ||
| return BidType.audio; | ||
| } else if (imp.getXNative() != null) { | ||
| return BidType.xNative; | ||
| } | ||
| } | ||
| } | ||
| return BidType.banner; | ||
| } | ||
| } | ||
11 changes: 11 additions & 0 deletions
11
src/main/java/org/prebid/server/proto/openrtb/ext/request/teal/ExtImpTeal.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,11 @@ | ||
| package org.prebid.server.proto.openrtb.ext.request.teal; | ||
|
|
||
| import lombok.Value; | ||
|
|
||
| @Value(staticConstructor = "of") | ||
| public class ExtImpTeal { | ||
|
|
||
| String account; | ||
|
|
||
| String placement; | ||
| } |
42 changes: 42 additions & 0 deletions
42
src/main/java/org/prebid/server/spring/config/bidder/TealConfiguration.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,42 @@ | ||
| package org.prebid.server.spring.config.bidder; | ||
|
|
||
| import org.prebid.server.bidder.BidderDeps; | ||
| import org.prebid.server.bidder.teal.TealBidder; | ||
| 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/teal.yaml", factory = YamlPropertySourceFactory.class) | ||
| public class TealConfiguration { | ||
|
|
||
| private static final String BIDDER_NAME = "teal"; | ||
|
|
||
| @Bean("tealConfigurationProperties") | ||
| @ConfigurationProperties("adapters.teal") | ||
| BidderConfigurationProperties configurationProperties() { | ||
| return new BidderConfigurationProperties(); | ||
| } | ||
|
|
||
| @Bean | ||
| BidderDeps tealBidderDeps(BidderConfigurationProperties tealConfigurationProperties, | ||
| @NotBlank @Value("${external-url}") String externalUrl, | ||
| JacksonMapper mapper) { | ||
|
|
||
| return BidderDepsAssembler.forBidder(BIDDER_NAME) | ||
| .withConfig(tealConfigurationProperties) | ||
| .usersyncerCreator(UsersyncerCreator.create(externalUrl)) | ||
| .bidderCreator(config -> new TealBidder(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,30 @@ | ||
| adapters: | ||
| teal: | ||
| ortb-version: "2.6" | ||
| endpoint: https://a.bids.ws/openrtb2/auction | ||
| modifying-vast-xml-allowed: true | ||
| endpoint-compression: gzip | ||
| geoscope: | ||
| - global | ||
| aliases: | ||
| tealplus: | ||
| enabled: false | ||
| ortb: | ||
| multiformat-supported: true | ||
| meta-info: | ||
| maintainer-email: prebid@teal.works | ||
| app-media-types: | ||
| - banner | ||
| - video | ||
| - native | ||
| site-media-types: | ||
| - banner | ||
| - video | ||
| - native | ||
| supported-vendors: | ||
| vendor-id: 1378 | ||
| usersync: | ||
| cookie-family-name: teal | ||
| iframe: | ||
| url: https://bids.ws/load-pbs.html?gdpr={{gdpr}}&gdpr_consent={{gdpr_consent}}&us_privacy={{us_privacy}}&redirect_url={{redirect_url}} | ||
| support-cors: false |
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,19 @@ | ||
| { | ||
| "$schema": "http://json-schema.org/draft-04/schema#", | ||
| "title": "Teal Adapter Params", | ||
| "description": "A schema which validates params accepted by the Teal adapter", | ||
| "type": "object", | ||
| "properties": { | ||
| "account": { | ||
| "type": "string", | ||
| "description": "Account ID" | ||
| }, | ||
| "placement": { | ||
| "type": "string", | ||
| "description": "Placement ID or name (optional)" | ||
| } | ||
| }, | ||
| "required": [ | ||
| "account" | ||
| ] | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.