Skip to content

Commit

Permalink
Merge pull request #2 from sdao-tl/update-tl-adapter-md
Browse files Browse the repository at this point in the history
add support for mediaTypes.video
  • Loading branch information
sdao-tl authored Aug 8, 2020
2 parents e4f94c4 + f6adf06 commit ba29729
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
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

0 comments on commit ba29729

Please sign in to comment.