Skip to content

Commit

Permalink
Merge pull request #1 from 33Across/XCH-2497_compatibility
Browse files Browse the repository at this point in the history
Rename Bidder from 'ttx' to 'thirtythreeacross'
  • Loading branch information
curlyblueeagle authored Jan 3, 2022
2 parents 4242290 + 80297ae commit a51d0cf
Show file tree
Hide file tree
Showing 21 changed files with 168 additions and 88 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.prebid.server.bidder.ttx;
package org.prebid.server.bidder.thirtythreeacross;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
Expand All @@ -18,15 +18,19 @@
import org.prebid.server.bidder.model.HttpCall;
import org.prebid.server.bidder.model.HttpRequest;
import org.prebid.server.bidder.model.Result;
import org.prebid.server.bidder.ttx.proto.TtxImpExt;
import org.prebid.server.bidder.ttx.proto.TtxImpExtTtx;
import org.prebid.server.bidder.ttx.response.TtxBidExt;
import org.prebid.server.bidder.ttx.response.TtxBidExtTtx;
import org.prebid.server.bidder.thirtythreeacross.proto.ThirtyThreeAcrossCaller;
import org.prebid.server.bidder.thirtythreeacross.proto.ThirtyThreeAcrossImpExt;
import org.prebid.server.bidder.thirtythreeacross.proto.ThirtyThreeAcrossImpExtTtx;
import org.prebid.server.bidder.thirtythreeacross.proto.ThirtyThreeAcrossReqExt;
import org.prebid.server.bidder.thirtythreeacross.proto.ThirtyThreeAcrossReqExtTtx;
import org.prebid.server.bidder.thirtythreeacross.response.ThirtyThreeAcrossBidExt;
import org.prebid.server.bidder.thirtythreeacross.response.ThirtyThreeAcrossBidExtTtx;
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.ttx.ExtImpTtx;
import org.prebid.server.proto.openrtb.ext.request.ExtRequest;
import org.prebid.server.proto.openrtb.ext.request.thirtythreeacross.ExtImpThirtyThreeAcross;
import org.prebid.server.proto.openrtb.ext.response.BidType;
import org.prebid.server.util.HttpUtil;

Expand All @@ -39,16 +43,16 @@
import java.util.Objects;
import java.util.stream.Collectors;

public class TtxBidder implements Bidder<BidRequest> {
public class ThirtyThreeAcrossBidder implements Bidder<BidRequest> {

private static final TypeReference<ExtPrebid<?, ExtImpTtx>> TTX_EXT_TYPE_REFERENCE =
new TypeReference<ExtPrebid<?, ExtImpTtx>>() {
private static final TypeReference<ExtPrebid<?, ExtImpThirtyThreeAcross>> TTX_EXT_TYPE_REFERENCE =
new TypeReference<ExtPrebid<?, ExtImpThirtyThreeAcross>>() {
};

private final String endpointUrl;
private final JacksonMapper mapper;

public TtxBidder(String endpointUrl, JacksonMapper mapper) {
public ThirtyThreeAcrossBidder(String endpointUrl, JacksonMapper mapper) {
this.endpointUrl = HttpUtil.validateUrl(Objects.requireNonNull(endpointUrl));
this.mapper = Objects.requireNonNull(mapper);
}
Expand All @@ -62,7 +66,7 @@ public Result<List<HttpRequest<BidRequest>>> makeHttpRequests(BidRequest request
for (Imp imp : request.getImp()) {
try {
validateImp(imp);
final ExtImpTtx extImpTtx = parseImpExt(imp);
final ExtImpThirtyThreeAcross extImpTtx = parseImpExt(imp);
final Imp updatedImp = updateImp(imp, extImpTtx);
impsMap.computeIfAbsent(computeKey(updatedImp), k -> new ArrayList<>()).add(updatedImp);
} catch (PreBidException e) {
Expand All @@ -84,15 +88,15 @@ private void validateImp(Imp imp) throws PreBidException {
}
}

private ExtImpTtx parseImpExt(Imp imp) throws PreBidException {
private ExtImpThirtyThreeAcross parseImpExt(Imp imp) throws PreBidException {
try {
return mapper.mapper().convertValue(imp.getExt(), TTX_EXT_TYPE_REFERENCE).getBidder();
} catch (IllegalArgumentException e) {
throw new PreBidException(e.getMessage());
}
}

private Imp updateImp(Imp imp, ExtImpTtx extImpTtx) throws PreBidException {
private Imp updateImp(Imp imp, ExtImpThirtyThreeAcross extImpTtx) throws PreBidException {
final String productId = extImpTtx.getProductId();
return imp.toBuilder()
.video(updatedVideo(imp.getVideo(), productId))
Expand Down Expand Up @@ -144,14 +148,29 @@ private static Integer resolvePlacement(Integer videoPlacement, String productId
}

private ObjectNode createImpExt(String productId, String zoneId, String siteId) {
final TtxImpExt ttxImpExt = TtxImpExt.of(
TtxImpExtTtx.of(productId, StringUtils.isNotEmpty(zoneId) ? zoneId : siteId));
final ThirtyThreeAcrossImpExt ttxImpExt = ThirtyThreeAcrossImpExt.of(
ThirtyThreeAcrossImpExtTtx.of(productId, StringUtils.isNotEmpty(zoneId) ? zoneId : siteId));
return mapper.mapper().valueToTree(ttxImpExt);
}

private ExtRequest createReqExt() {
final List<ThirtyThreeAcrossCaller> ttxCaller = new ArrayList<>();
ttxCaller.add(ThirtyThreeAcrossCaller.of());

final ExtRequest ttxReqExt = mapper.fillExtension(
ExtRequest.empty(),
ThirtyThreeAcrossReqExt.of(
ThirtyThreeAcrossReqExtTtx.of(ttxCaller)
)
);

return ttxReqExt;
}

private HttpRequest<BidRequest> createRequest(BidRequest request, List<Imp> requestImps) {
final BidRequest modifiedRequest = request.toBuilder()
.imp(requestImps)
.ext(createReqExt())
.build();

return HttpRequest.<BidRequest>builder()
Expand Down Expand Up @@ -190,17 +209,17 @@ private List<BidderBid> bidsFromResponse(BidResponse bidResponse) {
.collect(Collectors.toList());
}

private BidType getBidType(Bid
bid) {
private BidType getBidType(Bid bid) {
try {
final TtxBidExt ttxBidExt = mapper.mapper().convertValue(bid.getExt(), TtxBidExt.class);
final ThirtyThreeAcrossBidExt ttxBidExt =
mapper.mapper().convertValue(bid.getExt(), ThirtyThreeAcrossBidExt.class);
return ttxBidExt != null ? getBidTypeByTtx(ttxBidExt.getTtx()) : BidType.banner;
} catch (IllegalArgumentException e) {
return BidType.banner;
}
}

private static BidType getBidTypeByTtx(TtxBidExtTtx bidExt) {
private static BidType getBidTypeByTtx(ThirtyThreeAcrossBidExtTtx bidExt) {
return bidExt != null && Objects.equals(bidExt.getMediaType(), "video")
? BidType.video
: BidType.banner;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.prebid.server.bidder.thirtythreeacross.proto;

import lombok.NoArgsConstructor;
import lombok.Value;

@NoArgsConstructor(staticName = "of")
@Value
public class ThirtyThreeAcrossCaller {

final String name = "Prebid-Server-Java";
final String version = "N/A";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.prebid.server.bidder.thirtythreeacross.proto;

import lombok.AllArgsConstructor;
import lombok.Value;

@AllArgsConstructor(staticName = "of")
@Value
public class ThirtyThreeAcrossImpExt {

ThirtyThreeAcrossImpExtTtx ttx;
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.prebid.server.bidder.ttx.proto;
package org.prebid.server.bidder.thirtythreeacross.proto;

import lombok.AllArgsConstructor;
import lombok.Value;

@AllArgsConstructor(staticName = "of")
@Value
public class TtxImpExtTtx {
public class ThirtyThreeAcrossImpExtTtx {

String prod;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.prebid.server.bidder.thirtythreeacross.proto;

import lombok.AllArgsConstructor;
import lombok.Value;

@AllArgsConstructor(staticName = "of")
@Value
public class ThirtyThreeAcrossReqExt {

ThirtyThreeAcrossReqExtTtx ttx;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.prebid.server.bidder.thirtythreeacross.proto;

import lombok.AllArgsConstructor;
import lombok.Value;

import java.util.List;

@AllArgsConstructor(staticName = "of")
@Value
public class ThirtyThreeAcrossReqExtTtx {

List<ThirtyThreeAcrossCaller> caller;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.prebid.server.bidder.thirtythreeacross.response;

import lombok.AllArgsConstructor;
import lombok.Value;

@AllArgsConstructor(staticName = "of")
@Value
public class ThirtyThreeAcrossBidExt {

ThirtyThreeAcrossBidExtTtx ttx;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.prebid.server.bidder.ttx.response;
package org.prebid.server.bidder.thirtythreeacross.response;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
Expand All @@ -7,7 +7,7 @@

@AllArgsConstructor(staticName = "of")
@Value
public class TtxBidExtTtx {
public class ThirtyThreeAcrossBidExtTtx {

@JsonProperty("mediaType")
@JsonInclude(JsonInclude.Include.NON_EMPTY)
Expand Down
11 changes: 0 additions & 11 deletions src/main/java/org/prebid/server/bidder/ttx/proto/TtxImpExt.java

This file was deleted.

11 changes: 0 additions & 11 deletions src/main/java/org/prebid/server/bidder/ttx/response/TtxBidExt.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.prebid.server.proto.openrtb.ext.request.ttx;
package org.prebid.server.proto.openrtb.ext.request.thirtythreeacross;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
Expand All @@ -9,7 +9,7 @@
*/
@AllArgsConstructor(staticName = "of")
@Value
public class ExtImpTtx {
public class ExtImpThirtyThreeAcross {

@JsonProperty("siteId")
String siteId;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.prebid.server.spring.config.bidder;

import org.prebid.server.bidder.BidderDeps;
import org.prebid.server.bidder.ttx.TtxBidder;
import org.prebid.server.bidder.thirtythreeacross.ThirtyThreeAcrossBidder;
import org.prebid.server.json.JacksonMapper;
import org.prebid.server.spring.config.bidder.model.BidderConfigurationProperties;
import org.prebid.server.spring.config.bidder.util.BidderDepsAssembler;
Expand All @@ -16,26 +16,26 @@
import javax.validation.constraints.NotBlank;

@Configuration
@PropertySource(value = "classpath:/bidder-config/ttx.yaml", factory = YamlPropertySourceFactory.class)
public class TtxConfiguration {
@PropertySource(value = "classpath:/bidder-config/thirtythreeacross.yaml", factory = YamlPropertySourceFactory.class)
public class ThirtyThreeAcrossConfiguration {

private static final String BIDDER_NAME = "ttx";
private static final String BIDDER_NAME = "thirtythreeacross";

@Bean("ttxConfigurationProperties")
@ConfigurationProperties("adapters.ttx")
@Bean("thirtythreeacrossConfigurationProperties")
@ConfigurationProperties("adapters.thirtythreeacross")
BidderConfigurationProperties configurationProperties() {
return new BidderConfigurationProperties();
}

@Bean
BidderDeps ttxBidderDeps(BidderConfigurationProperties ttxConfigurationProperties,
BidderDeps thirtythreeacrossBidderDeps(BidderConfigurationProperties thirtythreeacrossConfigurationProperties,
@NotBlank @Value("${external-url}") String externalUrl,
JacksonMapper mapper) {

return BidderDepsAssembler.forBidder(BIDDER_NAME)
.withConfig(ttxConfigurationProperties)
.withConfig(thirtythreeacrossConfigurationProperties)
.usersyncerCreator(UsersyncerCreator.create(externalUrl))
.bidderCreator(config -> new TtxBidder(config.getEndpoint(), mapper))
.bidderCreator(config -> new ThirtyThreeAcrossBidder(config.getEndpoint(), mapper))
.assemble();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
adapters:
ttx:
thirtythreeacross:
endpoint: https://ssc.33across.com/api/v1/s2s
aliases:
'33across':
Expand Down
Loading

0 comments on commit a51d0cf

Please sign in to comment.