Skip to content

Commit

Permalink
IX adapter code refactoring (#711)
Browse files Browse the repository at this point in the history
  • Loading branch information
Index Exchange authored and Nate Cozi committed Oct 25, 2016
1 parent 85d865d commit caa5370
Show file tree
Hide file tree
Showing 6 changed files with 2,453 additions and 51 deletions.
23 changes: 16 additions & 7 deletions src/adapters/indexExchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ var cygnus_index_start = function () {
throw 'Invalid Site ID';
}

timeoutDelay = Number(timeoutDelay);
if (typeof timeoutDelay === 'number' && timeoutDelay % 1 === 0 && timeoutDelay >= 0) {
this.timeoutDelay = timeoutDelay;
}
Expand Down Expand Up @@ -114,8 +115,8 @@ var cygnus_index_start = function () {
}

OpenRTBRequest.prototype.serialize = function () {
var json = '{"id":' + this.requestID + ',"site":{"page":"' + quote(this.sitePage) + '"';
if (typeof document.referrer === 'string') {
var json = '{"id":"' + this.requestID + '","site":{"page":"' + quote(this.sitePage) + '"';
if (typeof document.referrer === 'string' && document.referrer !== "") {
json += ',"ref":"' + quote(document.referrer) + '"';
}

Expand Down Expand Up @@ -225,7 +226,8 @@ var cygnus_index_start = function () {
} else {
scriptSrc = window.location.protocol === 'https:' ? 'https://as-sec.casalemedia.com' : 'http://as.casalemedia.com';
}
scriptSrc += '/headertag?v=9&x3=1&fn=cygnus_index_parse_res&s=' + this.siteID + '&r=' + jsonURI;
var prebidVersion = encodeURIComponent("$prebid.version$");
scriptSrc += '/headertag?v=9&fn=cygnus_index_parse_res&s=' + this.siteID + '&r=' + jsonURI + '&pid=pb' + prebidVersion;
if (typeof this.timeoutDelay === 'number' && this.timeoutDelay % 1 === 0 && this.timeoutDelay >= 0) {
scriptSrc += '&t=' + this.timeoutDelay;
}
Expand Down Expand Up @@ -314,14 +316,17 @@ var IndexExchangeAdapter = function IndexExchangeAdapter() {
for (var j = 0; j < bid.sizes.length; j++) {
var validSize = false;
for (var k = 0; k < cygnus_index_adunits.length; k++) {
if (bid.sizes[j][0] === cygnus_index_adunits[k][0] &&
bid.sizes[j][1] === cygnus_index_adunits[k][1]) {
if (bid.sizes[j][0] == cygnus_index_adunits[k][0] &&
bid.sizes[j][1] == cygnus_index_adunits[k][1]) {
bid.sizes[j][0] = Number(bid.sizes[j][0]);
bid.sizes[j][1] = Number(bid.sizes[j][1]);
validSize = true;
break;
}
}

if (!validSize) {
utils.logMessage(ADAPTER_NAME + " slot excluded from request due to no valid sizes");
continue;
}

Expand All @@ -339,7 +344,8 @@ var IndexExchangeAdapter = function IndexExchangeAdapter() {


var siteID = Number(bid.params.siteID);
if (!siteID) {
if (typeof siteID !== "number" || siteID % 1 != 0 || siteID <= 0) {
utils.logMessage(ADAPTER_NAME + " slot excluded from request due to invalid siteID");
continue;
}
if (siteID && typeof cygnus_index_args.siteID === 'undefined') {
Expand All @@ -349,6 +355,10 @@ var IndexExchangeAdapter = function IndexExchangeAdapter() {
if (utils.hasValidBidRequest(bid.params, requiredParams, ADAPTER_NAME)) {
firstAdUnitCode = bid.placementCode;
var slotID = bid.params[requiredParams[0]];
if ( typeof slotID !== 'string' && typeof slotID !== 'number' ){
utils.logError(ADAPTER_NAME + " bid contains invalid slot ID from " + bid.placementCode + ". Discarding slot");
continue
}

sizeID++;
var size = {
Expand Down Expand Up @@ -443,7 +453,6 @@ var IndexExchangeAdapter = function IndexExchangeAdapter() {
var bid = bidfactory.createBid(1);
bid.cpm = currentCPM / 100;
bid.ad = indexObj[cpmAndSlotId][0];
bid.ad_id = adSlotId;
bid.bidderCode = ADAPTER_CODE;
bid.width = slotObj.width;
bid.height = slotObj.height;
Expand Down
4 changes: 4 additions & 0 deletions test/helpers/index_adapter_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ function _createBidSlot(placementCode, indexSlotID, sizes, config) {
if ( typeof config.tier3SiteID !== 'undefined' ){
bid.params.tier3SiteID = config.tier3SiteID;
}
if ( typeof config.slotSize !== 'undefined' ){
bid.params.size = config.slotSize;
}

//special parameter
if ( typeof(config.missingSlotID) !== 'undefined' ){
Expand All @@ -64,6 +67,7 @@ function _createBidSlot(placementCode, indexSlotID, sizes, config) {
if ( typeof(config.missingSiteID) !== 'undefined' ){
delete bid.params.siteID;
}

return bid;
}

Expand Down
Loading

0 comments on commit caa5370

Please sign in to comment.