Skip to content

Commit

Permalink
Fixes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
Serhii Nahornyi committed Nov 10, 2020
1 parent 29fd7fb commit b016319
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions src/main/java/org/prebid/server/bidder/yieldlab/YieldlabBidder.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.iab.openrtb.request.Site;
import com.iab.openrtb.request.User;
import com.iab.openrtb.response.Bid;
import io.netty.handler.codec.http.HttpHeaderValues;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.vertx.core.MultiMap;
import io.vertx.core.http.HttpMethod;
Expand Down Expand Up @@ -137,18 +138,18 @@ private String makeUrl(ExtImpYieldlab extImpYieldlab, BidRequest request) {

final Device device = request.getDevice();
if (device != null) {
uriBuilder.addParameter("yl_rtb_ifa", device.getIfa())
.addParameter("yl_rtb_devicetype", device.getDevicetype().toString());
uriBuilder.addParameter("yl_rtb_ifa", device.getIfa());

uriBuilder.addParameter("yl_rtb_devicetype", resolveNumberParameter(device.getDevicetype()));
final Integer connectionType = device.getConnectiontype();
if (connectionType != null) {
uriBuilder.addParameter("yl_rtb_connectiontype", connectionType.toString());
uriBuilder.addParameter("yl_rtb_connectiontype", device.getConnectiontype().toString());
}

final Geo geo = device.getGeo();
if (geo != null) {
uriBuilder.addParameter("lat", geo.getLat().toString())
.addParameter("lon", geo.getLon().toString());
uriBuilder.addParameter("lat", resolveNumberParameter(geo.getLat()));
uriBuilder.addParameter("lon", resolveNumberParameter(geo.getLon()));
}
}

Expand Down Expand Up @@ -209,30 +210,24 @@ private static String getConsentParameter(User user) {

private static MultiMap resolveHeaders(Site site, Device device, User user) {
final MultiMap headers = MultiMap.caseInsensitiveMultiMap()
.add("Accept", "application/json");
.add(HttpUtil.ACCEPT_HEADER, HttpHeaderValues.APPLICATION_JSON);

if (site != null) {
addHeader(headers, "Referer", site.getPage());
HttpUtil.addHeaderIfValueIsNotEmpty(headers, HttpUtil.REFERER_HEADER.toString(), site.getPage());
}

if (device != null) {
addHeader(headers, "User-Agent", device.getUa());
addHeader(headers, "X-Forwarded-For", device.getIp());
HttpUtil.addHeaderIfValueIsNotEmpty(headers, HttpUtil.USER_AGENT_HEADER.toString(), device.getUa());
HttpUtil.addHeaderIfValueIsNotEmpty(headers, HttpUtil.X_FORWARDED_FOR_HEADER.toString(), device.getIp());
}

if (user != null && StringUtils.isNotBlank(user.getBuyeruid())) {
headers.add("Cookie", String.format("id=%s", user.getBuyeruid()));
headers.add(HttpUtil.COOKIE_HEADER.toString(), String.format("id=%s", user.getBuyeruid()));
}

return headers;
}

private static void addHeader(MultiMap headers, String header, String value) {
if (StringUtils.isNotBlank(value)) {
headers.add(header, value);
}
}

@Override
public Result<List<BidderBid>> makeBids(HttpCall<Void> httpCall, BidRequest bidRequest) {
final int statusCode = httpCall.getResponse().getStatusCode();
Expand Down Expand Up @@ -271,7 +266,11 @@ private BidderBid resolveBidderBid(List<YieldlabResponse> yieldlabResponses,
if (matchedExtImp == null) {
throw new PreBidException("Invalid extension");
}

final Imp currentImp = bidRequest.getImp().get(currentImpIndex);
if (currentImp == null) {
throw new PreBidException(String.format("Imp not present for id %s", currentImpIndex));
}
final Bid.BidBuilder updatedBid = Bid.builder();

BidType bidType;
Expand Down Expand Up @@ -312,9 +311,13 @@ private Bid.BidBuilder addBidParams(YieldlabResponse yieldlabResponse, BidReques
Bid.BidBuilder updatedBid) {
final ExtImpYieldlab matchedExtImp = getMatchedExtImp(yieldlabResponse.getId(), bidRequest.getImp());

updatedBid.id(String.valueOf(yieldlabResponse.getId()))
if (matchedExtImp == null) {
throw new PreBidException("Invalid extension");
}

updatedBid.id(resolveNumberParameter(yieldlabResponse.getId()))
.price(resolvePrice(yieldlabResponse.getPrice()))
.dealid(String.valueOf(yieldlabResponse.getPid()))
.dealid(resolveNumberParameter(yieldlabResponse.getPid()))
.crid(makeCreativeId(bidRequest, yieldlabResponse, matchedExtImp))
.w(resolveSizeParameter(yieldlabResponse.getAdSize(), true))
.h(resolveSizeParameter(yieldlabResponse.getAdSize(), false));
Expand All @@ -326,6 +329,10 @@ private static BigDecimal resolvePrice(Double price) {
return price != null ? BigDecimal.valueOf(price / 100) : null;
}

private static String resolveNumberParameter(Number param) {
return param != null ? String.valueOf(param) : null;
}

private static String makeCreativeId(BidRequest bidRequest, YieldlabResponse yieldlabResponse,
ExtImpYieldlab extImp) {
// for passing validation tests
Expand Down

0 comments on commit b016319

Please sign in to comment.