Skip to content

Commit

Permalink
Remove pbs depracated legacy url (prebid#4226)
Browse files Browse the repository at this point in the history
* remove deprecated legacy url from pbs adapter

* fix eslint errors

* add and update tests for openRtb2 endpoint
  • Loading branch information
sumit116 authored Sep 26, 2019
1 parent f1642f1 commit 7075182
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 396 deletions.
180 changes: 3 additions & 177 deletions modules/prebidServerBidAdapter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,157 +281,6 @@ function _appendSiteAppDevice(request) {
}
}

function transformHeightWidth(adUnit) {
let sizesObj = [];
let sizes = utils.parseSizesInput(adUnit.sizes);
sizes.forEach(size => {
let heightWidth = size.split('x');
let sizeObj = {
'w': parseInt(heightWidth[0]),
'h': parseInt(heightWidth[1])
};
sizesObj.push(sizeObj);
});
return sizesObj;
}

/*
* Protocol spec for legacy endpoint
* e.g., https://<prebid-server-url>/v1/auction
*/
const LEGACY_PROTOCOL = {

buildRequest(s2sBidRequest, bidRequests, adUnits) {
adUnits.forEach(adUnit => {
adUnit.bids.forEach(bid => {
const adapter = adapterManager.bidderRegistry[bid.bidder];
if (adapter && adapter.getSpec().transformBidParams) {
bid.params = adapter.getSpec().transformBidParams(bid.params, isOpenRtb());
}
});
});

// pbs expects an ad_unit.video attribute if the imp is video
adUnits.forEach(adUnit => {
adUnit.sizes = transformHeightWidth(adUnit);
const videoMediaType = utils.deepAccess(adUnit, 'mediaTypes.video');
if (videoMediaType) {
adUnit.video = Object.assign({}, videoMediaType);
delete adUnit.mediaTypes;
// default is assumed to be 'banner' so if there is a video type
// we assume video only until PBS can support multi-format auction
adUnit.media_types = [VIDEO];
}
});

const request = {
account_id: _s2sConfig.accountId,
tid: s2sBidRequest.tid,
max_bids: _s2sConfig.maxBids,
timeout_millis: _s2sConfig.timeout,
secure: _s2sConfig.secure,
cache_markup: _s2sConfig.cacheMarkup === 1 || _s2sConfig.cacheMarkup === 2 ? _s2sConfig.cacheMarkup : 0,
url: utils.getTopWindowUrl(),
prebid_version: '$prebid.version$',
ad_units: adUnits,
is_debug: !!getConfig('debug'),
};

_appendSiteAppDevice(request);

let digiTrust = _getDigiTrustQueryParams(bidRequests && bidRequests[0]);
if (digiTrust) {
request.digiTrust = digiTrust;
}

return request;
},

interpretResponse(result, bidderRequests) {
const bids = [];
if (result.status === 'OK' || result.status === 'no_cookie') {
if (result.bidder_status) {
result.bidder_status.forEach(bidder => {
if (bidder.error) {
utils.logWarn(`Prebid Server returned error: '${bidder.error}' for ${bidder.bidder}`);
}

bidderRequests.filter(bidderRequest => bidderRequest.bidderCode === bidder.bidder)
.forEach(bidderRequest =>
(bidderRequest.bids || []).forEach(bid =>
bid.serverResponseTimeMs = bidder.response_time_ms
)
)
});
}

if (result.bids) {
result.bids.forEach(bidObj => {
const bidRequest = utils.getBidRequest(bidObj.bid_id, bidderRequests);
const cpm = bidObj.price;
const status = cpm !== 0 ? STATUS.GOOD : STATUS.NO_BID;
let bidObject = createBid(status, bidRequest);

bidObject.source = TYPE;
bidObject.creative_id = bidObj.creative_id;
bidObject.bidderCode = bidObj.bidder;
bidObject.cpm = cpm;
if (bidObj.cache_id) {
bidObject.cache_id = bidObj.cache_id;
}
if (bidObj.cache_url) {
bidObject.cache_url = bidObj.cache_url;
}
// From ORTB see section 4.2.3: adm Optional means of conveying ad markup in case the bid wins; supersedes the win notice if markup is included in both.
if (bidObj.media_type === VIDEO) {
bidObject.mediaType = VIDEO;
if (bidObj.adm) {
bidObject.vastXml = bidObj.adm;
}
if (bidObj.nurl) {
bidObject.vastUrl = bidObj.nurl;
}
// when video bid is already cached by Prebid Server, videoCacheKey and vastUrl should be provided properly
if (bidObj.cache_id && bidObj.cache_url) {
bidObject.videoCacheKey = bidObj.cache_id;
bidObject.vastUrl = bidObj.cache_url;
}
} else {
if (bidObj.adm && bidObj.nurl) {
bidObject.ad = bidObj.adm;
bidObject.ad += utils.createTrackPixelHtml(decodeURIComponent(bidObj.nurl));
} else if (bidObj.adm) {
bidObject.ad = bidObj.adm;
} else if (bidObj.nurl) {
bidObject.adUrl = bidObj.nurl;
}
}

bidObject.width = bidObj.width;
bidObject.height = bidObj.height;
bidObject.adserverTargeting = bidObj.ad_server_targeting;
if (bidObj.deal_id) {
bidObject.dealId = bidObj.deal_id;
}
bidObject.requestId = bidRequest.bidId || bidRequest.bid_Id;
bidObject.creativeId = bidObj.creative_id;

// TODO: Remove when prebid-server returns ttl, currency and netRevenue
bidObject.ttl = (bidObj.ttl) ? bidObj.ttl : DEFAULT_S2S_TTL;
bidObject.currency = (bidObj.currency) ? bidObj.currency : DEFAULT_S2S_CURRENCY;
bidObject.netRevenue = (bidObj.netRevenue) ? bidObj.netRevenue : DEFAULT_S2S_NETREVENUE;

if (result.burl) { bidObject.burl = result.burl; }

bids.push({ adUnit: bidObj.code, bid: bidObject });
});
}
}

return bids;
}
};

// https://iabtechlab.com/wp-content/uploads/2016/07/OpenRTB-Native-Ads-Specification-Final-1.2.pdf#page=40
let nativeDataIdMap = {
sponsoredBy: 1, // sponsored
Expand Down Expand Up @@ -624,7 +473,7 @@ const OPEN_RTB_PROTOCOL = {
const ext = adUnit.bids.reduce((acc, bid) => {
const adapter = adapterManager.bidderRegistry[bid.bidder];
if (adapter && adapter.getSpec().transformBidParams) {
bid.params = adapter.getSpec().transformBidParams(bid.params, isOpenRtb());
bid.params = adapter.getSpec().transformBidParams(bid.params, true);
}
acc[bid.bidder] = (_s2sConfig.adapterOptions && _s2sConfig.adapterOptions[bid.bidder]) ? Object.assign({}, bid.params, _s2sConfig.adapterOptions[bid.bidder]) : bid.params;
return acc;
Expand Down Expand Up @@ -893,29 +742,6 @@ const OPEN_RTB_PROTOCOL = {
}
};

const isOpenRtb = () => {
const OPEN_RTB_PATH = '/openrtb2/';

const endpoint = (_s2sConfig && _s2sConfig.endpoint) || '';
return ~endpoint.indexOf(OPEN_RTB_PATH);
}

/*
* Returns the required protocol adapter to communicate with the configured
* endpoint. The adapter is an object containing `buildRequest` and
* `interpretResponse` functions.
*
* Usage:
* // build JSON payload to send to server
* const request = protocol().buildRequest(s2sBidRequest, adUnits);
*
* // turn server response into bid object array
* const bids = protocol().interpretResponse(response, bidRequests, requestedBidders);
*/
const protocolAdapter = () => {
return isOpenRtb() ? OPEN_RTB_PROTOCOL : LEGACY_PROTOCOL;
};

/**
* Bidder adapter for Prebid Server
*/
Expand Down Expand Up @@ -943,7 +769,7 @@ export function PrebidServer() {
queueSync(_s2sConfig.bidders, consent);
}

const request = protocolAdapter().buildRequest(s2sBidRequest, bidRequests, validAdUnits);
const request = OPEN_RTB_PROTOCOL.buildRequest(s2sBidRequest, bidRequests, validAdUnits);
const requestJson = request && JSON.stringify(request);
if (request && requestJson) {
ajax(
Expand All @@ -966,7 +792,7 @@ export function PrebidServer() {
try {
result = JSON.parse(response);

bids = protocolAdapter().interpretResponse(
bids = OPEN_RTB_PROTOCOL.interpretResponse(
result,
bidderRequests,
requestedBidders
Expand Down
Loading

0 comments on commit 7075182

Please sign in to comment.