-
Notifications
You must be signed in to change notification settings - Fork 252
[Bidder Adapter] Add AdPlayx adapter #4582
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
base: master
Are you sure you want to change the base?
Changes from all commits
df0677a
4b6de5d
87a6ff3
b4bf265
2f7088e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| package org.prebid.server.bidder.adplayx; | ||
|
|
||
| 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.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.JacksonMapper; | ||
| import org.prebid.server.proto.openrtb.ext.ExtPrebid; | ||
| import org.prebid.server.proto.openrtb.ext.request.adplayx.ExtImpAdplayx; | ||
| import org.prebid.server.proto.openrtb.ext.response.BidType; | ||
| import org.prebid.server.util.HttpUtil; | ||
| import org.prebid.server.util.Uri; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Objects; | ||
|
|
||
| public class AdplayxBidder implements Bidder<BidRequest> { | ||
|
|
||
| private static final TypeReference<ExtPrebid<?, ExtImpAdplayx>> ADPLAYX_EXT_TYPE_REFERENCE = | ||
| new TypeReference<>() { }; | ||
|
|
||
| private final String endpointUrl; | ||
| private final JacksonMapper mapper; | ||
|
|
||
| public AdplayxBidder(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 ExtImpAdplayx extImp = parseImpExt(imp); | ||
|
|
||
| if (StringUtils.isBlank(extImp.getApptoken())) { | ||
| errors.add(BidderError.badInput("apptoken is required")); | ||
| continue; | ||
| } | ||
|
|
||
| final String uri = buildEndpointUrl(extImp); | ||
|
|
||
| // Clone bid request for this impression | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove comment |
||
| final BidRequest outgoingRequest = request.toBuilder() | ||
| .imp(Collections.singletonList(imp)) | ||
| .build(); | ||
|
|
||
| httpRequests.add(HttpRequest.<BidRequest>builder() | ||
| .method(HttpMethod.POST) | ||
| .uri(uri) | ||
| .headers(HttpUtil.headers()) | ||
| .body(mapper.encodeToBytes(outgoingRequest)) | ||
| .payload(outgoingRequest) | ||
| .build()); | ||
|
Comment on lines
+64
to
+70
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
| } catch (PreBidException e) { | ||
| errors.add(BidderError.badInput(e.getMessage())); | ||
| } | ||
| } | ||
|
|
||
| return Result.of(httpRequests, errors); | ||
| } | ||
|
|
||
| private ExtImpAdplayx parseImpExt(Imp imp) { | ||
| try { | ||
| return mapper.mapper().convertValue(imp.getExt(), ADPLAYX_EXT_TYPE_REFERENCE).getBidder(); | ||
| } catch (IllegalArgumentException e) { | ||
| throw new PreBidException("Error parsing imp.ext: " + e.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| private String buildEndpointUrl(ExtImpAdplayx extImp) { | ||
| return Uri.of(endpointUrl) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move |
||
| .addQueryParam("apptoken", extImp.getApptoken()) | ||
| .addQueryParam("placementid", StringUtils.trimToNull(extImp.getPlacementid())) | ||
| .toString(); | ||
| } | ||
|
|
||
| @Override | ||
| public Result<List<BidderBid>> makeBids(BidderCall<BidRequest> httpCall, BidRequest bidRequest) { | ||
| final String responseBody = httpCall.getResponse().getBody(); | ||
| if (StringUtils.isBlank(responseBody)) { | ||
| return Result.empty(); | ||
| } | ||
|
Comment on lines
+97
to
+99
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for this check. Inline |
||
|
|
||
| try { | ||
| final BidResponse bidResponse = mapper.decodeValue(responseBody, BidResponse.class); | ||
| if (bidResponse == null || bidResponse.getSeatbid() == null) { | ||
| return Result.empty(); | ||
| } | ||
|
|
||
| final List<BidderError> errors = new ArrayList<>(); | ||
| final List<BidderBid> bidderBids = new ArrayList<>(); | ||
|
|
||
| for (final SeatBid seatBid : bidResponse.getSeatbid()) { | ||
| for (final Bid bid : seatBid.getBid()) { | ||
| try { | ||
| final BidType bidType = getBidType(bid.getImpid(), bidRequest.getImp()); | ||
| bidderBids.add(BidderBid.of(bid, bidType, bidResponse.getCur())); | ||
| } catch (final PreBidException e) { | ||
| errors.add(BidderError.badServerResponse(e.getMessage())); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return Result.of(bidderBids, errors); | ||
| } catch (final Exception e) { | ||
| return Result.withError(BidderError.badServerResponse("Failed to decode response: " + e.getMessage())); | ||
| } | ||
| } | ||
|
|
||
| private BidType getBidType(String impId, List<Imp> imps) { | ||
| for (Imp imp : imps) { | ||
| if (imp.getId().equals(impId)) { | ||
| if (imp.getBanner() != null) { | ||
| return BidType.banner; | ||
| } | ||
| if (imp.getVideo() != null) { | ||
| return BidType.video; | ||
| } | ||
| if (imp.getAudio() != null) { | ||
| return BidType.audio; | ||
| } | ||
| if (imp.getXNative() != null) { | ||
| return BidType.xNative; | ||
| } | ||
| } | ||
| } | ||
| throw new PreBidException("Failed to find impression with id: " + impId); | ||
| } | ||
|
Comment on lines
+101
to
+145
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Refactor this code to be similar to other adapters. See |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package org.prebid.server.proto.openrtb.ext.request.adplayx; | ||
|
|
||
| import lombok.Value; | ||
|
|
||
| @Value(staticConstructor = "of") | ||
| public class ExtImpAdplayx { | ||
|
|
||
| String apptoken; | ||
|
|
||
| String placementid; | ||
| } |
| 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.adplayx.AdplayxBidder; | ||
| 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/adplayx.yaml", factory = YamlPropertySourceFactory.class) | ||
| public class AdplayxConfiguration { | ||
|
|
||
| private static final String BIDDER_NAME = "adplayx"; | ||
|
|
||
| @Bean("adplayxConfigurationProperties") | ||
| @ConfigurationProperties("adapters.adplayx") | ||
| BidderConfigurationProperties configurationProperties() { | ||
| return new BidderConfigurationProperties(); | ||
| } | ||
|
|
||
| @Bean | ||
| BidderDeps adplayxBidderDeps(BidderConfigurationProperties adplayxConfigurationProperties, | ||
| JacksonMapper mapper) { | ||
|
|
||
| return BidderDepsAssembler.forBidder(BIDDER_NAME) | ||
| .withConfig(adplayxConfigurationProperties) | ||
| .bidderCreator(config -> new AdplayxBidder(config.getEndpoint(), mapper)) | ||
| .assemble(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| adapters: | ||
| adplayx: | ||
| enabled: true | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove |
||
| endpoint: "https://api.adplayx.net/v1.0/ortb" | ||
| pbs-enforces-ccpa: true | ||
| modifying-vast-xml-allowed: true | ||
| meta-info: | ||
| maintainer-email: "support@adplayx.com" | ||
| app-media-types: | ||
| - banner | ||
| - video | ||
| site-media-types: | ||
| - banner | ||
| - video | ||
|
Comment on lines
+9
to
+14
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see a discrepancy between the code (supports all media types) and the supported media types (banner + video). If it's intended - then ok |
||
| supported-vendors: [] | ||
| vendor-id: 0 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| { | ||
| "$schema": "http://json-schema.org/draft-04/schema#", | ||
| "title": "AdPlayx Adapter Params", | ||
| "type": "object", | ||
| "properties": { | ||
| "apptoken": { | ||
| "type": "string", | ||
| "description": "Publisher app token" | ||
| }, | ||
| "placementid": { | ||
| "type": "string", | ||
| "description": "Placement ID (optional)" | ||
| } | ||
| }, | ||
| "required": ["apptoken"] | ||
| } |
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.
Format
new TypeReference<>() { }according to project style