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 bidder bidmyadz #1352

Merged
merged 11 commits into from
Jul 7, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
120 changes: 120 additions & 0 deletions src/main/java/org/prebid/server/bidder/bidmyadz/BidmyadzBidder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package org.prebid.server.bidder.bidmyadz;

import com.iab.openrtb.request.BidRequest;
import com.iab.openrtb.request.Device;
import com.iab.openrtb.request.Imp;
import com.iab.openrtb.response.Bid;
import com.iab.openrtb.response.BidResponse;
import com.iab.openrtb.response.SeatBid;
import io.vertx.core.http.HttpMethod;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.prebid.server.bidder.Bidder;
import org.prebid.server.bidder.model.BidderBid;
import org.prebid.server.bidder.model.BidderError;
import org.prebid.server.bidder.model.HttpCall;
import org.prebid.server.bidder.model.HttpRequest;
import org.prebid.server.bidder.model.Result;
import org.prebid.server.exception.PreBidException;
import org.prebid.server.json.DecodeException;
import org.prebid.server.json.EncodeException;
import org.prebid.server.json.JacksonMapper;
import org.prebid.server.proto.openrtb.ext.response.BidType;
import org.prebid.server.util.HttpUtil;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

Copy link
Collaborator

@SerhiiNahornyi SerhiiNahornyi Jul 5, 2021

Choose a reason for hiding this comment

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

/**
 * BidMyAdz {@link Bidder} implementation.
 */

public class BidmyadzBidder implements Bidder<BidRequest> {

private final String endpointUrl;
private final JacksonMapper mapper;

public BidmyadzBidder(String endpointUrl, JacksonMapper mapper) {
this.endpointUrl = HttpUtil.validateUrl(Objects.requireNonNull(endpointUrl));
this.mapper = Objects.requireNonNull(mapper);
}

@Override
public Result<List<HttpRequest<BidRequest>>> makeHttpRequests(BidRequest request) {
final List<BidderError> errors = new ArrayList<>();
if (!isValidRequest(request, errors)) {
return Result.withErrors(errors);
}

try {
return Result.withValue(HttpRequest.<BidRequest>builder()
.method(HttpMethod.POST)
.uri(endpointUrl)
.headers(HttpUtil.headers().add(HttpUtil.X_OPENRTB_VERSION_HEADER, "2.5"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's add method createHeaders()

.payload(request)
.body(mapper.encode(request))
.build());
} catch (EncodeException e) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This try/catch can be omitted

return Result.withError(
BidderError.badInput(String.format("Failed to encode request body, error: %s", e.getMessage())));
}
}

private boolean isValidRequest(BidRequest request, List<BidderError> errors) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can be static
And actually we can a bit update this method, not to check device for null

  private static boolean isValidRequest(BidRequest request, List<BidderError> errors) {
        if (request.getImp().size() > 1) {
            errors.add(BidderError.badInput("Bidder does not support multi impression"));
        }

        final Device device = request.getDevice();
        final String ip = device != null ? device.getIp() : null;
        final String ipv6 = device != null ? device.getIpv6() : null;

        if (StringUtils.isEmpty(ip) && StringUtils.isEmpty(ipv6)) {
            errors.add(BidderError.badInput("IP/IPv6 is a required field"));
        }

        final String userAgent = device != null ? device.getUa() : null;

        if (StringUtils.isEmpty(userAgent)) {
            errors.add(BidderError.badInput("User-Agent is a required field"));
        }

        return errors.isEmpty();
    }

Then hasValidIp() method can be removed

if (request.getImp().size() > 1) {
errors.add(BidderError.badInput("Bidder does not support multi impression"));
}
final Device device = request.getDevice();
if (device == null || !hasValidIp(device)) {
errors.add(BidderError.badInput("IP/IPv6 is a required field"));
}

if (device == null || StringUtils.isEmpty(device.getUa())) {
errors.add(BidderError.badInput("User-Agent is a required field"));
}

return errors.isEmpty();
}

private boolean hasValidIp(Device device) {
return StringUtils.isNotEmpty(device.getIp()) || StringUtils.isNotEmpty(device.getIpv6());
}

@Override
public Result<List<BidderBid>> makeBids(HttpCall<BidRequest> httpCall, BidRequest bidRequest) {
try {
final BidResponse bidResponse = mapper.decodeValue(httpCall.getResponse().getBody(), BidResponse.class);
return Result.withValues(extractBids(httpCall.getRequest().getPayload(), bidResponse));
} catch (DecodeException | PreBidException e) {
return Result.withError(BidderError.badServerResponse(e.getMessage()));
}
}

private static List<BidderBid> extractBids(BidRequest bidRequest, BidResponse bidResponse) {
if (bidResponse == null || CollectionUtils.isEmpty(bidResponse.getSeatbid())) {
throw new PreBidException("Empty SeatBid");
SerhiiNahornyi marked this conversation as resolved.
Show resolved Hide resolved
}
return bidsFromResponse(bidRequest, bidResponse);
}

private static List<BidderBid> bidsFromResponse(BidRequest bidRequest, BidResponse bidResponse) {
final SeatBid seatBid = bidResponse.getSeatbid().get(0);
return seatBid.getBid().stream()
Copy link
Collaborator

Choose a reason for hiding this comment

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

From Go they also have error for empty bids

.map(bid -> BidderBid.of(bid, getBidType(bid, bidRequest.getImp()), bidResponse.getCur()))
.collect(Collectors.toList());
}

private static BidType getBidType(Bid bid, List<Imp> imps) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

From go, biotype is resolved from bidExt

final String impId = bid.getImpid();
for (Imp imp : imps) {
if (imp.getId().equals(impId)) {
if (imp.getBanner() != null) {
return BidType.banner;
} else if (imp.getVideo() != null) {
return BidType.video;
} else if (imp.getXNative() != null) {
return BidType.xNative;
}
}
}
throw new PreBidException(String.format("Failed to find impression %s", impId));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.prebid.server.proto.openrtb.ext.request.bidmyadz;

import lombok.AllArgsConstructor;
import lombok.Value;

@Value
@AllArgsConstructor(staticName = "of")
public class ExtImpBidmyadz {

String placementId;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems here @JsonProperty should be used

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.prebid.server.spring.config.bidder;

import org.prebid.server.bidder.BidderDeps;
import org.prebid.server.bidder.bidmyadz.BidmyadzBidder;
import org.prebid.server.json.JacksonMapper;
import org.prebid.server.spring.config.bidder.model.BidderConfigurationProperties;
import org.prebid.server.spring.config.bidder.util.BidderDepsAssembler;
import org.prebid.server.spring.config.bidder.util.UsersyncerCreator;
import org.prebid.server.spring.env.YamlPropertySourceFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import javax.validation.constraints.NotBlank;

@Configuration
@PropertySource(value = "classpath:/bidder-config/bidmyadz.yaml", factory = YamlPropertySourceFactory.class)
public class BidmyadzConfiguration {

private static final String BIDDER_NAME = "bidmyadz";

@Value("${external-url}")
@NotBlank
private String externalUrl;

@Autowired
private JacksonMapper mapper;

@Autowired
@Qualifier("bidmyadzConfigurationProperties")
private BidderConfigurationProperties configProperties;

@Bean("bidmyadzConfigurationProperties")
@ConfigurationProperties("adapters.bidmyadz")
BidderConfigurationProperties configurationProperties() {
return new BidderConfigurationProperties();
}

@Bean
BidderDeps bidmyadzBidderDeps() {
return BidderDepsAssembler.forBidder(BIDDER_NAME)
.withConfig(configProperties)
.usersyncerCreator(UsersyncerCreator.create(externalUrl))
.bidderCreator(config -> new BidmyadzBidder(config.getEndpoint(), mapper))
.assemble();
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Redundant \n

}
27 changes: 27 additions & 0 deletions src/main/resources/bidder-config/bidmyadz.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
adapters:
bidmyadz:
enabled: false
endpoint: http://endpoint.bidmyadz.com/c0f68227d14ed938c6c49f3967cbe9bc
pbs-enforces-gdpr: true
pbs-enforces-ccpa: true
modifying-vast-xml-allowed: true
deprecated-names:
aliases: {}
meta-info:
maintainer-email: contact@bidmyadz.com
app-media-types:
- banner
- video
- native
site-media-types:
- banner
- video
- native
supported-vendors:
vendor-id: 724
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is between vendor id. BidMyAdz id is not present in go PR, and also 79.json does not contain it, so set it as zero,
Also pls fix it for bidmachine which id is 736

usersync:
url: https://cookie-sync.bidmyadz.com/c0f68227d14ed938c6c49f3967cbe9bc?gdpr={{.GDPR}}&gdpr_consent={{.GDPRConsent}}&ccpa={{.USPrivacy}}&red="+url.QueryEscape(externalURL)+"%2Fsetuid%3Fbidder%3Dbidmyadz%26uid%3D%5BUID%5D%26us_privacy%3D{{.USPrivacy}}%26gdpr_consent%3D{{.GDPRConsent}}%26gdpr%3D{{.GDPR}}
redirect-url:
cookie-family-name: bidmyadz
type: redirect
support-cors: false
12 changes: 12 additions & 0 deletions src/main/resources/static/bidder-params/bidmyadz.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "BidMyAdz Adapter Params",
"description": "A schema which validates params accepted by the BidMyAdz adapter",
"type": "object",
"properties": {
"placementId": {
"type": "string"
}
},
"required": ["placementId"]
}
Loading