-
Notifications
You must be signed in to change notification settings - Fork 224
New Adapter: TeqBlaze #4161
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
New Adapter: TeqBlaze #4161
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f946d26
New Adapter: TeqBlaze
przemkaczmarek 63370c9
fix vendor-id: 0
przemkaczmarek a0d4c0d
fix white list
przemkaczmarek 028aec3
fix comments
przemkaczmarek e103afb
fix comments
przemkaczmarek 51d3c77
adding two aliases: pinkLion and rocketlab
przemkaczmarek 23cf838
fix comments
przemkaczmarek e68d3b6
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
141 changes: 141 additions & 0 deletions
141
src/main/java/org/prebid/server/bidder/teqblaze/TeqblazeBidder.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,141 @@ | ||
| package org.prebid.server.bidder.teqblaze; | ||
|
|
||
| import com.fasterxml.jackson.core.type.TypeReference; | ||
| import com.fasterxml.jackson.databind.node.ObjectNode; | ||
| 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.bidder.teqblaze.proto.TeqblazeExtImp; | ||
| 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.teqblaze.ExtImpTeqblaze; | ||
| 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 TeqblazeBidder implements Bidder<BidRequest> { | ||
|
|
||
| private static final TypeReference<ExtPrebid<?, ExtImpTeqblaze>> EXT_TYPE_REF = new TypeReference<>() { | ||
| }; | ||
|
|
||
| private static final String PUBLISHER_PROPERTY = "publisher"; | ||
| private static final String NETWORK_PROPERTY = "network"; | ||
| private static final String BIDDER_PROPERTY = "bidder"; | ||
|
|
||
| private final String endpointUrl; | ||
| private final JacksonMapper mapper; | ||
|
|
||
| public TeqblazeBidder(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 ExtImpTeqblaze extImpTeqblaze = parseExtImp(imp); | ||
| final Imp modifiedImp = modifyImp(imp, extImpTeqblaze); | ||
| httpRequests.add(makeHttpRequest(request, modifiedImp)); | ||
| } catch (PreBidException e) { | ||
| errors.add(BidderError.badInput(e.getMessage())); | ||
| } | ||
| } | ||
|
|
||
| return httpRequests.isEmpty() | ||
| ? Result.withErrors(errors) | ||
| : Result.of(httpRequests, errors); | ||
| } | ||
|
|
||
| private ExtImpTeqblaze parseExtImp(Imp imp) { | ||
| try { | ||
| return mapper.mapper().convertValue(imp.getExt(), EXT_TYPE_REF).getBidder(); | ||
| } catch (IllegalArgumentException e) { | ||
| throw new PreBidException("Cannot deserialize ExtImpTeqblaze: " + e.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| private Imp modifyImp(Imp imp, ExtImpTeqblaze extImpTeqblaze) { | ||
| final TeqblazeExtImp impExtTeqblazeWithType = resolveImpExt(extImpTeqblaze); | ||
| final ObjectNode modifiedImpExtBidder = mapper.mapper().createObjectNode(); | ||
| modifiedImpExtBidder.set(BIDDER_PROPERTY, mapper.mapper().valueToTree(impExtTeqblazeWithType)); | ||
|
|
||
| return imp.toBuilder().ext(modifiedImpExtBidder).build(); | ||
| } | ||
|
|
||
| private TeqblazeExtImp resolveImpExt(ExtImpTeqblaze extImpTeqblaze) { | ||
| final TeqblazeExtImp.TeqblazeExtImpBuilder builder = TeqblazeExtImp.builder(); | ||
|
|
||
| if (StringUtils.isNotEmpty(extImpTeqblaze.getPlacementId())) { | ||
| builder.type(PUBLISHER_PROPERTY).placementId(extImpTeqblaze.getPlacementId()); | ||
| } else if (StringUtils.isNotEmpty(extImpTeqblaze.getEndpointId())) { | ||
| builder.type(NETWORK_PROPERTY).endpointId(extImpTeqblaze.getEndpointId()); | ||
| } | ||
|
|
||
| return builder.build(); | ||
| } | ||
|
|
||
| private HttpRequest<BidRequest> makeHttpRequest(BidRequest request, Imp imp) { | ||
| final BidRequest outgoingRequest = request.toBuilder().imp(List.of(imp)).build(); | ||
|
|
||
| return BidderUtil.defaultRequest(outgoingRequest, endpointUrl, mapper); | ||
| } | ||
|
|
||
| @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> bids = extractBids(bidResponse); | ||
| return Result.withValues(bids); | ||
| } 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 -> BidderBid.of(bid, getBidType(bid), bidResponse.getCur())) | ||
| .toList(); | ||
| } | ||
|
|
||
| private BidType getBidType(Bid bid) { | ||
| return switch (bid.getMtype()) { | ||
| case 1 -> BidType.banner; | ||
| case 2 -> BidType.video; | ||
| case 3 -> BidType.audio; | ||
| case 4 -> BidType.xNative; | ||
| case null, default -> | ||
| throw new PreBidException("could not define media type for impression: " + bid.getImpid()); | ||
| }; | ||
| } | ||
| } | ||
18 changes: 18 additions & 0 deletions
18
src/main/java/org/prebid/server/bidder/teqblaze/proto/TeqblazeExtImp.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,18 @@ | ||
| package org.prebid.server.bidder.teqblaze.proto; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import lombok.Builder; | ||
| import lombok.Value; | ||
|
|
||
| @Value | ||
| @Builder | ||
| public class TeqblazeExtImp { | ||
|
|
||
| String type; | ||
|
|
||
| @JsonProperty("placementId") | ||
| String placementId; | ||
|
|
||
| @JsonProperty("endpointId") | ||
| String endpointId; | ||
| } |
14 changes: 14 additions & 0 deletions
14
src/main/java/org/prebid/server/proto/openrtb/ext/request/teqblaze/ExtImpTeqblaze.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.teqblaze; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import lombok.Value; | ||
|
|
||
| @Value(staticConstructor = "of") | ||
| public class ExtImpTeqblaze { | ||
|
|
||
| @JsonProperty("placementId") | ||
| String placementId; | ||
|
|
||
| @JsonProperty("endpointId") | ||
| String endpointId; | ||
| } |
39 changes: 39 additions & 0 deletions
39
src/main/java/org/prebid/server/spring/config/bidder/util/TeqblazeConfiguration.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,39 @@ | ||
| package org.prebid.server.spring.config.bidder.util; | ||
|
|
||
| import org.prebid.server.bidder.BidderDeps; | ||
| import org.prebid.server.bidder.teqblaze.TeqblazeBidder; | ||
| import org.prebid.server.json.JacksonMapper; | ||
| import org.prebid.server.spring.config.bidder.model.BidderConfigurationProperties; | ||
| 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/teqblaze.yaml", factory = YamlPropertySourceFactory.class) | ||
| public class TeqblazeConfiguration { | ||
|
|
||
| private static final String BIDDER_NAME = "teqblaze"; | ||
|
|
||
| @Bean("teqblazeConfigurationProperties") | ||
| @ConfigurationProperties("adapters.teqblaze") | ||
| BidderConfigurationProperties configurationProperties() { | ||
| return new BidderConfigurationProperties(); | ||
| } | ||
|
|
||
| @Bean | ||
| BidderDeps teqblazeBidderDeps(BidderConfigurationProperties teqblazeConfigurationProperties, | ||
| @NotBlank @Value("${external-url}") String externalUrl, | ||
| JacksonMapper mapper) { | ||
|
|
||
| return BidderDepsAssembler.forBidder(BIDDER_NAME) | ||
| .withConfig(teqblazeConfigurationProperties) | ||
| .usersyncerCreator(UsersyncerCreator.create(externalUrl)) | ||
| .bidderCreator(config -> new TeqblazeBidder(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,33 @@ | ||
| adapters: | ||
| teqblaze: | ||
przemkaczmarek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| endpoint: http:// | ||
| aliases: | ||
| pinkLion: | ||
| enabled: false | ||
| endpoint: https://us-east-ep.pinklion.io/pserver | ||
| meta-info: | ||
| maintainer-email: prebid@pinklion.io | ||
| rocketlab: | ||
| enabled: false | ||
| endpoint: https://traffic1.rocketlab.ai/pserver | ||
| meta-info: | ||
| maintainer-email: support@rocketlab.ai | ||
| usersync: | ||
| enabled: true | ||
| cookie-family-name: rocketlab | ||
| redirect: | ||
| url: https://usync.rocketlab.ai/pbserver?gdpr={{gdpr}}&consent={{gdpr_consent}}&us_privacy={{us_privacy}}&gpp={{gpp}}&gpp_sid={{gpp_sid}}&redirect={{redirect_url}} | ||
| support-cors: false | ||
| uid-macro: '[UID]' | ||
| meta-info: | ||
| maintainer-email: github@teqblaze.com | ||
| app-media-types: | ||
| - banner | ||
| - video | ||
| - native | ||
| site-media-types: | ||
| - banner | ||
| - video | ||
| - 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,30 @@ | ||
| { | ||
| "$schema": "http://json-schema.org/draft-04/schema#", | ||
| "title": "Teqblaze Adapter Params", | ||
| "description": "A schema which validates params accepted by the TeqBlaze adapter", | ||
| "type": "object", | ||
| "properties": { | ||
| "placementId": { | ||
| "type": "string", | ||
| "minLength": 1, | ||
| "description": "Placement ID" | ||
| }, | ||
| "endpointId": { | ||
| "type": "string", | ||
| "minLength": 1, | ||
| "description": "Endpoint ID" | ||
| } | ||
| }, | ||
| "oneOf": [ | ||
| { | ||
| "required": [ | ||
| "placementId" | ||
| ] | ||
| }, | ||
| { | ||
| "required": [ | ||
| "endpointId" | ||
| ] | ||
| } | ||
| ] | ||
| } |
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.