Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 146 additions & 0 deletions src/main/java/org/prebid/server/bidder/adplayx/AdplayxBidder.java
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<>() { };

Copy link
Copy Markdown
Collaborator

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


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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use BidderUtil.defaultRequest

} 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)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move Uri.of(...) creation to adapter constructor

.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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for this check. Inline responseBody


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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor this code to be similar to other adapters. See AxisBidder as an example

}
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();
}
}
16 changes: 16 additions & 0 deletions src/main/resources/bidder-config/adplayx.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
adapters:
adplayx:
enabled: true

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove enabled: true

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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
16 changes: 16 additions & 0 deletions src/main/resources/static/bidder-params/adplayx.json
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"]
}
Loading