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 support for mediaTypes.video #2

Merged
merged 1 commit into from
Aug 8, 2020
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
29 changes: 20 additions & 9 deletions modules/tripleliftBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export const tripleliftAdapterSpec = {
supportedMediaTypes: [BANNER, VIDEO],
isBidRequestValid: function (bid) {
if (bid.mediaTypes.video) {
if (!bid.params.video) return false;
let video = _getORTBVideo(bid);
if (!video.w || !video.h) return false;
}
return typeof bid.params.inventoryCode !== 'undefined';
},
Expand Down Expand Up @@ -110,17 +111,16 @@ function _getSyncType(syncOptions) {
function _buildPostBody(bidRequests) {
let data = {};
let { schain } = bidRequests[0];
data.imp = bidRequests.map(function(bid, index) {
data.imp = bidRequests.map(function(bidRequest, index) {
let imp = {
id: index,
tagid: bid.params.inventoryCode,
floor: _getFloor(bid)
tagid: bidRequest.params.inventoryCode,
floor: _getFloor(bidRequest)
};

if (bid.mediaTypes.video) {
imp.video = bid.params.video;
} else if (bid.mediaTypes.banner) {
imp.banner = { format: _sizes(bid.sizes) };
if (bidRequest.mediaTypes.video) {
imp.video = _getORTBVideo(bidRequest);
} else if (bidRequest.mediaTypes.banner) {
imp.banner = { format: _sizes(bidRequest.sizes) };
};
return imp;
});
Expand All @@ -145,6 +145,17 @@ function _buildPostBody(bidRequests) {
return data;
}

function _getORTBVideo(bidRequest) {
// give precedent to mediaTypes.video
let video = { ...bidRequest.params.video, ...bidRequest.mediaTypes.video };
if (!video.w) video.w = video.playerSize[0][0];
if (!video.h) video.h = video.playerSize[0][1];
if (video.context === 'instream') video.placement = 1;
// clean up oRTB object
delete video.playerSize;
return video;
}

function _getFloor (bid) {
let floor = null;
if (typeof bid.getFloor === 'function') {
Expand Down
10 changes: 6 additions & 4 deletions test/spec/modules/tripleliftBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('triplelift adapter', function () {
instreamBid = {
bidder: 'triplelift',
params: {
inventoryCode: '12345',
inventoryCode: 'insteam_test',
floor: 1.0,
video: {
mimes: ['video/mp4'],
Expand Down Expand Up @@ -87,7 +87,9 @@ describe('triplelift adapter', function () {
});

it('should return false when required params are not passed - instream', function () {
delete instreamBid.params.video;
delete instreamBid.mediaTypes.playerSize;
delete instreamBid.params.video.w;
delete instreamBid.params.video.h;
expect(tripleliftAdapterSpec.isBidRequestValid(instreamBid)).to.equal(false);
});
});
Expand Down Expand Up @@ -137,7 +139,7 @@ describe('triplelift adapter', function () {
{
bidder: 'triplelift',
params: {
inventoryCode: '12345-instream',
inventoryCode: 'insteam_test',
floor: 1.0,
video: {
mimes: ['video/mp4'],
Expand Down Expand Up @@ -217,7 +219,7 @@ describe('triplelift adapter', function () {
expect(payload.imp[0].tagid).to.equal('12345');
expect(payload.imp[0].floor).to.equal(1.0);
expect(payload.imp[0].banner.format).to.deep.equal([{w: 300, h: 250}, {w: 300, h: 600}]);
expect(payload.imp[1].tagid).to.equal('12345-instream');
expect(payload.imp[1].tagid).to.equal('insteam_test');
expect(payload.imp[1].floor).to.equal(1.0);
expect(payload.imp[1].video).to.exist.and.to.be.a('object');
});
Expand Down