-
Notifications
You must be signed in to change notification settings - Fork 224
New Adapter: Start.io #3941
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
Merged
CTMBNara
merged 4 commits into
prebid:master
from
startappdev:implement-start-io-adapter
Jun 10, 2025
Merged
New Adapter: Start.io #3941
Changes from all commits
Commits
Show all changes
4 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
149 changes: 149 additions & 0 deletions
149
src/main/java/org/prebid/server/bidder/startio/StartioBidder.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,149 @@ | ||
| package org.prebid.server.bidder.startio; | ||
|
|
||
| import com.fasterxml.jackson.core.JsonPointer; | ||
| import com.fasterxml.jackson.databind.JsonNode; | ||
| import com.iab.openrtb.request.App; | ||
| import com.iab.openrtb.request.BidRequest; | ||
| import com.iab.openrtb.request.Imp; | ||
| import com.iab.openrtb.request.Site; | ||
| import com.iab.openrtb.response.Bid; | ||
| import com.iab.openrtb.response.BidResponse; | ||
| import com.iab.openrtb.response.SeatBid; | ||
| import org.apache.commons.collections4.CollectionUtils; | ||
| 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.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 StartioBidder implements Bidder<BidRequest> { | ||
|
|
||
| private static final JsonPointer BID_TYPE_POINTER = JsonPointer.valueOf("/prebid/type"); | ||
| private static final String BID_CURRENCY = "USD"; | ||
|
|
||
| private final String endpointUrl; | ||
| private final JacksonMapper mapper; | ||
|
|
||
| public StartioBidder(String endpointUrl, JacksonMapper mapper) { | ||
| this.endpointUrl = HttpUtil.validateUrl(Objects.requireNonNull(endpointUrl)); | ||
| this.mapper = Objects.requireNonNull(mapper); | ||
| } | ||
|
|
||
| @Override | ||
| public final Result<List<HttpRequest<BidRequest>>> makeHttpRequests(BidRequest bidRequest) { | ||
| if (hasNoAppOrSiteId(bidRequest)) { | ||
| return Result.withError(BidderError.badInput( | ||
| "Bidder requires either app.id or site.id to be specified.")); | ||
| } | ||
|
|
||
| if (isSupportedCurrency(bidRequest.getCur())) { | ||
| return Result.withError(BidderError.badInput("Unsupported currency, bidder only accepts USD.")); | ||
| } | ||
|
|
||
| final List<HttpRequest<BidRequest>> requests = new ArrayList<>(); | ||
| final List<BidderError> errors = new ArrayList<>(); | ||
| final List<Imp> imps = bidRequest.getImp(); | ||
| for (int i = 0; i < imps.size(); i++) { | ||
| final Imp imp = imps.get(i); | ||
| if (imp.getBanner() == null && imp.getVideo() == null && imp.getXNative() == null) { | ||
| errors.add(BidderError.badInput( | ||
| "imp[%d]: Unsupported media type, bidder does not support audio.".formatted(i))); | ||
|
|
||
| continue; | ||
| } | ||
|
|
||
| final Imp modifiedImp = imp.getAudio() != null | ||
| ? imp.toBuilder().audio(null).build() | ||
| : imp; | ||
| requests.add(BidderUtil.defaultRequest( | ||
| bidRequest.toBuilder().imp(Collections.singletonList(modifiedImp)).build(), | ||
| endpointUrl, mapper)); | ||
| } | ||
|
|
||
| return Result.of(requests, errors); | ||
| } | ||
|
|
||
| private static boolean hasNoAppOrSiteId(BidRequest bidRequest) { | ||
| final App app = bidRequest.getApp(); | ||
| final Site site = bidRequest.getSite(); | ||
| return (app == null || StringUtils.isEmpty(app.getId())) | ||
| && (site == null || StringUtils.isEmpty(site.getId())); | ||
| } | ||
|
|
||
| private static boolean isSupportedCurrency(List<String> currencies) { | ||
| return CollectionUtils.isNotEmpty(currencies) && !currencies.contains(BID_CURRENCY); | ||
| } | ||
|
|
||
| @Override | ||
| public final Result<List<BidderBid>> makeBids(BidderCall<BidRequest> httpCall, BidRequest bidRequest) { | ||
| final BidResponse response; | ||
|
|
||
| try { | ||
| response = mapper.decodeValue(httpCall.getResponse().getBody(), BidResponse.class); | ||
| } catch (DecodeException e) { | ||
| return Result.withError(BidderError.badServerResponse(e.getMessage())); | ||
| } | ||
|
|
||
| final List<BidderError> errors = new ArrayList<>(); | ||
| return Result.of(extractBids(response, errors), errors); | ||
| } | ||
|
|
||
| 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 -> constructBidderBid(bid, bidResponse.getCur(), errors)) | ||
| .filter(Objects::nonNull) | ||
| .toList(); | ||
| } | ||
|
|
||
| private static BidderBid constructBidderBid(Bid bid, String currency, List<BidderError> errors) { | ||
| final BidType type = getBidType(bid); | ||
| if (type != null) { | ||
| return BidderBid.of(bid, type, currency); | ||
| } | ||
|
|
||
| errors.add(BidderError.badServerResponse( | ||
| "Failed to parse bid media type for impression %s.".formatted(bid.getImpid()))); | ||
| return null; | ||
| } | ||
|
|
||
| private static BidType getBidType(Bid bid) { | ||
| final JsonNode ext = bid.getExt(); | ||
| final JsonNode bidType = ext != null ? ext.at(BID_TYPE_POINTER) : null; | ||
| if (bidType == null || !bidType.isTextual()) { | ||
| return null; | ||
| } | ||
|
|
||
| return switch (bidType.textValue()) { | ||
| case "banner" -> BidType.banner; | ||
| case "video" -> BidType.video; | ||
| case "native" -> BidType.xNative; | ||
| default -> null; | ||
| }; | ||
| } | ||
|
|
||
| } |
41 changes: 41 additions & 0 deletions
41
src/main/java/org/prebid/server/spring/config/bidder/StartioBidderConfiguration.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.startio.StartioBidder; | ||
| 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/startio.yaml", factory = YamlPropertySourceFactory.class) | ||
| public class StartioBidderConfiguration { | ||
|
|
||
| private static final String BIDDER_NAME = "startio"; | ||
|
|
||
| @Bean("startioConfigurationProperties") | ||
| @ConfigurationProperties("adapters.startio") | ||
| BidderConfigurationProperties configurationProperties() { | ||
| return new BidderConfigurationProperties(); | ||
| } | ||
|
|
||
| @Bean | ||
| BidderDeps startioBidderDeps(BidderConfigurationProperties startioConfigurationProperties, | ||
| @NotBlank @Value("${external-url}") String externalUrl, | ||
| JacksonMapper mapper) { | ||
|
|
||
| return BidderDepsAssembler.forBidder(BIDDER_NAME) | ||
| .withConfig(startioConfigurationProperties) | ||
| .usersyncerCreator(UsersyncerCreator.create(externalUrl)) | ||
| .bidderCreator(config -> new StartioBidder(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,14 @@ | ||
| adapters: | ||
| startio: | ||
| endpoint: http://pbs-rtb.startappnetwork.com/1.3/2.5/getbid?account=pbs | ||
| meta-info: | ||
| maintainer-email: [email protected] | ||
| app-media-types: | ||
| - banner | ||
| - video | ||
| - native | ||
| site-media-types: | ||
| - banner | ||
| - video | ||
| - native | ||
| vendor-id: 1216 |
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,8 @@ | ||
| { | ||
| "$schema": "http://json-schema.org/draft-04/schema#", | ||
| "title": "Start.io Adapter Params", | ||
| "description": "A schema which validates params accepted by the Start.io adapter", | ||
| "type": "object", | ||
| "properties": {}, | ||
| "required": [] | ||
| } |
Oops, something went wrong.
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.