Skip to content

Commit

Permalink
allows multiple bids to be registered per a slot. fixes prebid#496
Browse files Browse the repository at this point in the history
  • Loading branch information
snapwich committed Aug 4, 2016
1 parent 45fd284 commit 967f2da
Showing 1 changed file with 40 additions and 29 deletions.
69 changes: 40 additions & 29 deletions src/adapters/rubicon.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}

/**
Expand Down Expand Up @@ -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());
});
}

Expand Down

0 comments on commit 967f2da

Please sign in to comment.