-
Notifications
You must be signed in to change notification settings - Fork 181
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
New bidder bidmyadz #1352
Changes from 4 commits
888a120
d2a7067
229fd67
fe3008f
0571316
2dd92b3
090cff7
e7cc985
f149dd2
47b1f0e
1ac8efe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; | ||
|
||
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")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can be static 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 |
||
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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems here |
||
} |
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(); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Redundant \n |
||
} |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, |
||
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 |
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"] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.