-
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
Merged
Merged
New bidder bidmyadz #1352
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
888a120
add new bidder bidmachine
d2a7067
fix comments
229fd67
add new bidmyadz bidder
fe3008f
add new bidmyadz bidder
0571316
fixes according to comments
2dd92b3
fixes according to comments
090cff7
fixes according to comments
e7cc985
fixes according to comments
f149dd2
fixes according to comments
47b1f0e
fixes according to comments
1ac8efe
fixes according to comments
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
118 changes: 118 additions & 0 deletions
118
src/main/java/org/prebid/server/bidder/bidmyadz/BidmyadzBidder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
/** | ||
* 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()); | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/org/prebid/server/proto/openrtb/ext/request/bidmyadz/ExtImpBidmyadz.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
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 |
||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/org/prebid/server/spring/config/bidder/BidmyadzConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.