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
17 changes: 14 additions & 3 deletions src/main/java/org/prebid/server/bidder/mobkoi/MobkoiBidder.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
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.ExtRequest;
import org.prebid.server.proto.openrtb.ext.request.ExtUser;
import org.prebid.server.proto.openrtb.ext.request.mobkoi.ExtImpMobkoi;
import org.prebid.server.proto.openrtb.ext.response.BidType;
import org.prebid.server.bidder.mobkoi.proto.MobkoiBidRequestExt;
import org.prebid.server.util.BidderUtil;
import org.prebid.server.util.HttpUtil;

Expand All @@ -39,6 +41,9 @@ public class MobkoiBidder implements Bidder<BidRequest> {
new TypeReference<>() {
};

/**
* The integration endpoint that will be used to send the bid requests to. Managed by the adapter configuration.
*/
Comment on lines +44 to +46
Copy link
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 comment

private final String endpointUrl;
private final JacksonMapper mapper;

Expand All @@ -60,7 +65,7 @@ public Result<List<HttpRequest<BidRequest>>> makeHttpRequests(BidRequest bidRequ
return Result.withError(BidderError.badInput(e.getMessage()));
}

final String selectedEndpointUrl = resolveEndpoint(extImpMobkoi.getAdServerBaseUrl());
final String selectedEndpointUrl = resolveEndpoint(extImpMobkoi.getIntegrationEndpoint());

return Result.withValue(BidderUtil.defaultRequest(
modifyBidRequest(bidRequest, modifiedFirstImp),
Expand Down Expand Up @@ -104,10 +109,16 @@ private String resolveEndpoint(String customUri) {
}
}

private static BidRequest modifyBidRequest(BidRequest bidRequest, Imp modifiedFirstImp) {
private BidRequest modifyBidRequest(BidRequest bidRequest, Imp modifiedFirstImp) {
final User user = modifyUser(bidRequest.getUser());
final List<Imp> imps = updateFirstImpWith(bidRequest.getImp(), modifiedFirstImp);
return bidRequest.toBuilder().user(user).imp(imps).build();
final ExtRequest requestExt = modifyReqExt(bidRequest.getExt());
return bidRequest.toBuilder().user(user).imp(imps).ext(requestExt).build();
}

private ExtRequest modifyReqExt(ExtRequest existingRequestExt) {
final ExtRequest target = existingRequestExt != null ? existingRequestExt : ExtRequest.empty();
return mapper.fillExtension(target, MobkoiBidRequestExt.of());
}

private static User modifyUser(User user) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.prebid.server.bidder.mobkoi.proto;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Value;

@Value(staticConstructor = "of")
public class MobkoiBidRequestExt {

@JsonProperty("mobkoi")
Copy link
Collaborator

Choose a reason for hiding this comment

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

No need for JsonProperty here

final Mobkoi mobkoi;
Copy link
Collaborator

Choose a reason for hiding this comment

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

No need for final modifier, because you are using @Value


public static MobkoiBidRequestExt of() {
return new MobkoiBidRequestExt(Mobkoi.of());
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove this static constructor

@Value(staticConstructor = "of")
public class MobkoiBidRequestExt {

    Mobkoi mobkoi = Mobkoi.of();

    ...
}


@Value(staticConstructor = "of")
public static class Mobkoi {

@JsonProperty("integration_type")
Copy link
Collaborator

Choose a reason for hiding this comment

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

No need for @JsonProperty here, our object mapper defaults to snake_case

final String integrationType = "pbs";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ public class ExtImpMobkoi {
@JsonProperty("placementId")
String placementId;

@JsonProperty("adServerBaseUrl")
String adServerBaseUrl;
/**
* The integration endpoint that the bid requests will be sent to. For example, https://test.mobkoi.com/bid.
*/
Comment on lines +12 to +14
Copy link
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 comment

@JsonProperty("integrationEndpoint")
String integrationEndpoint;
}
4 changes: 2 additions & 2 deletions src/main/resources/static/bidder-params/mobkoi.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
},
"adServerBaseUrl": {
"type": "string",
"description": "Mobkoi's ad server url",
"pattern": "^https?://[^.]+\\.mobkoi\\.com$"
"description": "Mobkoi's integration endpoint that will be used to send the bid requests to. For example, https://test.mobkoi.com/bid.",
"pattern": "^https?://[^.]+\\.mobkoi\\.com(/.*)?$"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Rename adServerBaseUrl to integrationEndpoint

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,24 @@ public void makeHttpRequestsShouldOverrideUserExtAndSetConsent() {
assertThat(result.getErrors()).isEmpty();
}

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

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

// then
assertThat(result.getValue())
.extracting(httpRequest -> mapper.readValue(httpRequest.getBody(), BidRequest.class))
.extracting(request -> request.getExt())
.extracting(ext -> ext.getProperty("mobkoi"))
.extracting(mobkoi -> mobkoi.get("integration_type").asText())
.hasSize(1).element(0)
.isEqualTo("pbs");
}

@Test
public void makeBidsShouldReturnEmptyListIfBidResponseIsNull() throws JsonProcessingException {
// given
Expand Down Expand Up @@ -238,8 +256,13 @@ private static Imp givenImp(UnaryOperator<Imp.ImpBuilder> impCustomizer) {
return impCustomizer.apply(Imp.builder().id("imp_id").ext(impExt("placementIdValue", null))).build();
}

private static ObjectNode impExt(String placementId, String adServerBaseUrl) {
return mapper.valueToTree(ExtPrebid.of(null, ExtImpMobkoi.of(placementId, adServerBaseUrl)));
/**
* @param placementId The placement id provided by Mobkoi.
* @param integrationEndpoint The integration endpoint that will be used to send the bid requests to.
* @return The imp ext.
*/
Comment on lines +259 to +263
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove this comment

private static ObjectNode impExt(String placementId, String integrationEndpoint) {
return mapper.valueToTree(ExtPrebid.of(null, ExtImpMobkoi.of(placementId, integrationEndpoint)));
}

private static BidResponse givenBidResponse(UnaryOperator<Bid.BidBuilder> bidCustomizer) {
Expand Down