-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c1a1f41
commit fcc8993
Showing
14 changed files
with
857 additions
and
0 deletions.
There are no files selected for viewing
133 changes: 133 additions & 0 deletions
133
src/main/java/org/prebid/server/bidder/adyoulike/AdyoulikeBidder.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,133 @@ | ||
package org.prebid.server.bidder.adyoulike; | ||
|
||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import com.iab.openrtb.request.BidRequest; | ||
import com.iab.openrtb.request.Imp; | ||
import com.iab.openrtb.response.BidResponse; | ||
import com.iab.openrtb.response.SeatBid; | ||
import io.vertx.core.MultiMap; | ||
import io.vertx.core.http.HttpMethod; | ||
import org.apache.commons.collections4.CollectionUtils; | ||
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.ExtPrebid; | ||
import org.prebid.server.proto.openrtb.ext.request.adyoulike.ExtImpAdyoulike; | ||
import org.prebid.server.proto.openrtb.ext.response.BidType; | ||
import org.prebid.server.util.HttpUtil; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Adyoulike {@link Bidder} implementation. | ||
*/ | ||
public class AdyoulikeBidder implements Bidder<BidRequest> { | ||
|
||
private static final TypeReference<ExtPrebid<?, ExtImpAdyoulike>> ADYOULIKE_EXT_TYPE_REFERENCE = | ||
new TypeReference<ExtPrebid<?, ExtImpAdyoulike>>() { | ||
}; | ||
private static final String URL_PUBLISHER_ID_MACRO = "{{publisherId}}"; | ||
|
||
private final String endpointUrl; | ||
private final JacksonMapper mapper; | ||
|
||
public AdyoulikeBidder(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<Imp> modifiedImps = new ArrayList<>(); | ||
final List<BidderError> errors = new ArrayList<>(); | ||
|
||
for (Imp imp : request.getImp()) { | ||
try { | ||
final ExtImpAdyoulike impExt = parseImpExt(imp); | ||
|
||
modifiedImps.add(imp.toBuilder().tagid(impExt.getPlacement()).build()); | ||
} catch (PreBidException e) { | ||
errors.add(BidderError.badInput(e.getMessage())); | ||
} | ||
} | ||
|
||
if (errors.size() > 0) { | ||
return Result.withErrors(errors); | ||
} | ||
|
||
final BidRequest outgoingRequest = request.toBuilder().imp(modifiedImps).build(); | ||
|
||
return Result.withValue(HttpRequest.<BidRequest>builder() | ||
.method(HttpMethod.POST) | ||
.uri(endpointUrl) | ||
.headers(resolveHeaders()) | ||
.payload(outgoingRequest) | ||
.body(mapper.encode(outgoingRequest)) | ||
.build()); | ||
} | ||
|
||
private ExtImpAdyoulike parseImpExt(Imp imp) { | ||
try { | ||
return mapper.mapper().convertValue(imp.getExt(), ADYOULIKE_EXT_TYPE_REFERENCE).getBidder(); | ||
} catch (IllegalArgumentException e) { | ||
throw new PreBidException(e.getMessage()); | ||
} | ||
} | ||
|
||
private static MultiMap resolveHeaders() { | ||
return HttpUtil.headers() | ||
.add(HttpUtil.X_OPENRTB_VERSION_HEADER, "2.5"); | ||
} | ||
|
||
@Override | ||
public final Result<List<BidderBid>> makeBids(HttpCall<BidRequest> httpCall, BidRequest bidRequest) { | ||
try { | ||
final BidResponse bidResponse = mapper.decodeValue(httpCall.getResponse().getBody(), BidResponse.class); | ||
return Result.of(extractBids(httpCall.getRequest().getPayload(), bidResponse), Collections.emptyList()); | ||
} 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())) { | ||
return Collections.emptyList(); | ||
} | ||
return bidsFromResponse(bidRequest, bidResponse); | ||
} | ||
|
||
private static List<BidderBid> bidsFromResponse(BidRequest bidRequest, BidResponse bidResponse) { | ||
return bidResponse.getSeatbid().stream() | ||
.filter(Objects::nonNull) | ||
.map(SeatBid::getBid) | ||
.filter(Objects::nonNull) | ||
.flatMap(Collection::stream) | ||
.map(bid -> BidderBid.of(bid, getBidType(bid.getImpid(), bidRequest.getImp()), bidResponse.getCur())) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
private static BidType getBidType(String impId, List<Imp> imps) { | ||
for (Imp imp : imps) { | ||
if (imp.getId().equals(impId)) { | ||
if (imp.getBanner() == null && imp.getVideo() != null) { | ||
return BidType.video; | ||
} else if (imp.getBanner() == null && imp.getXNative() != null) { | ||
return BidType.xNative; | ||
} | ||
} | ||
} | ||
return BidType.banner; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/org/prebid/server/proto/openrtb/ext/request/adyoulike/ExtImpAdyoulike.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,24 @@ | ||
package org.prebid.server.proto.openrtb.ext.request.adyoulike; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Value; | ||
|
||
/** | ||
* Defines the contract for bidRequest.imp[i].ext.adyoulike | ||
*/ | ||
@AllArgsConstructor(staticName = "of") | ||
@Value | ||
public class ExtImpAdyoulike { | ||
|
||
String placement; | ||
|
||
String campaign; | ||
|
||
String track; | ||
|
||
String creative; | ||
|
||
String source; | ||
|
||
String debug; | ||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/org/prebid/server/spring/config/bidder/AdyoulikeConfiguration.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.adyoulike.AdyoulikeBidder; | ||
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/adyoulike.yaml", factory = YamlPropertySourceFactory.class) | ||
public class AdyoulikeConfiguration { | ||
|
||
private static final String BIDDER_NAME = "adyoulike"; | ||
|
||
@Value("${external-url}") | ||
@NotBlank | ||
private String externalUrl; | ||
|
||
@Autowired | ||
private JacksonMapper mapper; | ||
|
||
@Autowired | ||
@Qualifier("adyoulikeConfigurationProperties") | ||
private BidderConfigurationProperties configProperties; | ||
|
||
@Bean("adyoulikeConfigurationProperties") | ||
@ConfigurationProperties("adapters.adyoulike") | ||
BidderConfigurationProperties configurationProperties() { | ||
return new BidderConfigurationProperties(); | ||
} | ||
|
||
@Bean | ||
BidderDeps adyoulileBidderDeps() { | ||
return BidderDepsAssembler.forBidder(BIDDER_NAME) | ||
.withConfig(configProperties) | ||
.usersyncerCreator(UsersyncerCreator.create(externalUrl)) | ||
.bidderCreator(config -> new AdyoulikeBidder(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
adapters: | ||
adyoulike: | ||
enabled: false | ||
endpoint: https://broker-preprod.omnitagjs.com/broker/bid?partnerId=19340f4f097d16f41f34fc0274981ca4 | ||
pbs-enforces-gdpr: true | ||
pbs-enforces-ccpa: true | ||
modifying-vast-xml-allowed: true | ||
deprecated-names: | ||
aliases: {} | ||
meta-info: | ||
maintainer-email: core@adyoulike.com | ||
app-media-types: | ||
site-media-types: | ||
- banner | ||
- video | ||
- native | ||
supported-vendors: | ||
vendor-id: 259 | ||
usersync: | ||
url: http://visitor.omnitagjs.com/visitor/bsync?uid=19340f4f097d16f41f34fc0274981ca4&name=PrebidServer&gdpr={{gdpr}}&gdpr_consent={{gdpr_consent}}&us_privacy={{us_privacy}}&url= | ||
redirect-url: /setuid?bidder=adyoulike&gdpr={{gdpr}}&gdpr_consent={{gdpr_consent}}&us_privacy={{us_privacy}}&uid=[BUYER_USERID] | ||
cookie-family-name: adyoulike | ||
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,33 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"title": "AdYouLike Adapter Params", | ||
"description": "A schema which validates params accepted by the AdYouLike adapter", | ||
"type": "object", | ||
"properties": { | ||
"placement": { | ||
"type": "string", | ||
"description": "Placement Id" | ||
}, | ||
"campaign": { | ||
"type": "string", | ||
"description": "Id of a forced campaign" | ||
}, | ||
"track": { | ||
"type": "string", | ||
"description": "Id of a forced Track" | ||
}, | ||
"creative": { | ||
"type": "string", | ||
"description": "Id of a forced creative" | ||
}, | ||
"source": { | ||
"type": "string", | ||
"description": "context of the campaign" | ||
}, | ||
"debug": { | ||
"type": "string", | ||
"description": "Arbitrary id used for debug purpose" | ||
} | ||
}, | ||
"required": ["placement"] | ||
} |
Oops, something went wrong.