-
Notifications
You must be signed in to change notification settings - Fork 223
New Adapter: Clydo #4299
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
przemkaczmarek
wants to merge
3
commits into
master
Choose a base branch
from
New-Adapter-Clydo
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
New Adapter: Clydo #4299
Changes from 1 commit
Commits
Show all changes
3 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
178 changes: 178 additions & 0 deletions
178
src/main/java/org/prebid/server/bidder/clydo/ClydoBidder.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,178 @@ | ||
| package org.prebid.server.bidder.clydo; | ||
|
|
||
| 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.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.clydo.ExtImpClydo; | ||
| 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.Collections; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Objects; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public class ClydoBidder implements Bidder<BidRequest> { | ||
|
|
||
| private static final TypeReference<ExtPrebid<?, ExtImpClydo>> CLYDO_EXT_TYPE_REFERENCE = | ||
| new TypeReference<>() { | ||
| }; | ||
|
|
||
| private static final String REGION_MACRO = "{{Region}}"; | ||
| private static final String PARTNER_ID_MACRO = "{{PartnerId}}"; | ||
| private static final String DEFAULT_REGION = "us"; | ||
|
|
||
| private final String endpointUrl; | ||
| private final JacksonMapper mapper; | ||
|
|
||
| public ClydoBidder(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<BidderError> errors = new ArrayList<>(); | ||
| final List<HttpRequest<BidRequest>> httpRequests = new ArrayList<>(); | ||
|
|
||
| for (Imp imp : request.getImp()) { | ||
| try { | ||
| final ExtImpClydo extImpClydo = parseExtImp(imp); | ||
| final HttpRequest<BidRequest> httpRequest = makeHttpRequest(request, imp, extImpClydo); | ||
| httpRequests.add(httpRequest); | ||
| } catch (PreBidException e) { | ||
| errors.add(BidderError.badInput(e.getMessage())); | ||
| } | ||
| } | ||
|
|
||
| if (httpRequests.isEmpty()) { | ||
| return Result.withError(BidderError.badInput("found no valid impressions")); | ||
| } | ||
|
|
||
| return Result.of(httpRequests, errors); | ||
| } | ||
|
|
||
| private ExtImpClydo parseExtImp(Imp imp) { | ||
| try { | ||
| return mapper.mapper().convertValue(imp.getExt(), CLYDO_EXT_TYPE_REFERENCE).getBidder(); | ||
| } catch (IllegalArgumentException e) { | ||
| throw new PreBidException("Cannot deserialize ExtImpClydo: " + e.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| private static String resolveUrl(String endpoint, ExtImpClydo extImp) { | ||
| return endpoint | ||
| .replace(REGION_MACRO, getRegionInfo(extImp)) | ||
| .replace(PARTNER_ID_MACRO, extImp.getPartnerId()); | ||
przemkaczmarek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| private static String getRegionInfo(ExtImpClydo extImp) { | ||
| final String region = extImp.getRegion(); | ||
| if (region == null) { | ||
| return DEFAULT_REGION; | ||
| } | ||
|
|
||
| return switch (region) { | ||
| case "us", "usw", "eu", "apac" -> region; | ||
| default -> DEFAULT_REGION; | ||
| }; | ||
przemkaczmarek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| private HttpRequest<BidRequest> makeHttpRequest(BidRequest request, Imp imp, ExtImpClydo extImpClydo) { | ||
| final BidRequest outgoingRequest = request.toBuilder().imp(List.of(imp)).build(); | ||
|
|
||
| return BidderUtil.defaultRequest(outgoingRequest, resolveUrl(endpointUrl, extImpClydo), mapper); | ||
przemkaczmarek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| @Override | ||
| public Result<List<BidderBid>> makeBids(BidderCall<BidRequest> httpCall, BidRequest bidRequest) { | ||
| try { | ||
| final BidResponse bidResponse = mapper.decodeValue(httpCall.getResponse().getBody(), BidResponse.class); | ||
| final List<BidderBid> bidderBids = extractBids(bidRequest, bidResponse); | ||
| return Result.of(bidderBids, Collections.emptyList()); | ||
przemkaczmarek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } catch (DecodeException e) { | ||
| return Result.withError(BidderError.badServerResponse(e.getMessage())); | ||
| } catch (PreBidException e) { | ||
| return Result.withError(BidderError.badInput(e.getMessage())); | ||
| } | ||
przemkaczmarek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| private List<BidderBid> extractBids(BidRequest bidRequest, BidResponse bidResponse) { | ||
| if (bidResponse == null || bidResponse.getSeatbid() == null || bidResponse.getSeatbid().isEmpty()) { | ||
| return Collections.emptyList(); | ||
| } | ||
|
|
||
| final Map<String, BidType> impIdToBidTypeMap = buildImpIdToBidTypeMap(bidRequest); | ||
|
|
||
| return bidResponse.getSeatbid().stream() | ||
| .filter(Objects::nonNull) | ||
| .map(SeatBid::getBid) | ||
| .filter(Objects::nonNull) | ||
| .flatMap(List::stream) | ||
| .filter(Objects::nonNull) | ||
| .map(bid -> BidderBid.of(bid, resolveBidType(bid, impIdToBidTypeMap), bidResponse.getCur())) | ||
| .collect(Collectors.toList()); | ||
| } | ||
|
|
||
| private static Map<String, BidType> buildImpIdToBidTypeMap(BidRequest bidRequest) { | ||
| if (bidRequest == null || bidRequest.getImp() == null || bidRequest.getImp().isEmpty()) { | ||
| return Collections.emptyMap(); | ||
| } | ||
przemkaczmarek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| final Map<String, BidType> impIdToBidTypeMap = new HashMap<>(); | ||
| for (Imp imp : bidRequest.getImp()) { | ||
| final String impId = imp.getId(); | ||
| if (impIdToBidTypeMap.containsKey(impId)) { | ||
| throw new PreBidException("Duplicate impression ID found"); | ||
| } | ||
przemkaczmarek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| final BidType bidType = determineBidType(imp); | ||
| if (bidType == null) { | ||
| throw new PreBidException("Failed to get media type"); | ||
| } | ||
|
|
||
| impIdToBidTypeMap.put(impId, bidType); | ||
| } | ||
|
|
||
| return impIdToBidTypeMap; | ||
| } | ||
|
|
||
| private static BidType determineBidType(Imp imp) { | ||
| if (imp.getAudio() != null) { | ||
| return BidType.audio; | ||
| } else if (imp.getVideo() != null) { | ||
| return BidType.video; | ||
| } else if (imp.getXNative() != null) { | ||
| return BidType.xNative; | ||
| } else if (imp.getBanner() != null) { | ||
| return BidType.banner; | ||
| } | ||
|
|
||
| return null; | ||
przemkaczmarek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| private static BidType resolveBidType(Bid bid, Map<String, BidType> impIdToBidTypeMap) { | ||
| if (bid.getImpid() == null) { | ||
| throw new PreBidException("Missing imp id for bid.id: '%s'".formatted(bid.getId())); | ||
| } | ||
przemkaczmarek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| return impIdToBidTypeMap.getOrDefault(bid.getImpid(), BidType.banner); | ||
| } | ||
| } | ||
14 changes: 14 additions & 0 deletions
14
src/main/java/org/prebid/server/proto/openrtb/ext/request/clydo/ExtImpClydo.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,14 @@ | ||
| package org.prebid.server.proto.openrtb.ext.request.clydo; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import lombok.Value; | ||
|
|
||
| @Value(staticConstructor = "of") | ||
| public class ExtImpClydo { | ||
|
|
||
| @JsonProperty("partnerId") | ||
| String partnerId; | ||
|
|
||
| @JsonProperty("region") | ||
| String region; | ||
| } |
41 changes: 41 additions & 0 deletions
41
src/main/java/org/prebid/server/spring/config/bidder/ClydoConfiguration.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.clydo.ClydoBidder; | ||
| 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/clydo.yaml", factory = YamlPropertySourceFactory.class) | ||
| public class ClydoConfiguration { | ||
|
|
||
| private static final String BIDDER_NAME = "clydo"; | ||
|
|
||
| @Bean("clydoConfigurationProperties") | ||
| @ConfigurationProperties("adapters.clydo") | ||
| BidderConfigurationProperties configurationProperties() { | ||
| return new BidderConfigurationProperties(); | ||
| } | ||
|
|
||
| @Bean | ||
| BidderDeps clydoBidderDeps(BidderConfigurationProperties clydoConfigurationProperties, | ||
| @NotBlank @Value("${external-url}") String externalUrl, | ||
| JacksonMapper mapper) { | ||
|
|
||
| return BidderDepsAssembler.forBidder(BIDDER_NAME) | ||
| .withConfig(clydoConfigurationProperties) | ||
| .usersyncerCreator(UsersyncerCreator.create(externalUrl)) | ||
| .bidderCreator(config -> new ClydoBidder(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,21 @@ | ||
| adapters: | ||
| clydo: | ||
| endpoint: http://region={{Region}}.clydo.io/partnerId={{PartnerId}} | ||
| modifying-vast-xml-allowed: true | ||
| endpoint-compression: gzip | ||
| geoscope: | ||
| - global | ||
| meta-info: | ||
| maintainer-email: [email protected] | ||
| app-media-types: | ||
| - banner | ||
| - video | ||
| - audio | ||
| - native | ||
| site-media-types: | ||
| - banner | ||
| - video | ||
| - audio | ||
| - native | ||
| supported-vendors: | ||
| vendor-id: 0 |
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,20 @@ | ||
| { | ||
| "$schema": "http://json-schema.org/draft-04/schema#", | ||
| "title": "Clydo Adapter Params", | ||
| "description": "A schema which validates params accepted by the Clydo adapter", | ||
| "type": "object", | ||
| "properties": { | ||
| "partnerId": { | ||
| "type": "string", | ||
| "description": "Partner ID", | ||
| "minLength": 1 | ||
| }, | ||
| "region": { | ||
| "type": "string", | ||
| "description": "Regional endpoint identifier (us, usw, eu, apac)", | ||
| "enum": ["us", "usw", "eu", "apac"] | ||
| } | ||
| }, | ||
|
|
||
| "required": ["partnerId"] | ||
| } |
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.