From 967f2da600d2406c7eb708f5296c0742bf4cd0be Mon Sep 17 00:00:00 2001 From: Rich Snapp Date: Thu, 4 Aug 2016 12:54:02 -0600 Subject: [PATCH] allows multiple bids to be registered per a slot. fixes #496 --- src/adapters/rubicon.js | 69 ++++++++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 29 deletions(-) diff --git a/src/adapters/rubicon.js b/src/adapters/rubicon.js index e67eba2371f..27e2faa416d 100644 --- a/src/adapters/rubicon.js +++ b/src/adapters/rubicon.js @@ -99,59 +99,70 @@ var RubiconAdapter = function RubiconAdapter() { } /** - * Create a (successful) bid for a unit, + * Create (successful) bids for a unit, * based on the given response * @param {String} placement placement code/unit path * @param {Object} response the response from rubicon * @return {Bid} a bid objectj */ - function _makeBid(response, ads) { + function _makeBids(response, ads) { // if there are multiple ads, sort by CPM ads = ads.sort(_adCpmSort); - var bidResponse = bidfactory.createBid(1); - var ad = ads[0]; - var size = ad.dimensions; + var bidResponses = []; - if (!size) { - // this really shouldn't happen - utils.logError('no dimensions given', RUBICON_BIDDER_CODE, ad); - return _errorBid(response, ads); - } + ads.forEach(function(ad) { - bidResponse.bidderCode = RUBICON_BIDDER_CODE; - bidResponse.cpm = ad.cpm; + var bidResponse, + size = ad.dimensions; - // the element id is what the iframe will use to render - // itself using the rubicontag.renderCreative API - bidResponse.ad = _creative(response.getElementId(), size); - bidResponse.width = size[0]; - bidResponse.height = size[1]; + if (!size) { + // this really shouldn't happen + utils.logError('no dimensions given', RUBICON_BIDDER_CODE, ad); + bidResponse = _errorBid(response, ads); + } else { + bidResponse = bidfactory.createBid(1); - // DealId - if (ads.deal !== undefined && ads.deal !== "") { - bidResponse.dealId = ads.deal; - } + bidResponse.bidderCode = RUBICON_BIDDER_CODE; + bidResponse.cpm = ad.cpm; - return bidResponse; + // the element id is what the iframe will use to render + // itself using the rubicontag.renderCreative API + bidResponse.ad = _creative(response.getElementId(), size); + bidResponse.width = size[0]; + bidResponse.height = size[1]; + + // DealId + if (ads.deal !== undefined && ads.deal !== "") { + bidResponse.dealId = ads.deal; + } + } + + bidResponses.push(bidResponse); + + }); + + return bidResponses; } /** - * Add a success/error bid based + * Add success/error bids based * on the response from rubicon * @param {Object} response -- AJAX response from fastlane */ - function _addBid(response, ads) { + function _addBids(response, ads) { // get the bid for the placement code - var bid; + var bids; if (!ads || ads.length === 0) { - bid = _errorBid(response, ads); + bids = [ _errorBid(response, ads) ]; } else { - bid = _makeBid(response, ads); + bids = _makeBids(response, ads); } - bidmanager.addBidResponse(response.getElementId(), bid); + bids.forEach(function(bid) { + bidmanager.addBidResponse(response.getElementId(), bid); + }); } /** @@ -265,7 +276,7 @@ var RubiconAdapter = function RubiconAdapter() { utils.logMessage('Rubicon Project bidding complete: ' + ((new Date).getTime() - _bidStart)); utils._each(slots, function (slot) { - _addBid(slot, slot.getRawResponses()); + _addBids(slot, slot.getRawResponses()); }); }