Skip to content

Commit

Permalink
Added new types of traffic Colossus SSP adapter (prebid#2281)
Browse files Browse the repository at this point in the history
* add video&native traffic colossus ssp

* Native obj validation

* Native obj validation #2

* Added size field in requests

* fixed test
  • Loading branch information
Bill Newman authored and jsnellbaker committed Apr 26, 2018
1 parent baea840 commit 5c14e9c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 54 deletions.
71 changes: 25 additions & 46 deletions modules/colossussspBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,39 @@
import { registerBidder } from 'src/adapters/bidderFactory';
import { BANNER, NATIVE, VIDEO } from 'src/mediaTypes';
import * as utils from 'src/utils';

const BIDDER_CODE = 'colossusssp';
const URL = '//colossusssp.com/?c=o&m=multi';
const URL_SYNC = '//colossusssp.com/?c=o&m=cookie';

let sizeObj = {
'468x60': 1,
'728x90': 2,
'300x600': 10,
'300x250': 15,
'300x100': 19,
'320x50': 43,
'300x50': 44,
'300x300': 48,
'300x1050': 54,
'970x90': 55,
'970x250': 57,
'1000x90': 58,
'320x80': 59,
'640x480': 65,
'320x480': 67,
'320x320': 72,
'320x160': 73,
'480x300': 83,
'970x310': 94,
'970x210': 96,
'480x320': 101,
'768x1024': 102,
'1000x300': 113,
'320x100': 117,
'800x250': 118,
'200x600': 119
};
function isBidResponseValid(bid) {
if (!bid.requestId || !bid.cpm || !bid.creativeId || !bid.ttl || !bid.currency) {
return false;
}

utils._each(sizeObj, (item, key) => sizeObj[item] = key);
switch (bid.mediaType) {
case BANNER:
return Boolean(bid.width && bid.height && bid.ad);
case VIDEO:
return Boolean(bid.vastUrl);
case NATIVE:
return Boolean(bid.native);
default:
return false;
}
}

export const spec = {
code: BIDDER_CODE,

supportedMediaTypes: [BANNER, VIDEO, NATIVE],
/**
* Determines whether or not the given bid request is valid.
*
* @param {object} bid The bid to validate.
* @return boolean True if this is a valid bid, and false otherwise.
*/
isBidRequestValid: (bid) => {
return (!isNaN(bid.params.placement_id) &&
((bid.params.sizes !== undefined && bid.params.sizes.length > 0 && bid.params.sizes.some((sizeIndex) => sizeObj[sizeIndex] !== undefined)) ||
(bid.sizes !== undefined && bid.sizes.length > 0 && bid.sizes.map((size) => `${size[0]}x${size[1]}`).some((size) => sizeObj[size] !== undefined))));
return Boolean(bid.bidId && bid.params && !isNaN(bid.params.placement_id));
},

/**
Expand Down Expand Up @@ -78,10 +63,12 @@ export const spec = {
};
for (let i = 0; i < validBidRequests.length; i++) {
let bid = validBidRequests[i];
let placement = {};
placement['placementId'] = bid.params.placement_id;
placement['bidId'] = bid.bidId;
placement['sizes'] = bid.sizes;
let placement = {
placementId: bid.params.placement_id,
bidId: bid.bidId,
sizes: bid.sizes,
traffic: bid.params.traffic || BANNER
};
placements.push(placement);
}
return {
Expand All @@ -103,15 +90,7 @@ export const spec = {
serverResponse = serverResponse.body;
for (let i = 0; i < serverResponse.length; i++) {
let resItem = serverResponse[i];
if (resItem.width && !isNaN(resItem.width) &&
resItem.height && !isNaN(resItem.height) &&
resItem.requestId && typeof resItem.requestId === 'string' &&
resItem.cpm && !isNaN(resItem.cpm) &&
resItem.ad && typeof resItem.ad === 'string' &&
resItem.ttl && !isNaN(resItem.ttl) &&
resItem.creativeId && typeof resItem.creativeId === 'string' &&
resItem.netRevenue && typeof resItem.netRevenue === 'boolean' &&
resItem.currency && typeof resItem.currency === 'string') {
if (isBidResponseValid(resItem)) {
response.push(resItem);
}
}
Expand Down
3 changes: 2 additions & 1 deletion modules/colossussspBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ Module that connects to Colossus SSP demand sources
bids: [{
bidder: 'colossusssp',
params: {
placement_id: 0
placement_id: 0,
traffic: 'banner'
}
}]
}
Expand Down
13 changes: 6 additions & 7 deletions test/spec/modules/colossussspBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,13 @@ describe('ColossussspAdapter', () => {
};

describe('isBidRequestValid', () => {
it('Should return true when placement_id can be cast to a number, and when at least one of the sizes passed is allowed', () => {
it('Should return true when placement_id can be cast to a number', () => {
expect(spec.isBidRequestValid(bid)).to.be.true;
});
it('Should return false when placement_id is not a number', () => {
bid.params.placement_id = 'aaa';
expect(spec.isBidRequestValid(bid)).to.be.false;
});
it('Should return false when the sizes are not allowed', () => {
bid.sizes = [[1, 1]];
expect(spec.isBidRequestValid(bid)).to.be.false;
});
});

describe('buildRequests', () => {
Expand Down Expand Up @@ -56,9 +52,10 @@ describe('ColossussspAdapter', () => {
let placements = data['placements'];
for (let i = 0; i < placements.length; i++) {
let placement = placements[i];
expect(placement).to.have.all.keys('placementId', 'bidId', 'sizes');
expect(placement).to.have.all.keys('placementId', 'bidId', 'traffic', 'sizes');
expect(placement.placementId).to.be.a('number');
expect(placement.bidId).to.be.a('string');
expect(placement.traffic).to.be.a('string');
expect(placement.sizes).to.be.an('array');
}
});
Expand All @@ -72,6 +69,7 @@ describe('ColossussspAdapter', () => {
let resObject = {
body: [ {
requestId: '123',
mediaType: 'banner',
cpm: 0.3,
width: 320,
height: 50,
Expand All @@ -88,7 +86,7 @@ describe('ColossussspAdapter', () => {
for (let i = 0; i < serverResponses.length; i++) {
let dataItem = serverResponses[i];
expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'ad', 'ttl', 'creativeId',
'netRevenue', 'currency');
'netRevenue', 'currency', 'mediaType');
expect(dataItem.requestId).to.be.a('string');
expect(dataItem.cpm).to.be.a('number');
expect(dataItem.width).to.be.a('number');
Expand All @@ -98,6 +96,7 @@ describe('ColossussspAdapter', () => {
expect(dataItem.creativeId).to.be.a('string');
expect(dataItem.netRevenue).to.be.a('boolean');
expect(dataItem.currency).to.be.a('string');
expect(dataItem.mediaType).to.be.a('string');
}
it('Returns an empty array if invalid response is passed', () => {
serverResponses = spec.interpretResponse('invalid_response');
Expand Down

0 comments on commit 5c14e9c

Please sign in to comment.