Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import com.iab.openrtb.response.Bid;
import com.iab.openrtb.response.BidResponse;
import com.iab.openrtb.response.SeatBid;
import io.vertx.core.MultiMap;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.prebid.server.bidder.Bidder;
import org.prebid.server.bidder.model.BidderBid;
Expand Down Expand Up @@ -42,11 +42,6 @@ public class TheTradeDeskBidder implements Bidder<BidRequest> {
new TypeReference<>() {
};

private static final String PREBID_INTEGRATION_TYPE_HEADER = "x-integration-type";
private static final String PREBID_INTEGRATION_TYPE = "1";
private static final MultiMap HEADERS = HttpUtil.headers()
.add(PREBID_INTEGRATION_TYPE_HEADER, PREBID_INTEGRATION_TYPE);

private static final String SUPPLY_ID_MACRO = "{{SupplyId}}";
private static final Pattern SUPPLY_ID_PATTERN = Pattern.compile("([a-z]+)$");

Expand All @@ -73,6 +68,7 @@ public Result<List<HttpRequest<BidRequest>>> makeHttpRequests(BidRequest request
final List<Imp> modifiedImps = new ArrayList<>();

String publisherId = null;
String sourceSupplyId = null;
for (Imp imp : request.getImp()) {
try {
final ExtImpTheTradeDesk extImp = parseImpExt(imp);
Expand All @@ -82,6 +78,11 @@ public Result<List<HttpRequest<BidRequest>>> makeHttpRequests(BidRequest request
? extImpPublisherId
: publisherId;

final String extImpSourceSupplyId = extImp.getSupplySourceId();
sourceSupplyId = sourceSupplyId == null && StringUtils.isNotBlank(extImpSourceSupplyId)
? extImpSourceSupplyId
: sourceSupplyId;

modifiedImps.add(modifyImp(imp));
} catch (PreBidException e) {
return Result.withError(BidderError.badInput(e.getMessage()));
Expand All @@ -91,8 +92,7 @@ public Result<List<HttpRequest<BidRequest>>> makeHttpRequests(BidRequest request
final BidRequest outgoingRequest = modifyRequest(request, modifiedImps, publisherId);
final HttpRequest<BidRequest> httpRequest = BidderUtil.defaultRequest(
outgoingRequest,
HEADERS,
resolveEndpoint(),
resolveEndpoint(sourceSupplyId),
mapper);

return Result.withValue(httpRequest);
Expand Down Expand Up @@ -165,8 +165,10 @@ private static App modifyApp(BidRequest request, String publisherId) {
.build();
}

private String resolveEndpoint() {
return endpointUrl.replace(SUPPLY_ID_MACRO, HttpUtil.encodeUrl(StringUtils.defaultString(supplyId)));
private String resolveEndpoint(String sourceSupplyId) {
return endpointUrl.replace(
SUPPLY_ID_MACRO,
HttpUtil.encodeUrl(StringUtils.defaultString(ObjectUtils.defaultIfNull(sourceSupplyId, supplyId))));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ public class ExtImpTheTradeDesk {

@JsonProperty("publisherId")
String publisherId;

@JsonProperty("supplySourceId")
String supplySourceId;
}
10 changes: 7 additions & 3 deletions src/main/resources/static/bidder-params/thetradedesk.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
"properties": {
"publisherId": {
"type": "string",
"minLength": 1,
"description": "An ID which identifies the publisher"
},
"supplySourceId": {
"type":"string",
"minLength": 1,
"description": "An ID provided by TheTradeDesk used to determine which endpoint to use"
}
},
"required": [
"publisherId"
]
"required": ["publisherId"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,12 @@ public void makeHttpRequestsShouldReturnExpectedHeaders() {
.satisfies(headers -> assertThat(headers.get(CONTENT_TYPE_HEADER))
.isEqualTo(APPLICATION_JSON_CONTENT_TYPE))
.satisfies(headers -> assertThat(headers.get(ACCEPT_HEADER))
.isEqualTo(APPLICATION_JSON_VALUE))
.satisfies(headers -> assertThat(headers.get("x-integration-type"))
.isEqualTo("1"));
.isEqualTo(APPLICATION_JSON_VALUE));
assertThat(result.getErrors()).isEmpty();
}

@Test
public void makeHttpRequestsShouldUseCorrectUri() {
public void makeHttpRequestsShouldUseConfiguredSupplyIdWhenImpExtSupplyIdIsNotProvided() {
// given
final BidRequest bidRequest = givenBidRequest(identity(), identity());

Expand All @@ -116,6 +114,42 @@ public void makeHttpRequestsShouldUseCorrectUri() {
.containsExactly("https://test.endpoint.com/supplyid");
}

@Test
public void makeHttpRequestsShouldUseImpExtSupplyIdWhenProvided() {
// given
final BidRequest bidRequest = givenBidRequest(
identity(),
imp -> imp.ext(impExt("publisher", "supplySourceId")));

// when
final Result<List<HttpRequest<BidRequest>>> result = target.makeHttpRequests(bidRequest);

// then
assertThat(result.getErrors()).isEmpty();
assertThat(result.getValue())
.extracting(HttpRequest::getUri)
.containsExactly("https://test.endpoint.com/supplySourceId");
}

@Test
public void makeHttpRequestsShouldUseFirstFoundSupplySourceId() {
// given
final BidRequest bidRequest = givenBidRequest(
identity(),
imp -> imp.ext(impExt("publisher", null)),
imp -> imp.ext(impExt("publisher", "supplySourceId1")),
imp -> imp.ext(impExt("publisher", "supplySourceId2")));

// when
final Result<List<HttpRequest<BidRequest>>> result = target.makeHttpRequests(bidRequest);

// then
assertThat(result.getErrors()).isEmpty();
assertThat(result.getValue())
.extracting(HttpRequest::getUri)
.containsExactly("https://test.endpoint.com/supplySourceId1");
}

@Test
public void makeHttpRequestsShouldHaveImpIds() {
// given
Expand Down Expand Up @@ -259,7 +293,7 @@ public void makeHttpRequestsShouldReturnAppWithExtImpPublisherWhenAppWithoutPubl
}

@Test
public void makeHttpRequestsShouldReturnAppWithPublisherOfTheFirsrExtImp() {
public void makeHttpRequestsShouldReturnAppWithPublisherOfTheFirstExtImp() {
final BidRequest bidRequest = givenBidRequest(
request -> request.app(App.builder().build()),
imp -> imp.ext(impExt("newPublisher")),
Expand Down Expand Up @@ -453,7 +487,11 @@ private static Imp givenImp(UnaryOperator<Imp.ImpBuilder> impCustomizer) {
}

private static ObjectNode impExt(String publisherId) {
return mapper.valueToTree(ExtPrebid.of(null, ExtImpTheTradeDesk.of(publisherId)));
return impExt(publisherId, null);
}

private static ObjectNode impExt(String publisherId, String supplySourceId) {
return mapper.valueToTree(ExtPrebid.of(null, ExtImpTheTradeDesk.of(publisherId, supplySourceId)));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
},
"ext": {
"thetradedesk": {
"publisherId": "publisherId"
"publisherId": "publisherId",
"supplySourceId": "somesupplyid"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"ext": {
"tid": "${json-unit.any-string}",
"bidder": {
"publisherId": "publisherId"
"publisherId": "publisherId",
"supplySourceId": "somesupplyid"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,6 @@ adapters.tradplus.enabled=true
adapters.tradplus.endpoint=http://{{ZoneID}}localhost:8090/{{AccountID}}/tradplus-exchange
adapters.thetradedesk.enabled=true
adapters.thetradedesk.endpoint=http://localhost:8090/thetradedesk-exchange/{{SupplyId}}
adapters.thetradedesk.extra-info.supply-id=somesupplyid
adapters.triplelift.enabled=true
adapters.triplelift.endpoint=http://localhost:8090/triplelift-exchange
adapters.tripleliftnative.enabled=true
Expand Down
Loading