Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

przemkaczmarek
Copy link
Collaborator

@przemkaczmarek przemkaczmarek commented Jan 27, 2025

🔧 Type of changes

  • new bid adapter

✨ What's the context?

What's the context for the changes?
#3677 (comment)

@przemkaczmarek
Copy link
Collaborator Author

Hi @AntoxaAntoxic, can You check my adapter because I have problem with AdverxoTest

@przemkaczmarek przemkaczmarek changed the title AdverxoTest does not work New Adapter: Adverxo #3677 Jan 28, 2025
Comment on lines +87 to +98
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);
}
Copy link
Collaborator

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;
Copy link
Collaborator

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

Comment on lines +100 to +121
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;
}
Copy link
Collaborator

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) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

static

Comment on lines +129 to +140
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();
}
Copy link
Collaborator

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()));
Copy link
Collaborator

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 {
Copy link
Collaborator

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}")
Copy link
Collaborator

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\"}}";
Copy link
Collaborator

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()))
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants