Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IX Deal Support #638

Merged
merged 1 commit into from
Sep 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 6 additions & 14 deletions src/adapters/indexExchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,36 +404,28 @@ var IndexExchangeAdapter = function IndexExchangeAdapter() {
bid.width = slotObj.width;
bid.height = slotObj.height;
bid.siteID = slotObj.siteID;

if ( typeof _IndexRequestData.targetIDToResp === 'object' && typeof _IndexRequestData.targetIDToResp[cpmAndSlotId] === 'object' && typeof _IndexRequestData.targetIDToResp[cpmAndSlotId].dealID !== 'undefined' ) {
bid.dealId = _IndexRequestData.targetIDToResp[cpmAndSlotId].dealID;
}
bids.push(bid);
}
}

var currentBid = undefined;

//Pick the highest bidding price for this slot
if (bids.length > 0) {
// Choose the highest bid
// Add all bid responses
for (var i = 0; i < bids.length; i++) {
var bid = bids[i];
if (typeof currentBid === 'undefined') {
currentBid = bid;
continue;
}

if (bid.cpm > currentBid.cpm) {
currentBid = bid;
}
bidmanager.addBidResponse(adUnitCode, bids[i]);
}

// No bids for expected bid, pass bid
} else {
var bid = bidfactory.createBid(2);
bid.bidderCode = ADAPTER_CODE;
currentBid = bid;
bidmanager.addBidResponse(adUnitCode, currentBid);
}

bidmanager.addBidResponse(adUnitCode, currentBid);
}
} catch (e) {
utils.logError('Error calling index adapter', ADAPTER_NAME, e);
Expand Down
96 changes: 96 additions & 0 deletions test/helpers/index_adapter_response.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
var OPEN_MARKET = 'IOM';
var PRIVATE_MARKET = 'IPM';

function cygnus_index_parse_res( response ) {
try {
if (response) {
if (typeof _IndexRequestData !== "object" || typeof _IndexRequestData.impIDToSlotID !== "object" || typeof _IndexRequestData.impIDToSlotID[response.id] === "undefined") {
return;
}
var targetMode = 1;
var callbackFn;
if (typeof _IndexRequestData.reqOptions === 'object' && typeof _IndexRequestData.reqOptions[response.id] === 'object') {
if (typeof _IndexRequestData.reqOptions[response.id].callback === "function") {
callbackFn = _IndexRequestData.reqOptions[response.id].callback;
}
if (typeof _IndexRequestData.reqOptions[response.id].targetMode === "number") {
targetMode = _IndexRequestData.reqOptions[response.id].targetMode;
}
}

_IndexRequestData.lastRequestID = response.id;
_IndexRequestData.targetIDToBid = {};
_IndexRequestData.targetIDToResp = {};
var allBids = [];
var seatbidLength = typeof response.seatbid === "undefined" ? 0 : response.seatbid.length;
for (var i = 0; i < seatbidLength; i++) {
for (var j = 0; j < response.seatbid[i].bid.length; j++) {
var bid = response.seatbid[i].bid[j];
if (typeof bid.ext !== "object" || typeof bid.ext.pricelevel !== "string") {
continue;
}
if (typeof _IndexRequestData.impIDToSlotID[response.id][bid.impid] === "undefined") {
continue;
}
var slotID = _IndexRequestData.impIDToSlotID[response.id][bid.impid];
if (typeof index_slots === "undefined") {
index_slots = [];
}
if (typeof _IndexRequestData.targetIDToBid === "undefined") {
_IndexRequestData.targetIDToBid = {};
}
if (typeof _IndexRequestData.targetIDToResp === "undefined") {
_IndexRequestData.targetIDToResp = {};
}
var targetID;
var targetPrefix;
if (typeof bid.ext.dealid === "string") {
if (targetMode === 1) {
targetID = slotID + bid.ext.pricelevel;
} else {
targetID = slotID + "_" + bid.ext.dealid;
}
targetPrefix = PRIVATE_MARKET + '_';
} else {
targetID = slotID + bid.ext.pricelevel;
targetPrefix = OPEN_MARKET + '_';
}
index_slots.push(targetPrefix + targetID);
if (_IndexRequestData.targetIDToBid[targetID] === undefined) {
_IndexRequestData.targetIDToBid[targetID] = [bid.adm];
} else {
_IndexRequestData.targetIDToBid[targetID].push(bid.adm);
}
var impBid = {};
impBid.impressionID = bid.impid;
if (typeof bid.ext.dealid !== 'undefined') {
impBid.dealID = bid.ext.dealid;
}
impBid.bid = bid.price;
impBid.slotID = slotID;
impBid.priceLevel = bid.ext.pricelevel;
impBid.target = targetPrefix + targetID;
_IndexRequestData.targetIDToResp[targetID] = impBid;
allBids.push(impBid);
}
}
if (typeof callbackFn === "function") {
if (allBids.length === 0) {
callbackFn(response.id);
} else {
callbackFn(response.id, allBids);
}
}

}
} catch (e) { }
if (typeof index_slots === "undefined") {
index_slots = [];
}

if (typeof window.cygnus_index_ready_state === 'function') {
window.cygnus_index_ready_state();
}
}

exports.cygnus_index_parse_res = cygnus_index_parse_res;
Loading