-
Notifications
You must be signed in to change notification settings - Fork 188
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
New Adapter: Adverxo #3677 #3705
base: master
Are you sure you want to change the base?
Conversation
Hi @AntoxaAntoxic, can You check my adapter because I have problem with AdverxoTest |
private String resolveEndpoint(ExtImpAdverxo extImpAdverxo) { | ||
final String adUnitAsString = Optional.of(extImpAdverxo.getAdUnitId()) | ||
.map(Object::toString) | ||
.orElse(StringUtils.EMPTY); | ||
final String authAsString = Optional.ofNullable(extImpAdverxo.getAuth()) | ||
.map(Object::toString) | ||
.orElse(StringUtils.EMPTY); | ||
|
||
return endpointUrl | ||
.replace(ADUNIT_MACROS_ENDPOINT, adUnitAsString) | ||
.replace(AUTH_MACROS_ENDPOINT, authAsString); | ||
} |
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.
HttpUtil.encodeUrl(StringUtils.defaultString(impExt.getEnv()))
private String resolveEndpoint(ExtImpAdverxo extImp) {
return endpointUrl
.replace(ADUNIT_MACROS_ENDPOINT, extImp.getAdUnitId() == null ? StringUtils.EMPTY : String.valueOf(extImp.getAdUnitId()))
.replace(AUTH_MACROS_ENDPOINT, HttpUtil.encodeUrl(StringUtils.defaultString(extImp.getAuth())));
}
public class ExtImpAdverxo { | ||
|
||
@JsonProperty("adUnitId") | ||
int adUnitId; |
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.
please use a non-primitive type
private Imp modifyImp(Imp imp, BidRequest request) { | ||
final BigDecimal bidFloor = imp.getBidfloor(); | ||
final String bidFloorCur = imp.getBidfloorcur(); | ||
|
||
if (bidFloor != null && bidFloor.compareTo(BigDecimal.ZERO) > 0 | ||
&& StringUtils.isNotBlank(bidFloorCur) | ||
&& !StringUtils.equalsIgnoreCase(bidFloorCur, DEFAULT_BID_CURRENCY)) { | ||
|
||
final BigDecimal convertedPrice = currencyConversionService.convertCurrency( | ||
bidFloor, | ||
request, | ||
bidFloorCur, | ||
DEFAULT_BID_CURRENCY | ||
); | ||
|
||
return imp.toBuilder() | ||
.bidfloor(convertedPrice) | ||
.bidfloorcur(DEFAULT_BID_CURRENCY) | ||
.build(); | ||
} | ||
return imp; | ||
} |
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.
private Imp modifyImp(BidRequest bidRequest, Imp imp) {
final Price resolvedBidFloor = resolveBidFloor(imp, bidRequest);
return imp.toBuilder()
.bidfloor(resolvedBidFloor.getValue())
.bidfloorcur(resolvedBidFloor.getCurrency())
.build();
}
private Price resolveBidFloor(Imp imp, BidRequest bidRequest) {
final Price initialBidFloorPrice = Price.of(imp.getBidfloorcur(), imp.getBidfloor());
return BidderUtil.shouldConvertBidFloor(initialBidFloorPrice, DEFAULT_BID_CURRENCY)
? convertBidFloor(initialBidFloorPrice, bidRequest)
: initialBidFloorPrice;
}
private Price convertBidFloor(Price bidFloorPrice, BidRequest bidRequest) {
final BigDecimal convertedPrice = currencyConversionService.convertCurrency(
bidFloorPrice.getValue(),
bidRequest,
bidFloorPrice.getCurrency(),
DEFAULT_BID_CURRENCY);
return Price.of(DEFAULT_BID_CURRENCY, convertedPrice);
}
return imp; | ||
} | ||
|
||
private BidRequest createRequest(BidRequest originalRequest, Imp modifiedImp) { |
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.
static
private HttpRequest<BidRequest> createHttpRequest(BidRequest outgoingRequest, | ||
String endpoint, | ||
String impId) { | ||
return HttpRequest.<BidRequest>builder() | ||
.method(HttpMethod.POST) | ||
.uri(endpoint) | ||
.headers(HttpUtil.headers()) | ||
.body(mapper.encodeToBytes(outgoingRequest)) | ||
.impIds(Collections.singleton(impId)) | ||
.payload(outgoingRequest) | ||
.build(); | ||
} |
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.
use BidderUtil.defaultRequest
instead
final Imp modifiedImp = modifyImp(imp, request); | ||
final BidRequest outgoingRequest = createRequest(request, modifiedImp); | ||
|
||
requests.add(createHttpRequest(outgoingRequest, endpoint, imp.getId())); |
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.
a request per imp case is not covered in unit tests
} | ||
|
||
@Test | ||
public void makeBidsShouldCorrectlyResolveBidTypes() throws JsonProcessingException { |
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.
split into 3 tests
.impid("123") | ||
.mtype(1) | ||
.adm("Price is ${AUCTION_PRICE}") | ||
.nurl("nurl?price=${AUCTION_PRICE}") |
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.
nurl is not changed in Go
@Test | ||
public void makeBidsShouldHandleNativeAdmParsing() throws JsonProcessingException { | ||
// Given | ||
final String adm = "{\"native\": {\"key\": \"value\"}}"; |
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.
cover the case when a native adm can't be parsed
.bid(List.of( | ||
Bid.builder().impid("123").mtype(1).adm("bannerAdm").build(), | ||
Bid.builder().impid("456").mtype(2).adm("videoAdm").build(), | ||
Bid.builder().impid("789").mtype(4).adm("{\"native\":{\"assets\":[]}}").build())) |
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.
cover the case when the returned mtype is not supported
🔧 Type of changes
✨ What's the context?
What's the context for the changes?
#3677 (comment)