-
Notifications
You must be signed in to change notification settings - Fork 242
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
7
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
7 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 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
204 changes: 204 additions & 0 deletions
204
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,204 @@ | ||
| 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 io.vertx.core.http.HttpMethod; | ||
| 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.HttpUtil; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| 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 String endpointUrl; | ||
| private final JacksonMapper mapper; | ||
|
|
||
| public FloxisBidder(String endpointUrl, JacksonMapper mapper) { | ||
| this.endpointUrl = HttpUtil.validateUrl(Objects.requireNonNull(endpointUrl)); | ||
| this.mapper = Objects.requireNonNull(mapper); | ||
| } | ||
|
|
||
| @Override | ||
| public Result<List<HttpRequest<BidRequest>>> makeHttpRequests(BidRequest request) { | ||
| final List<Imp> imps = request.getImp(); | ||
| final Imp firstImp = imps.getFirst(); | ||
|
|
||
| final ExtImpFloxis firstImpExt; | ||
| try { | ||
| firstImpExt = parseImpExt(firstImp); | ||
| } catch (PreBidException e) { | ||
| return Result.withError(BidderError.badInput(e.getMessage())); | ||
| } | ||
|
|
||
| try { | ||
| for (int i = 1; i < imps.size(); i++) { | ||
| final Imp imp = imps.get(i); | ||
| validateImpExt(parseImpExt(imp), firstImpExt, imp.getId(), firstImp.getId()); | ||
| } | ||
| } catch (PreBidException e) { | ||
| return Result.withError(BidderError.badInput(e.getMessage())); | ||
| } | ||
|
|
||
| return Result.withValue(HttpRequest.<BidRequest>builder() | ||
| .method(HttpMethod.POST) | ||
| .uri(resolveUrl(endpointUrl, firstImpExt)) | ||
| .headers(HttpUtil.headers()) | ||
| .impIds(BidderUtil.impIds(request)) | ||
| .payload(request) | ||
| .body(mapper.encodeToBytes(request)) | ||
| .build()); | ||
| } | ||
|
|
||
| private ExtImpFloxis parseImpExt(Imp imp) { | ||
| try { | ||
| return 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())); | ||
| } | ||
| } | ||
|
|
||
| private static void validateImpExt(ExtImpFloxis impExt, | ||
| ExtImpFloxis firstImpExt, | ||
| String impId, | ||
| String firstImpId) { | ||
|
|
||
| if (!Objects.equals(impExt.getSeat(), firstImpExt.getSeat()) | ||
| || !Objects.equals(impExt.getRegion(), firstImpExt.getRegion()) | ||
| || !Objects.equals(impExt.getPartner(), firstImpExt.getPartner())) { | ||
| throw new PreBidException( | ||
| "all impressions must target the same Floxis seat, region and partner; " | ||
| + "imp %s differs from imp %s".formatted(impId, firstImpId)); | ||
| } | ||
| } | ||
|
|
||
| private static String resolveUrl(String endpoint, ExtImpFloxis extImp) { | ||
| return endpoint | ||
| .replace(HOST_MACRO, resolveBidHost(extImp.getRegion(), extImp.getPartner())) | ||
| .replace(SEAT_MACRO, HttpUtil.encodeUrl(extImp.getSeat())); | ||
| } | ||
|
|
||
| private static String resolveBidHost(String region, String partner) { | ||
| final String resolvedRegion = StringUtils.isBlank(region) ? DEFAULT_REGION : region; | ||
| final String resolvedPartner = StringUtils.isBlank(partner) ? DEFAULT_PARTNER : partner; | ||
| return resolvedPartner.equals(DEFAULT_PARTNER) | ||
| ? HttpUtil.encodeUrl(resolvedRegion) | ||
| : HttpUtil.encodeUrl(resolvedPartner) + "-" + HttpUtil.encodeUrl(resolvedRegion); | ||
| } | ||
|
|
||
| @Override | ||
| public Result<List<BidderBid>> makeBids(BidderCall<BidRequest> httpCall, BidRequest bidRequest) { | ||
| final BidResponse bidResponse; | ||
| try { | ||
| bidResponse = mapper.decodeValue(httpCall.getResponse().getBody(), BidResponse.class); | ||
| } catch (DecodeException e) { | ||
| return Result.withError(BidderError.badServerResponse(e.getMessage())); | ||
| } | ||
| return extractBids(bidResponse, bidRequest); | ||
| } | ||
|
|
||
| private static Result<List<BidderBid>> extractBids(BidResponse bidResponse, BidRequest bidRequest) { | ||
| if (bidResponse == null || CollectionUtils.isEmpty(bidResponse.getSeatbid())) { | ||
| return Result.empty(); | ||
| } | ||
|
|
||
| final List<BidderError> errors = new ArrayList<>(); | ||
| final List<BidderBid> bids = new ArrayList<>(); | ||
| for (SeatBid seatBid : bidResponse.getSeatbid()) { | ||
| if (seatBid == null || CollectionUtils.isEmpty(seatBid.getBid())) { | ||
| continue; | ||
| } | ||
| for (Bid bid : seatBid.getBid()) { | ||
| try { | ||
| bids.add(BidderBid.of(bid, getMediaTypeForBid(bidRequest.getImp(), bid), bidResponse.getCur())); | ||
| } catch (PreBidException e) { | ||
| errors.add(BidderError.badServerResponse(e.getMessage())); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return Result.of(bids, errors); | ||
| } | ||
|
|
||
| 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; | ||
| } | ||
| } | ||
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; | ||
| } |
42 changes: 42 additions & 0 deletions
42
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,42 @@ | ||
| 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.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/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, | ||
| @NotBlank @Value("${external-url}") String externalUrl, | ||
| JacksonMapper mapper) { | ||
|
|
||
| return BidderDepsAssembler.forBidder(BIDDER_NAME) | ||
| .withConfig(floxisConfigurationProperties) | ||
| .usersyncerCreator(UsersyncerCreator.create(externalUrl)) | ||
| .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,25 @@ | ||
| 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}}" | ||
| support-cors: false | ||
| 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,25 @@ | ||
| { | ||
| "$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", | ||
| "additionalProperties": false, | ||
| "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.
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.
extract to separate method (see other bidders)
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.
Extracted into a separate extractBids method, matching the other bidders.