-
Notifications
You must be signed in to change notification settings - Fork 224
Adverxo: New adapter ported from Go #3705
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
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ae9b2f2
AdverxoTest does not work
przemkaczmarek 50062ce
fix checkstyle
przemkaczmarek 84a0490
Fix tests
przemkaczmarek 61c230f
fix clean code
przemkaczmarek 2be2f83
fix comments
przemkaczmarek a333369
fix comments
przemkaczmarek 37ee752
fix comments
przemkaczmarek c21a5aa
removing params in integration tests
przemkaczmarek 86b00f3
fix comments
przemkaczmarek 97c61ec
fix comments
przemkaczmarek aab6750
fix comments
przemkaczmarek 6f0427d
fix comments
przemkaczmarek 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
183 changes: 183 additions & 0 deletions
183
src/main/java/org/prebid/server/bidder/adverxo/AdverxoBidder.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,183 @@ | ||
| package org.prebid.server.bidder.adverxo; | ||
|
|
||
| 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.Price; | ||
| import org.prebid.server.bidder.model.Result; | ||
| import org.prebid.server.currency.CurrencyConversionService; | ||
| 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.adverxo.ExtImpAdverxo; | ||
| import org.prebid.server.proto.openrtb.ext.response.BidType; | ||
| import org.prebid.server.util.BidderUtil; | ||
| import org.prebid.server.util.HttpUtil; | ||
|
|
||
| import java.math.BigDecimal; | ||
| import java.util.ArrayList; | ||
| import java.util.Collection; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Objects; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public class AdverxoBidder implements Bidder<BidRequest> { | ||
|
|
||
| private static final TypeReference<ExtPrebid<?, ExtImpAdverxo>> ADVERXO_EXT_TYPE_REFERENCE = | ||
| new TypeReference<>() { | ||
| }; | ||
| private static final String DEFAULT_BID_CURRENCY = "USD"; | ||
| private static final String ADUNIT_MACROS_ENDPOINT = "{{adUnitId}}"; | ||
| private static final String AUTH_MACROS_ENDPOINT = "{{auth}}"; | ||
| private static final String PRICE_MACRO = "${AUCTION_PRICE}"; | ||
|
|
||
| private final String endpointUrl; | ||
| private final JacksonMapper mapper; | ||
| private final CurrencyConversionService currencyConversionService; | ||
|
|
||
| public AdverxoBidder(String endpointUrl, | ||
| JacksonMapper mapper, | ||
| CurrencyConversionService currencyConversionService) { | ||
|
|
||
| this.endpointUrl = HttpUtil.validateUrl(Objects.requireNonNull(endpointUrl)); | ||
| this.mapper = mapper; | ||
| this.currencyConversionService = currencyConversionService; | ||
| } | ||
|
|
||
| @Override | ||
| public Result<List<HttpRequest<BidRequest>>> makeHttpRequests(BidRequest request) { | ||
| final List<BidderError> errors = new ArrayList<>(); | ||
| final List<HttpRequest<BidRequest>> requests = new ArrayList<>(); | ||
|
|
||
| for (Imp imp : request.getImp()) { | ||
| try { | ||
| final ExtImpAdverxo extImp = parseImpExt(imp); | ||
| final String endpoint = resolveEndpoint(extImp); | ||
| final Imp modifiedImp = modifyImp(request, imp); | ||
| final BidRequest outgoingRequest = createRequest(request, modifiedImp); | ||
|
|
||
| requests.add(BidderUtil.defaultRequest(outgoingRequest, endpoint, mapper)); | ||
| } catch (PreBidException e) { | ||
| errors.add(BidderError.badInput(e.getMessage())); | ||
| } | ||
| } | ||
|
|
||
| return Result.of(requests, errors); | ||
| } | ||
|
|
||
| private ExtImpAdverxo parseImpExt(Imp imp) { | ||
| try { | ||
| return mapper.mapper().convertValue(imp.getExt(), ADVERXO_EXT_TYPE_REFERENCE).getBidder(); | ||
| } catch (IllegalArgumentException e) { | ||
| throw new PreBidException("Error parsing ext.imp.bidder: " + e.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| private String resolveEndpoint(ExtImpAdverxo extImp) { | ||
| return endpointUrl | ||
| .replace(ADUNIT_MACROS_ENDPOINT, Objects.toString(extImp.getAdUnitId(), "0")) | ||
| .replace(AUTH_MACROS_ENDPOINT, HttpUtil.encodeUrl(StringUtils.defaultString(extImp.getAuth()))); | ||
| } | ||
|
|
||
| private Imp modifyImp(BidRequest bidRequest, Imp imp) { | ||
| final Price resolvedBidFloor = resolveBidFloor(imp, bidRequest); | ||
|
|
||
| return imp.toBuilder() | ||
| .bidfloor(resolvedBidFloor.getValue()) | ||
| .bidfloorcur(resolvedBidFloor.getCurrency()) | ||
| .build(); | ||
| } | ||
|
|
||
| private Price resolveBidFloor(Imp imp, BidRequest bidRequest) { | ||
| final Price initialBidFloorPrice = Price.of(imp.getBidfloorcur(), imp.getBidfloor()); | ||
| return BidderUtil.shouldConvertBidFloor(initialBidFloorPrice, DEFAULT_BID_CURRENCY) | ||
| ? convertBidFloor(initialBidFloorPrice, bidRequest) | ||
| : initialBidFloorPrice; | ||
| } | ||
|
|
||
| private Price convertBidFloor(Price bidFloorPrice, BidRequest bidRequest) { | ||
| final BigDecimal convertedPrice = currencyConversionService.convertCurrency( | ||
| bidFloorPrice.getValue(), | ||
| bidRequest, | ||
| bidFloorPrice.getCurrency(), | ||
| DEFAULT_BID_CURRENCY); | ||
|
|
||
| return Price.of(DEFAULT_BID_CURRENCY, convertedPrice); | ||
| } | ||
|
|
||
| private static BidRequest createRequest(BidRequest originalRequest, Imp modifiedImp) { | ||
| return originalRequest.toBuilder() | ||
| .imp(Collections.singletonList(modifiedImp)) | ||
| .build(); | ||
| } | ||
|
|
||
| @Override | ||
| public Result<List<BidderBid>> makeBids(BidderCall<BidRequest> httpCall, BidRequest bidRequest) { | ||
| try { | ||
| final BidResponse bidResponse = mapper.decodeValue(httpCall.getResponse().getBody(), BidResponse.class); | ||
| return Result.withValues(extractBids(bidResponse)); | ||
| } catch (DecodeException | PreBidException e) { | ||
| return Result.withError(BidderError.badServerResponse(e.getMessage())); | ||
| } | ||
| } | ||
|
|
||
| private List<BidderBid> extractBids(BidResponse bidResponse) { | ||
| 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 -> makeBid(bid, bidResponse.getCur())) | ||
| .collect(Collectors.toList()); | ||
| } | ||
|
|
||
| private BidderBid makeBid(Bid bid, String currency) { | ||
| final BidType bidType = getBidType(bid.getMtype()); | ||
| final String resolvedAdm = bidType == BidType.xNative ? resolveAdm(bid.getAdm(), bid.getPrice()) : bid.getAdm(); | ||
| final Bid processedBid = processBidMacros(bid, resolvedAdm); | ||
|
|
||
| return BidderBid.of(processedBid, bidType, currency); | ||
| } | ||
|
|
||
| private static BidType getBidType(Integer mType) { | ||
| return switch (mType) { | ||
| case 1 -> BidType.banner; | ||
| case 2 -> BidType.video; | ||
| case 4 -> BidType.xNative; | ||
| case null, default -> throw new PreBidException("Unsupported mType " + mType); | ||
| }; | ||
| } | ||
|
|
||
| private static Bid processBidMacros(Bid bid, String adm) { | ||
| final String price = bid.getPrice() != null ? bid.getPrice().toPlainString() : "0"; | ||
|
|
||
| return bid.toBuilder() | ||
| .adm(replaceMacro(adm, price)) | ||
| .build(); | ||
| } | ||
|
|
||
| private static String replaceMacro(String input, String value) { | ||
| return input != null ? input.replace(PRICE_MACRO, value) : null; | ||
| } | ||
|
|
||
| private static String resolveAdm(String bidAdm, BigDecimal price) { | ||
| return StringUtils.isNotBlank(bidAdm) ? bidAdm.replace("${AUCTION_PRICE}", String.valueOf(price)) : bidAdm; | ||
| } | ||
| } |
13 changes: 13 additions & 0 deletions
13
src/main/java/org/prebid/server/proto/openrtb/ext/request/adverxo/ExtImpAdverxo.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.adverxo; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import lombok.Value; | ||
|
|
||
| @Value(staticConstructor = "of") | ||
| public class ExtImpAdverxo { | ||
|
|
||
| @JsonProperty("adUnitId") | ||
| Integer adUnitId; | ||
|
|
||
| String auth; | ||
| } |
43 changes: 43 additions & 0 deletions
43
src/main/java/org/prebid/server/spring/config/bidder/AdverxoBidderConfiguration.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,43 @@ | ||
| package org.prebid.server.spring.config.bidder; | ||
|
|
||
| import org.prebid.server.bidder.BidderDeps; | ||
| import org.prebid.server.bidder.adverxo.AdverxoBidder; | ||
| import org.prebid.server.currency.CurrencyConversionService; | ||
| 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/adverxo.yaml", factory = YamlPropertySourceFactory.class) | ||
| public class AdverxoBidderConfiguration { | ||
|
|
||
| private static final String BIDDER_NAME = "adverxo"; | ||
|
|
||
| @Bean("adverxoConfigurationProperties") | ||
| @ConfigurationProperties("adapters.adverxo") | ||
| BidderConfigurationProperties configurationProperties() { | ||
| return new BidderConfigurationProperties(); | ||
| } | ||
|
|
||
| @Bean | ||
| BidderDeps adverxoBidderDeps(BidderConfigurationProperties adverxoConfigurationProperties, | ||
| @NotBlank @Value("${external-url}") String externalUrl, | ||
| JacksonMapper mapper, | ||
| CurrencyConversionService currencyConversionService) { | ||
|
|
||
| return BidderDepsAssembler.forBidder(BIDDER_NAME) | ||
| .withConfig(adverxoConfigurationProperties) | ||
| .usersyncerCreator(UsersyncerCreator.create(externalUrl)) | ||
| .bidderCreator(config -> new AdverxoBidder(config.getEndpoint(), mapper, currencyConversionService)) | ||
| .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,70 @@ | ||
| adapters: | ||
| adverxo: | ||
| endpoint: https://pbsadverxo.com/auction?adUnitId={{adUnitId}}&auth={{auth}} | ||
| endpoint-compression: gzip | ||
| aliases: | ||
CTMBNara marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| adport: | ||
| enabled: false | ||
| endpoint: https://adport.pbsadverxo.com/auction?id={{adUnitId}}&auth={{auth}} | ||
| usersync: | ||
| enabled: false | ||
| cookie-family-name: adport | ||
| iframe: | ||
CTMBNara marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| url: https://adport.pbsadverxo.com/usync?type=iframe&gdpr={{gdpr}}&consent={{gdpr_consent}}&us_privacy={{us_privacy}}&redirect={{redirect_url}} | ||
| uid-macro: '$UID' | ||
| support-cors: false | ||
| redirect: | ||
| url: https://adport.pbsadverxo.com/usync?type=image&gdpr={{gdpr}}&consent={{gdpr_consent}}&us_privacy={{us_privacy}}&redirect={{redirect_url}} | ||
| uid-macro: '$UID' | ||
| support-cors: false | ||
| bidsmind: | ||
| enabled: false | ||
| endpoint: https://bidsmind.pbsadverxo.com/auction?id={{adUnitId}}&auth={{auth}} | ||
| usersync: | ||
| enabled: false | ||
| cookie-family-name: bidsmind | ||
| iframe: | ||
| url: https://bidsmind.pbsadverxo.com/usync?type=iframe&gdpr={{gdpr}}&consent={{gdpr_consent}}&us_privacy={{us_privacy}}&redirect={{redirect_url}} | ||
| uid-macro: '$UID' | ||
| support-cors: false | ||
| redirect: | ||
| url: https://bidsmind.pbsadverxo.com/usync?type=image&gdpr={{gdpr}}&consent={{gdpr_consent}}&us_privacy={{us_privacy}}&redirect={{redirect_url}} | ||
| uid-macro: '$UID' | ||
| support-cors: false | ||
| mobupps: | ||
| enabled: false | ||
| endpoint: https://mobupps.pbsadverxo.com/auction?id={{adUnitId}}&auth={{auth}} | ||
| usersync: | ||
| enabled: false | ||
| cookie-family-name: mobupps | ||
| iframe: | ||
| url: https://mobupps.pbsadverxo.com/usync?type=iframe&gdpr={{gdpr}}&consent={{gdpr_consent}}&us_privacy={{us_privacy}}&redirect={{redirect_url}} | ||
| uid-macro: '$UID' | ||
| support-cors: false | ||
| redirect: | ||
| url: https://mobupps.pbsadverxo.com/usync?type=image&gdpr={{gdpr}}&consent={{gdpr_consent}}&us_privacy={{us_privacy}}&redirect={{redirect_url}} | ||
| uid-macro: '$UID' | ||
| support-cors: false | ||
| meta-info: | ||
| maintainer-email: developer@adverxo.com | ||
| app-media-types: | ||
| - banner | ||
| - native | ||
| - video | ||
| site-media-types: | ||
| - banner | ||
| - native | ||
| - video | ||
| supported-vendors: | ||
| vendor-id: 0 | ||
| usersync: | ||
| cookie-family-name: adverxo | ||
| iframe: | ||
| url: https://pbsadverxo.com/usync?type=iframe&gdpr={{gdpr}}&consent={{gdpr_consent}}&us_privacy={{us_privacy}}&redirect={{redirect_url}} | ||
| support-cors: false | ||
| uid-macro: '$UID' | ||
| redirect: | ||
| url: https://pbsadverxo.com/usync?type=image&gdpr={{gdpr}}&consent={{gdpr_consent}}&us_privacy={{us_privacy}}&redirect={{redirect_url}} | ||
| support-cors: false | ||
| uid-macro: '$UID' | ||
|
|
||
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": "Adverxo Adapter Params", | ||
| "description": "A schema which validates params accepted by the Adverxo adapter", | ||
| "type": "object", | ||
| "properties": { | ||
| "adUnitId": { | ||
| "type": "integer", | ||
| "minimum": 1, | ||
| "description": "Unique identifier for the ad unit in Adverxo platform." | ||
| }, | ||
| "auth": { | ||
| "type": "string", | ||
| "minLength": 6, | ||
| "description": "Authentication token provided by Adverxo platform for the AdUnit." | ||
| } | ||
| }, | ||
| "required": ["adUnitId", "auth"] | ||
| } |
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.