Skip to content

Commit

Permalink
Consolidate Unruly Adapter: Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
marki1an committed Jan 6, 2022
1 parent 90baabe commit aaafe28
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 28 deletions.
11 changes: 7 additions & 4 deletions src/main/java/org/prebid/server/bidder/unruly/UnrulyBidder.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public Result<List<HttpRequest<BidRequest>>> makeHttpRequests(BidRequest request
}

final List<HttpRequest<BidRequest>> outgoingRequests = modifiedImps.stream()
.map(imp -> createSingleRequest(imp, request, endpointUrl))
.map(imp -> createSingleRequest(imp, request))
.collect(Collectors.toList());

return Result.of(outgoingRequests, errors);
Expand All @@ -85,8 +85,7 @@ private Imp modifyImp(Imp imp, ExtImpUnruly extImpUnruly) {
return modifiedImp.build();
}

private HttpRequest<BidRequest> createSingleRequest(Imp modifiedImp, BidRequest request,
String endpointUrl) {
private HttpRequest<BidRequest> createSingleRequest(Imp modifiedImp, BidRequest request) {
final BidRequest outgoingRequest = request.toBuilder().imp(Collections.singletonList(modifiedImp)).build();

return HttpRequest.<BidRequest>builder()
Expand Down Expand Up @@ -132,7 +131,11 @@ private static List<BidderBid> bidsFromResponse(BidRequest bidRequest, BidRespon
private static BidType getBidType(String impId, List<Imp> imps) {
for (Imp imp : imps) {
if (imp.getId().equals(impId)) {
return BidType.video;
if (imp.getBanner() != null) {
return BidType.banner;
} else if (imp.getVideo() != null) {
return BidType.video;
}
}
}
throw new PreBidException(String.format("Failed to find impression %s", impId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
@AllArgsConstructor(staticName = "of")
public class ExtImpUnruly {

String uuid;

@JsonProperty("siteid")
String siteId;
Integer siteId;
}
8 changes: 5 additions & 3 deletions src/main/resources/bidder-config/unruly.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
adapters:
unruly:
endpoint: http://targeting.unrulymedia.com/openrtb/2.2
endpoint: https://targeting.unrulymedia.com/unruly_prebid_server
meta-info:
maintainer-email: adspaces@unrulygroup.com
maintainer-email: prebidsupport@unrulygroup.com
app-media-types:
- banner
- video
site-media-types:
- banner
- video
supported-vendors:
vendor-id: 162
vendor-id: 36
usersync:
url: https://sync.1rx.io/usersync2/rmphb?gdpr={{gdpr}}&gdpr_consent={{gdpr_consent}}&us_privacy={{us_privacy}}&redir=
redirect-url: /setuid?bidder=unruly&gdpr={{gdpr}}&gdpr_consent={{gdpr_consent}}&us_privacy={{us_privacy}}&uid=[RX_UUID]
Expand Down
7 changes: 1 addition & 6 deletions src/main/resources/static/bidder-params/unruly.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,12 @@
"description": "A schema which validates params accepted by the Unruly adapter",
"type": "object",
"properties": {
"uuid": {
"type": "string",
"description": "uuid"
},
"siteid": {
"type": "string",
"type": "integer",
"description": "ID for publisher site"
}
},
"required": [
"uuid",
"siteid"
]
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.prebid.server.bidder.unruly;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.iab.openrtb.request.Banner;
import com.iab.openrtb.request.BidRequest;
import com.iab.openrtb.request.Imp;
import com.iab.openrtb.request.Video;
Expand Down Expand Up @@ -29,6 +30,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.tuple;
import static org.prebid.server.proto.openrtb.ext.response.BidType.banner;
import static org.prebid.server.proto.openrtb.ext.response.BidType.video;

public class UnrulyBidderTest extends VertxTest {
Expand Down Expand Up @@ -131,7 +133,7 @@ public void makeBidsShouldReturnVideoBid() throws JsonProcessingException {
// given
final HttpCall<BidRequest> httpCall = givenHttpCall(
BidRequest.builder()
.imp(singletonList(Imp.builder().id("123").build()))
.imp(singletonList(Imp.builder().video(Video.builder().build()).id("123").build()))
.build(),
mapper.writeValueAsString(
givenBidResponse(bidBuilder -> bidBuilder.impid("123"))));
Expand All @@ -145,6 +147,25 @@ public void makeBidsShouldReturnVideoBid() throws JsonProcessingException {
.containsOnly(BidderBid.of(Bid.builder().impid("123").build(), video, "USD"));
}

@Test
public void makeBidsShouldReturnBannerBid() throws JsonProcessingException {
// given
final HttpCall<BidRequest> httpCall = givenHttpCall(
BidRequest.builder()
.imp(singletonList(Imp.builder().banner(Banner.builder().build()).id("123").build()))
.build(),
mapper.writeValueAsString(
givenBidResponse(bidBuilder -> bidBuilder.impid("123"))));

// when
final Result<List<BidderBid>> result = unrulyBidder.makeBids(httpCall, null);

// then
assertThat(result.getErrors()).isEmpty();
assertThat(result.getValue())
.containsOnly(BidderBid.of(Bid.builder().impid("123").build(), banner, "USD"));
}

@Test
public void makeBidsShouldReturnErrorIfImpressionWasNotFound() throws JsonProcessingException {
// given
Expand All @@ -169,7 +190,7 @@ private static BidRequest givenBidRequest(
Function<Imp.ImpBuilder, Imp.ImpBuilder> impCustomizer) {

return bidRequestCustomizer.apply(BidRequest.builder()
.imp(singletonList(givenImp(impCustomizer))))
.imp(singletonList(givenImp(impCustomizer))))
.build();
}

Expand All @@ -179,9 +200,9 @@ private static BidRequest givenBidRequest(Function<Imp.ImpBuilder, Imp.ImpBuilde

private static Imp givenImp(Function<Imp.ImpBuilder, Imp.ImpBuilder> impCustomizer) {
return impCustomizer.apply(Imp.builder()
.id("123")
.video(Video.builder().build())
.ext(mapper.valueToTree(ExtPrebid.of(null, ExtImpUnruly.of("uuid", "site_id")))))
.id("123")
.video(Video.builder().build())
.ext(mapper.valueToTree(ExtPrebid.of(null, ExtImpUnruly.of(123)))))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
},
"ext": {
"unruly": {
"uuid": "uu_id_1",
"siteid": "site_id_1"
"siteid": 123
}
}
}
Expand All @@ -24,4 +23,4 @@
"gdpr": 0
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
},
"ext": {
"unruly": {
"uuid": "uu_id_1",
"siteid": "site_id_1"
"siteid": 123
}
}
}
Expand Down Expand Up @@ -42,4 +41,4 @@
"gdpr": 0
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@
"price": 1.25,
"crid": "crid",
"adm": "adm001",
"ext": {
"prebid": {
"type": "video"
}
},
"h": 600,
"w": 800
}
]
}
],
"bidid": "bid001"
}
}

0 comments on commit aaafe28

Please sign in to comment.