-
Notifications
You must be signed in to change notification settings - Fork 247
Port Floxis: New Adapter #4529
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
floxis-admin
wants to merge
16
commits into
prebid:master
Choose a base branch
from
floxis-admin:floxis-new-adapter
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
Port Floxis: New Adapter #4529
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
07efcf6
Port Floxis: New Adapter
floxis-admin f6797a3
Floxis: set vendor-id to 1609 (IAB TCF registration approved)
floxis-admin 41c57c2
Floxis: declare ortb-version 2.6 + multi-imp seat guard + IT downconvβ¦
floxis-admin 86a34b6
Floxis: mirror Prebid.js seat/region/partner host logic
floxis-admin ee616ff
Floxis adapter: annotate ExtImpFloxis.seat with @JsonProperty for conβ¦
floxis-admin 0db0e0c
Floxis adapter: pin fixed .floxis.tech domain in endpoint (region/parβ¦
floxis-admin 21d1900
Floxis adapter: apply maintainer review feedback
floxis-admin af2757d
Merge remote-tracking branch 'upstream/master' into floxis-new-adapter
floxis-admin 1682006
Floxis adapter: use Uri for endpoint macros and apply review feedback
floxis-admin 1f993a6
Floxis adapter: add http_method to the integration-test bid request fβ¦
floxis-admin 8640651
Floxis adapter: resolve region and partner defaults before comparing β¦
floxis-admin bc31896
Floxis adapter: stop rejecting unknown bidder params
floxis-admin b8bca87
Floxis adapter: use BidderUtil.defaultRequest, drop dead support-corsβ¦
floxis-admin 4b54eb3
Floxis adapter: split multi-imp requests by seat and host
floxis-admin 954c48d
Floxis adapter: validate seat, region and partner in the adapter
floxis-admin edd7b70
Floxis: group imps by a HostId record and drop schema-covered validation
floxis-admin 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
207 changes: 207 additions & 0 deletions
207
src/main/java/org/prebid/server/bidder/floxis/FloxisBidder.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,207 @@ | ||
| package org.prebid.server.bidder.floxis; | ||
|
|
||
| import com.fasterxml.jackson.core.type.TypeReference; | ||
| 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.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.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.floxis.ExtImpFloxis; | ||
| import org.prebid.server.proto.openrtb.ext.response.BidType; | ||
| import org.prebid.server.util.BidderUtil; | ||
| import org.prebid.server.util.Uri; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Collection; | ||
| import java.util.Collections; | ||
| import java.util.LinkedHashMap; | ||
| import java.util.List; | ||
| import java.util.Locale; | ||
| import java.util.Map; | ||
| import java.util.Objects; | ||
|
|
||
| public class FloxisBidder implements Bidder<BidRequest> { | ||
|
|
||
| private static final TypeReference<ExtPrebid<?, ExtImpFloxis>> FLOXIS_EXT_TYPE_REFERENCE = | ||
| new TypeReference<>() { | ||
| }; | ||
|
|
||
| private static final String HOST_MACRO = "Host"; | ||
| private static final String SEAT_MACRO = "SeatId"; | ||
|
|
||
| private static final String DEFAULT_REGION = "us-e"; | ||
| private static final String DEFAULT_PARTNER = "floxis"; | ||
|
|
||
| private final Uri endpointUrl; | ||
| private final JacksonMapper mapper; | ||
|
|
||
| public FloxisBidder(String endpointUrl, JacksonMapper mapper) { | ||
| this.endpointUrl = Uri.of(endpointUrl); | ||
| this.mapper = Objects.requireNonNull(mapper); | ||
| } | ||
|
|
||
| @Override | ||
| public Result<List<HttpRequest<BidRequest>>> makeHttpRequests(BidRequest request) { | ||
| final List<BidderError> errors = new ArrayList<>(); | ||
| final Map<HostId, List<Imp>> impsByHost = new LinkedHashMap<>(); | ||
|
|
||
| for (Imp imp : request.getImp()) { | ||
| final ExtImpFloxis impExt; | ||
| try { | ||
| impExt = parseImpExt(imp); | ||
| } catch (PreBidException e) { | ||
| errors.add(BidderError.badInput(e.getMessage())); | ||
| continue; | ||
| } | ||
|
|
||
| impsByHost.computeIfAbsent(HostId.of(impExt), key -> new ArrayList<>()).add(imp); | ||
| } | ||
|
|
||
| final List<HttpRequest<BidRequest>> httpRequests = impsByHost.entrySet().stream() | ||
| .map(entry -> BidderUtil.defaultRequest( | ||
| request.toBuilder().imp(entry.getValue()).build(), | ||
| resolveUrl(entry.getKey()), | ||
| mapper)) | ||
| .toList(); | ||
|
|
||
| return Result.of(httpRequests, errors); | ||
| } | ||
|
|
||
| private ExtImpFloxis parseImpExt(Imp imp) { | ||
| final ExtImpFloxis impExt; | ||
| try { | ||
| impExt = mapper.mapper().convertValue(imp.getExt(), FLOXIS_EXT_TYPE_REFERENCE).getBidder(); | ||
| } catch (IllegalArgumentException e) { | ||
| throw new PreBidException("invalid imp.ext.bidder for imp %s: %s".formatted(imp.getId(), e.getMessage())); | ||
| } | ||
|
|
||
| final String region = StringUtils.isBlank(impExt.getRegion()) | ||
| ? DEFAULT_REGION | ||
| : impExt.getRegion().toLowerCase(Locale.ROOT); | ||
| final String partner = StringUtils.isBlank(impExt.getPartner()) | ||
| ? DEFAULT_PARTNER | ||
| : impExt.getPartner().toLowerCase(Locale.ROOT); | ||
|
|
||
| return ExtImpFloxis.of(impExt.getSeat(), region, partner); | ||
| } | ||
|
|
||
| private String resolveUrl(HostId hostId) { | ||
| return endpointUrl | ||
| .replaceMacro(HOST_MACRO, hostId.host()) | ||
| .replaceMacro(SEAT_MACRO, hostId.seat()) | ||
| .expand(); | ||
| } | ||
|
|
||
| @Override | ||
| public 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<>(); | ||
| final List<BidderBid> bidderBids = extractBids(bidResponse, bidRequest.getImp(), errors); | ||
| return Result.of(bidderBids, errors); | ||
| } catch (DecodeException e) { | ||
| return Result.withError(BidderError.badServerResponse(e.getMessage())); | ||
| } | ||
| } | ||
|
|
||
| private static List<BidderBid> extractBids(BidResponse bidResponse, List<Imp> imps, List<BidderError> errors) { | ||
| if (bidResponse == null || CollectionUtils.isEmpty(bidResponse.getSeatbid())) { | ||
| return Collections.emptyList(); | ||
| } | ||
|
|
||
| return bidResponse.getSeatbid().stream() | ||
| .filter(Objects::nonNull) | ||
| .map(SeatBid::getBid) | ||
| .filter(Objects::nonNull) | ||
| .flatMap(Collection::stream) | ||
| .filter(Objects::nonNull) | ||
| .map(bid -> makeBidderBid(bid, imps, bidResponse.getCur(), errors)) | ||
| .filter(Objects::nonNull) | ||
| .toList(); | ||
| } | ||
|
|
||
| private static BidderBid makeBidderBid(Bid bid, List<Imp> imps, String currency, List<BidderError> errors) { | ||
| try { | ||
| return BidderBid.of(bid, getMediaTypeForBid(imps, bid), currency); | ||
| } catch (PreBidException e) { | ||
| errors.add(BidderError.badServerResponse(e.getMessage())); | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| private static BidType getMediaTypeForBid(List<Imp> imps, Bid bid) { | ||
| final Integer mtype = bid.getMtype(); | ||
| if (mtype != null && mtype != 0) { | ||
| return switch (mtype) { | ||
| case 1 -> BidType.banner; | ||
| case 2 -> BidType.video; | ||
| case 3 -> BidType.audio; | ||
| case 4 -> BidType.xNative; | ||
| default -> throw new PreBidException( | ||
| "unsupported bid.mtype %d for impression %s".formatted(mtype, bid.getImpid())); | ||
| }; | ||
| } | ||
|
|
||
| final Imp imp = imps.stream() | ||
| .filter(currentImp -> Objects.equals(currentImp.getId(), bid.getImpid())) | ||
| .findFirst() | ||
| .orElseThrow(() -> new PreBidException( | ||
| "unable to find impression %s for bid".formatted(bid.getImpid()))); | ||
|
|
||
| if (countFormats(imp) != 1) { | ||
| throw new PreBidException( | ||
| "unable to resolve a single media type for impression %s; set bid.mtype" | ||
| .formatted(bid.getImpid())); | ||
| } | ||
|
|
||
| if (imp.getBanner() != null) { | ||
| return BidType.banner; | ||
| } else if (imp.getVideo() != null) { | ||
| return BidType.video; | ||
| } else if (imp.getAudio() != null) { | ||
| return BidType.audio; | ||
| } else { | ||
| return BidType.xNative; | ||
| } | ||
| } | ||
|
|
||
| private static int countFormats(Imp imp) { | ||
| int formats = 0; | ||
| if (imp.getBanner() != null) { | ||
| formats++; | ||
| } | ||
| if (imp.getVideo() != null) { | ||
| formats++; | ||
| } | ||
| if (imp.getAudio() != null) { | ||
| formats++; | ||
| } | ||
| if (imp.getXNative() != null) { | ||
| formats++; | ||
| } | ||
| return formats; | ||
| } | ||
|
|
||
| private record HostId(String seat, String host) { | ||
|
|
||
| static HostId of(ExtImpFloxis impExt) { | ||
| final String partner = impExt.getPartner(); | ||
| final String region = impExt.getRegion(); | ||
| return new HostId( | ||
| impExt.getSeat(), | ||
| partner.equals(DEFAULT_PARTNER) ? region : partner + "-" + region); | ||
| } | ||
| } | ||
| } |
13 changes: 13 additions & 0 deletions
13
src/main/java/org/prebid/server/proto/openrtb/ext/request/floxis/ExtImpFloxis.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,13 @@ | ||
| package org.prebid.server.proto.openrtb.ext.request.floxis; | ||
|
|
||
| import lombok.Value; | ||
|
|
||
| @Value(staticConstructor = "of") | ||
| public class ExtImpFloxis { | ||
|
|
||
| String seat; | ||
|
|
||
| String region; | ||
|
|
||
| String partner; | ||
| } |
35 changes: 35 additions & 0 deletions
35
src/main/java/org/prebid/server/spring/config/bidder/FloxisConfiguration.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,35 @@ | ||
| package org.prebid.server.spring.config.bidder; | ||
|
|
||
| import org.prebid.server.bidder.BidderDeps; | ||
| import org.prebid.server.bidder.floxis.FloxisBidder; | ||
| 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.env.YamlPropertySourceFactory; | ||
| 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; | ||
|
|
||
| @Configuration | ||
| @PropertySource(value = "classpath:/bidder-config/floxis.yaml", factory = YamlPropertySourceFactory.class) | ||
| public class FloxisConfiguration { | ||
|
|
||
| private static final String BIDDER_NAME = "floxis"; | ||
|
|
||
| @Bean("floxisConfigurationProperties") | ||
| @ConfigurationProperties("adapters.floxis") | ||
| BidderConfigurationProperties configurationProperties() { | ||
| return new BidderConfigurationProperties(); | ||
| } | ||
|
|
||
| @Bean | ||
| BidderDeps floxisBidderDeps(BidderConfigurationProperties floxisConfigurationProperties, | ||
| JacksonMapper mapper) { | ||
|
|
||
| return BidderDepsAssembler.forBidder(BIDDER_NAME) | ||
| .withConfig(floxisConfigurationProperties) | ||
| .bidderCreator(config -> new FloxisBidder(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,24 @@ | ||
| adapters: | ||
| floxis: | ||
| endpoint: https://{Host}.floxis.tech/pbs?seat={SeatId} | ||
| ortb-version: "2.6" | ||
| modifying-vast-xml-allowed: false | ||
| meta-info: | ||
| maintainer-email: prebid@floxis.tech | ||
| app-media-types: | ||
| - banner | ||
| - video | ||
| - native | ||
| - audio | ||
| site-media-types: | ||
| - banner | ||
| - video | ||
| - native | ||
| - audio | ||
| supported-vendors: | ||
| vendor-id: 1609 | ||
| usersync: | ||
| cookie-family-name: floxis | ||
| redirect: | ||
| url: "https://px-us-e.floxis.tech/sync?gdpr={gdpr}&gdpr_consent={gdpr_consent}&gpp={gpp}&gpp_sid={gpp_sid}&us_privacy={us_privacy}&dest={redirect_url}" | ||
| uid-macro: "${USER_ID}" |
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,24 @@ | ||
| { | ||
| "$schema": "http://json-schema.org/draft-04/schema#", | ||
| "title": "Floxis Adapter Params", | ||
| "description": "A schema which validates params accepted by the Floxis adapter", | ||
| "type": "object", | ||
| "properties": { | ||
| "seat": { | ||
| "type": "string", | ||
| "minLength": 1, | ||
| "description": "The Floxis seat ID this publisher buys through" | ||
| }, | ||
| "region": { | ||
| "type": "string", | ||
| "pattern": "^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?$", | ||
| "description": "The Floxis region (DNS label, interpolated into the bidding host); defaults to us-e when omitted" | ||
| }, | ||
| "partner": { | ||
| "type": "string", | ||
| "pattern": "^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?$", | ||
| "description": "The white-label partner (DNS label, interpolated into the bidding host); defaults to floxis when omitted" | ||
| } | ||
| }, | ||
| "required": ["seat"] | ||
| } |
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.