Skip to content

Commit

Permalink
Handle adding bids in core response handler
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewlane committed Feb 8, 2018
1 parent f20b0c0 commit d207b48
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions modules/prebidServerBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,6 @@ function _getDigiTrustQueryParams() {
const legacy = {
// build payload for endpoint
buildRequest(s2sBidRequest, ad_units) {
const isDebug = !!getConfig('debug');

const request = {
account_id: _s2sConfig.accountId,
tid: s2sBidRequest.tid,
Expand All @@ -224,19 +222,18 @@ const legacy = {
url: utils.getTopWindowUrl(),
prebid_version: '$prebid.version$',
ad_units: ad_units,
is_debug: isDebug,
is_debug: !!getConfig('debug'),
};

let digiTrust = _getDigiTrustQueryParams();

// grab some global config and pass it along
['app', 'device'].forEach(setting => {
let value = getConfig(setting);
if (typeof value === 'object') {
requestJson[setting] = value;
request[setting] = value;
}
});

let digiTrust = _getDigiTrustQueryParams();
if (digiTrust) {
request.digiTrust = digiTrust;
}
Expand All @@ -245,7 +242,9 @@ const legacy = {
},

// handler for endpoint response
interpretResponse(result, addBidResponse, bidRequests, requestedBidders) {
interpretResponse(result, bidRequests, requestedBidders) {
const bids = [];

if (result.status === 'OK' || result.status === 'no_cookie') {
if (result.bidder_status) {
result.bidder_status.forEach(bidder => {
Expand Down Expand Up @@ -319,9 +318,7 @@ const legacy = {
bidObject.currency = (bidObj.currency) ? bidObj.currency : DEFAULT_S2S_CURRENCY;
bidObject.netRevenue = (bidObj.netRevenue) ? bidObj.netRevenue : DEFAULT_S2S_NETREVENUE;

if (isValid(bidObj.code, bidObject, bidRequests)) {
addBidResponse(bidObj.code, bidObject);
}
bids.push({ adUnit: bidObj.code, bid: bidObject })
});
}
}
Expand All @@ -330,6 +327,8 @@ const legacy = {
// cookie sync
cookieSet(_s2sConfig.cookieSetUrl);
}

return bids;
}
};

Expand Down Expand Up @@ -378,7 +377,9 @@ const openRtb = {
},

// handler for endpoint response
interpretResponse(response, addBidResponse, bidRequests, requestedBidders) {
interpretResponse(response, bidRequests, requestedBidders) {
const bids = [];

if (response.seatbid) {
response.seatbid.forEach(bidObj => {
let cpm = bidObj.bid[0].price;
Expand Down Expand Up @@ -407,11 +408,11 @@ const openRtb = {
bidObject.currency = (bidObj.currency) ? bidObj.currency : DEFAULT_S2S_CURRENCY;
bidObject.netRevenue = (bidObj.netRevenue) ? bidObj.netRevenue : DEFAULT_S2S_NETREVENUE;

if (isValid(bidObj.bid[0].impid, bidObject, bidRequests)) {
addBidResponse(bidObj.bid[0].impid, bidObject);
}
bids.push({ adUnit: bidObj.bid[0].impid, bid: bidObject });
});
}

return bids;
}
};

Expand All @@ -425,7 +426,7 @@ const openRtb = {
* const request = protocol().buildRequest(s2sBidRequest, ad_units);
*
* // handle server response with using given parameters, e.g. in `handleResponse`
* protocol().interpretResponse(response, addBidResponse, bidRequests, requestedBidders);
* protocol().interpretResponse(response, bidRequests, requestedBidders);
*/
const protocol = () => {
const isOpenRtb = _s2sConfig.endpoint.includes(OPEN_RTB_PATH);
Expand Down Expand Up @@ -478,7 +479,13 @@ export function PrebidServer() {

try {
result = JSON.parse(response);
protocol().interpretResponse(result, addBidResponse, bidRequests, requestedBidders);

const bids = protocol().interpretResponse(result, bidRequests, requestedBidders);
(bids || []).forEach(({adUnit, bid}) => {
if (isValid(adUnit, bid, bidRequests)) {
addBidResponse(adUnit, bid);
}
});
} catch (error) {
utils.logError(error);
}
Expand Down

0 comments on commit d207b48

Please sign in to comment.