forked from prebid/prebid-server-java
-
Notifications
You must be signed in to change notification settings - Fork 0
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
3ac30bc
commit db72a00
Showing
11 changed files
with
442 additions
and
36 deletions.
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
src/main/java/org/prebid/server/bidder/loopme/LoopmeBidder.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,95 @@ | ||
package org.prebid.server.bidder.loopme; | ||
|
||
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.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.BidderCall; | ||
import org.prebid.server.bidder.model.BidderError; | ||
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.BidderUtil; | ||
import org.prebid.server.util.HttpUtil; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.stream.Collectors; | ||
|
||
public class LoopmeBidder implements Bidder<BidRequest> { | ||
|
||
private final String endpointUrl; | ||
|
||
private final JacksonMapper mapper; | ||
|
||
public LoopmeBidder(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) { | ||
|
||
return Result.withValue(HttpRequest.<BidRequest>builder() | ||
.method(HttpMethod.POST) | ||
.uri(endpointUrl) | ||
.headers(HttpUtil.headers()) | ||
.impIds(BidderUtil.impIds(request)) | ||
.body(mapper.encodeToBytes(request)) | ||
.payload(request) | ||
.build()); | ||
} | ||
|
||
@Override | ||
public final Result<List<BidderBid>> makeBids(BidderCall<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) { | ||
return BidType.banner; | ||
} else if (imp.getVideo() != null) { | ||
return BidType.video; | ||
} else if (imp.getAudio() != null) { | ||
return BidType.audio; | ||
} else if (imp.getXNative() != null) { | ||
return BidType.xNative; | ||
} | ||
} | ||
} | ||
return BidType.banner; | ||
} | ||
} |
18 changes: 10 additions & 8 deletions
18
src/main/java/org/prebid/server/proto/openrtb/ext/request/loopme/ExtImpLoopme.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 |
---|---|---|
@@ -1,16 +1,18 @@ | ||
package org.prebid.server.proto.openrtb.ext.request.loopme; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Value; | ||
|
||
/** | ||
* Defines the contract for bidrequest.imp[i].ext.loopme | ||
*/ | ||
@AllArgsConstructor(staticName = "of") | ||
@Value | ||
@Value(staticConstructor = "of") | ||
public class ExtImpLoopme { | ||
|
||
@JsonProperty("accountId") | ||
String accountId; | ||
@JsonProperty("publisherId") | ||
String publisherId; | ||
|
||
@JsonProperty("bundleId") | ||
String bundleId; | ||
|
||
@JsonProperty("placementId") | ||
String placementId; | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/org/prebid/server/spring/config/bidder/LoopmeConfiguration.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,40 @@ | ||
package org.prebid.server.spring.config.bidder; | ||
|
||
import org.prebid.server.bidder.BidderDeps; | ||
import org.prebid.server.bidder.loopme.LoopmeBidder; | ||
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.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/loopme.yaml", factory = YamlPropertySourceFactory.class) | ||
public class LoopmeConfiguration { | ||
|
||
private static final String BIDDER_NAME = "loopme"; | ||
|
||
@Bean("loopmeConfigurationProperties") | ||
@ConfigurationProperties("adapters.loopme") | ||
BidderConfigurationProperties configurationProperties() { | ||
return new BidderConfigurationProperties(); | ||
} | ||
|
||
@Bean | ||
BidderDeps loopmeBidderDeps(BidderConfigurationProperties loopmeConfigurationProperties, | ||
@NotBlank @Value("${external-url}") String externalUrl, | ||
JacksonMapper mapper) { | ||
return BidderDepsAssembler.forBidder(BIDDER_NAME) | ||
.withConfig(loopmeConfigurationProperties) | ||
.usersyncerCreator(UsersyncerCreator.create(externalUrl)) | ||
.bidderCreator(config -> new LoopmeBidder(loopmeConfigurationProperties.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 |
---|---|---|
|
@@ -41,21 +41,6 @@ adapters: | |
- video | ||
supported-vendors: | ||
vendor-id: 0 | ||
loopme: | ||
enabled: false | ||
endpoint: http://prebid-eu.loopmertb.com | ||
meta-info: | ||
maintainer-email: [email protected] | ||
app-media-types: | ||
- banner | ||
- video | ||
- native | ||
site-media-types: | ||
- banner | ||
- video | ||
- native | ||
supported-vendors: | ||
vendor-id: 109 | ||
zeta_global_ssp: | ||
enabled: false | ||
endpoint: https://ssp.disqus.com/bid/prebid-server?sid=GET_SID_FROM_ZETA | ||
|
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,23 @@ | ||
adapters: | ||
loopme: | ||
endpoint: http://prebid.loopmertb.com | ||
meta-info: | ||
maintainer-email: [email protected] | ||
app-media-types: | ||
- banner | ||
- video | ||
- audio | ||
- native | ||
site-media-types: | ||
- banner | ||
- video | ||
- audio | ||
- native | ||
supported-vendors: | ||
vendor-id: 109 | ||
usersync: | ||
url: https://csync.loopme.me/?pubid=11393&gdpr={{gdpr}}&gdpr_consent={{gdpr_consent}}&us_privacy={{us_privacy}}&redirect={{redirect_url}} | ||
redirect-url: /setuid?bidder=loopme&gdpr={{gdpr}}&gdpr_consent={{gdpr_consent}}&us_privacy={{us_privacy}}&uid={udid} | ||
cookie-family-name: loopme | ||
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
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
Oops, something went wrong.