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 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
118 changes: 118 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,118 @@
package org.prebid.server.bidder.bidmyadz;

import com.fasterxml.jackson.databind.JsonNode;
import com.iab.openrtb.request.BidRequest;
import com.iab.openrtb.request.Device;
import com.iab.openrtb.response.Bid;
import com.iab.openrtb.response.BidResponse;
import io.vertx.core.MultiMap;
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.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;

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.
 */

/**
* 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);
}

return Result.withValue(HttpRequest.<BidRequest>builder()
.method(HttpMethod.POST)
.uri(endpointUrl)
.headers(createHeaders())
.payload(request)
.body(mapper.encode(request))
.build());
}

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();
}

private static MultiMap createHeaders() {
return HttpUtil.headers().add(HttpUtil.X_OPENRTB_VERSION_HEADER, "2.5");
}

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

private BidderBid extractBids(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(bidResponse);
}

private BidderBid bidsFromResponse(BidResponse bidResponse) {
final List<Bid> bids = bidResponse.getSeatbid().get(0).getBid();

if (CollectionUtils.isEmpty(bids)) {
throw new PreBidException("Empty SeatBid.Bids");
}

final Bid bid = bids.get(0);
return BidderBid.of(bid, getBidType(bid.getExt()), bidResponse.getCur());
}

private static BidType getBidType(JsonNode ext) {
final JsonNode mediaTypeNode = ext != null ? ext.get("mediaType") : null;
final String mediaType = mediaTypeNode != null && mediaTypeNode.isTextual() ? mediaTypeNode.asText() : null;
if (StringUtils.isEmpty(mediaType)) {
throw new PreBidException("Missed mediaType");
}
try {
return BidType.valueOf(mediaType);
} catch (IllegalArgumentException e) {
throw new PreBidException(e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.prebid.server.proto.openrtb.ext.request.bidmyadz;

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

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

@JsonProperty("placementId")
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,51 @@
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();
}
}
2 changes: 1 addition & 1 deletion src/main/resources/bidder-config/bidmachine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ adapters:
- video
site-media-types:
supported-vendors:
vendor-id: 724
vendor-id: 736
usersync:
url:
redirect-url:
Expand Down
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: 0
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