Skip to content

Commit

Permalink
Feature/pre1.0 sizes support for ccx bid adapter (#2633)
Browse files Browse the repository at this point in the history
* added ccxAdapter

* add ccxAdapter - lint formatting fixes

* pre 1.0 sizes support
  • Loading branch information
korys authored and snapwich committed May 30, 2018
1 parent 3ee3b16 commit 931c4ed
Show file tree
Hide file tree
Showing 3 changed files with 229 additions and 79 deletions.
60 changes: 42 additions & 18 deletions modules/ccxBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,36 @@ function _getSiteObj () {
}

function _validateSizes (sizeObj, type) {
if (!utils.isArray(sizeObj)) {
if (!utils.isArray(sizeObj) || typeof sizeObj[0] === 'undefined') {
return false
}

if (type === 'video' && (typeof sizeObj[0] === 'undefined' || !utils.isArray(sizeObj[0]) || sizeObj[0].length !== 2)) {
if (type === 'video' && (!utils.isArray(sizeObj[0]) || sizeObj[0].length !== 2)) {
return false
}

let result = true

if (type === 'banner') {
if (typeof sizeObj[0] === 'undefined') {
return false
} else {
let result = true
utils._each(sizeObj, function (size) {
if (!utils.isArray(size) || (size.length !== 2)) {
result = false
}
})
return result
}

if (type === 'old') {
if (!utils.isArray(sizeObj[0]) && sizeObj.length !== 2) {
result = false
} else if (utils.isArray(sizeObj[0])) {
utils._each(sizeObj, function (size) {
if (!utils.isArray(size) || (size.length !== 2)) {
result = false
}
})
return result
}
return result;
}

return true
Expand All @@ -57,20 +67,28 @@ function _buildBid (bid) {
placement.id = bid.bidId
placement.secure = 1

if (utils.deepAccess(bid, 'mediaTypes.banner')) {
let sizes = utils.deepAccess(bid, 'mediaTypes.banner.sizes') || utils.deepAccess(bid, 'mediaTypes.video.playerSize') || utils.deepAccess(bid, 'sizes')

if (utils.deepAccess(bid, 'mediaTypes.banner') || utils.deepAccess(bid, 'mediaType') === 'banner' || (!utils.deepAccess(bid, 'mediaTypes.video') && !utils.deepAccess(bid, 'mediaType'))) {
placement.banner = {'format': []}
let sizes = utils.deepAccess(bid, 'mediaTypes.banner.sizes')
utils._each(sizes, function (size) {
placement.banner.format.push({'w': size[0], 'h': size[1]})
})
} else if (utils.deepAccess(bid, 'mediaTypes.video')) {
if (utils.isArray(sizes[0])) {
utils._each(sizes, function (size) {
placement.banner.format.push({'w': size[0], 'h': size[1]})
})
} else {
placement.banner.format.push({'w': sizes[0], 'h': sizes[1]})
}
} else if (utils.deepAccess(bid, 'mediaTypes.video') || utils.deepAccess(bid, 'mediaType') === 'video') {
placement.video = {}

let size = utils.deepAccess(bid, 'mediaTypes.video.playerSize')

if (typeof size !== 'undefined') {
placement.video.w = size[0][0]
placement.video.h = size[0][1]
if (typeof sizes !== 'undefined') {
if (utils.isArray(sizes[0])) {
placement.video.w = sizes[0][0]
placement.video.h = sizes[0][1]
} else {
placement.video.w = sizes[0]
placement.video.h = sizes[1]
}
}

placement.video.protocols = utils.deepAccess(bid, 'params.video.protocols') || SUPPORTED_VIDEO_PROTOCOLS
Expand Down Expand Up @@ -133,6 +151,12 @@ export const spec = {
utils.logWarn('Bid sizes are invalid.')
}
return isValid
} else if (utils.deepAccess(bid, 'sizes')) {
let isValid = _validateSizes(bid.sizes, 'old')
if (!isValid) {
utils.logWarn('Bid sizes are invalid.')
}
return isValid
} else {
utils.logWarn('Bid sizes are required.')
return false
Expand Down
41 changes: 41 additions & 0 deletions modules/ccxBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,45 @@ Module that connects to Clickonometrics's demand sources
]
}

];

# Pre 1.0 Support

var adUnits = [
{
code: 'test-banner',
mediaType: 'banner',
sizes: [300, 250],
bids: [
{
bidder: "ccx",
params: {
placementId: 3286844
}
}
]
},
{
code: 'test-video',
mediaType: 'video',
sizes: [1920, 1080]
bids: [
{
bidder: "ccx",
params: {
placementId: 3287742,
//following options are not required, default values will be used. Uncomment if you want to use custom values
/*video: {
//check OpenRTB documentation for following options description
protocols: [2, 3, 5, 6], //default
mimes: ["video/mp4", "video/x-flv"], //default
playbackmethod: [1, 2, 3, 4], //default
skip: 1, //default 0
skipafter: 5 //delete this key if skip = 0
}*/
}
}
]
}

];
207 changes: 146 additions & 61 deletions test/spec/modules/ccxBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,42 @@ import { spec } from 'modules/ccxBidAdapter';
import * as utils from 'src/utils';

describe('ccxAdapter', () => {
let bids = [{
adUnitCode: 'banner',
auctionId: '0b9de793-8eda-481e-a548-c187d58b28d9',
bidId: '2e56e1af51a5d7',
bidder: 'ccx',
bidderRequestId: '17e7b9f58a607e',
mediaTypes: {
banner: {
sizes: [[300, 250]]
}
},
params: {
placementId: 607
},
sizes: [[300, 250]],
transactionId: 'aefddd38-cfa0-48ab-8bdd-325de4bab5f9'
},
{
adUnitCode: 'video',
auctionId: '0b9de793-8eda-481e-a548-c187d58b28d9',
bidId: '3u94t90ut39tt3t',
bidder: 'ccx',
bidderRequestId: '23ur20r239r2r',
mediaTypes: {
video: {
playerSize: [[640, 480]]
}
},
params: {
placementId: 608
let bids = [
{
adUnitCode: 'banner',
auctionId: '0b9de793-8eda-481e-a548-c187d58b28d9',
bidId: '2e56e1af51a5d7',
bidder: 'ccx',
bidderRequestId: '17e7b9f58a607e',
mediaTypes: {
banner: {
sizes: [[300, 250]]
}
},
params: {
placementId: 607
},
sizes: [[300, 250]],
transactionId: 'aefddd38-cfa0-48ab-8bdd-325de4bab5f9'
},
sizes: [[640, 480]],
transactionId: 'aefddd38-cfa0-48ab-8bdd-325de4bab5f9'
}];
{
adUnitCode: 'video',
auctionId: '0b9de793-8eda-481e-a548-c187d58b28d9',
bidId: '3u94t90ut39tt3t',
bidder: 'ccx',
bidderRequestId: '23ur20r239r2r',
mediaTypes: {
video: {
playerSize: [[640, 480]]
}
},
params: {
placementId: 608
},
sizes: [[640, 480]],
transactionId: 'aefddd38-cfa0-48ab-8bdd-325de4bab5f9'
}
];
describe('isBidRequestValid', () => {
it('Valid bid requests', () => {
expect(spec.isBidRequestValid(bids[0])).to.be.true;
Expand All @@ -63,8 +65,16 @@ describe('ccxAdapter', () => {
bidsClone[1].mediaTypes.video.sizes = [640, 480];
expect(spec.isBidRequestValid(bidsClone[1])).to.be.false;
});
it('Valid bid reqeust - old style sizes', () => {
let bidsClone = utils.deepClone(bids);
delete (bidsClone[0].mediaTypes);
delete (bidsClone[1].mediaTypes);
expect(spec.isBidRequestValid(bidsClone[0])).to.be.true;
expect(spec.isBidRequestValid(bidsClone[1])).to.be.true;
bidsClone[0].sizes = [300, 250];
expect(spec.isBidRequestValid(bidsClone[0])).to.be.true;
});
});

describe('buildRequests', function () {
it('No valid bids', function () {
expect(spec.buildRequests([])).to.be.empty;
Expand Down Expand Up @@ -163,41 +173,116 @@ describe('ccxAdapter', () => {

expect(data.imp).to.deep.have.same.members(imps);
});
});
it('Valid bid request - sizes old style', function () {
let bidsClone = utils.deepClone(bids);
delete (bidsClone[0].mediaTypes);
delete (bidsClone[1].mediaTypes);
bidsClone[0].mediaType = 'banner';
bidsClone[1].mediaType = 'video';

let response = {
id: '0b9de793-8eda-481e-a548-c187d58b28d9',
seatbid: [
{bid: [
let imps = [
{
id: '2e56e1af51a5d7_221',
impid: '2e56e1af51a5d7',
price: 8.1,
adid: '221',
adm: '<script>TEST</script>',
adomain: ['clickonometrics.com'],
crid: '221',
w: 300,
h: 250,
banner: {
format: [
{
w: 300,
h: 250
}
]
},
ext: {
type: 'standard'
}
pid: 607
},
id: '2e56e1af51a5d7',
secure: 1
},
{
id: '2e56e1af51a5d8_222',
impid: '2e56e1af51a5d8',
price: 5.68,
adid: '222',
adm: '<xml>',
adomain: ['clickonometrics.com'],
crid: '222',
w: 640,
h: 480,
video: {
w: 640,
h: 480,
protocols: [2, 3, 5, 6],
mimes: ['video/mp4', 'video/x-flv'],
playbackmethod: [1, 2, 3, 4],
skip: 0
},
id: '3u94t90ut39tt3t',
secure: 1,
ext: {
type: 'video'
pid: 608
}
}
]}
];

let response = spec.buildRequests(bidsClone, {'bids': bidsClone});
let data = JSON.parse(response.data);

expect(data.imp).to.deep.have.same.members(imps);
});
it('Valid bid request - sizes old style - no media type', function () {
let bidsClone = utils.deepClone(bids);
delete (bidsClone[0].mediaTypes);
delete (bidsClone[1]);

let imps = [
{
banner: {
format: [
{
w: 300,
h: 250
}
]
},
ext: {
pid: 607
},
id: '2e56e1af51a5d7',
secure: 1
}
];

let response = spec.buildRequests(bidsClone, {'bids': bidsClone});
let data = JSON.parse(response.data);

expect(data.imp).to.deep.have.same.members(imps);
});
});

let response = {
id: '0b9de793-8eda-481e-a548-c187d58b28d9',
seatbid: [
{
bid: [
{
id: '2e56e1af51a5d7_221',
impid: '2e56e1af51a5d7',
price: 8.1,
adid: '221',
adm: '<script>TEST</script>',
adomain: ['clickonometrics.com'],
crid: '221',
w: 300,
h: 250,
ext: {
type: 'standard'
}
},
{
id: '2e56e1af51a5d8_222',
impid: '2e56e1af51a5d8',
price: 5.68,
adid: '222',
adm: '<xml>',
adomain: ['clickonometrics.com'],
crid: '222',
w: 640,
h: 480,
ext: {
type: 'video'
}
}
]
}
],
cur: 'PLN',
ext: {
Expand Down

0 comments on commit 931c4ed

Please sign in to comment.