Skip to content

Commit

Permalink
Add Video Support for Datablocks Bid Adapter (prebid#4195)
Browse files Browse the repository at this point in the history
* add datablocks Analytics and Bidder Adapters

* remove preload param

* remove preloadid

* better coverage of tests

* better coverage

* IE doesn't support array.find

* lint test

* update example host

* native asset id should be integer

* add datablocks Video

* remove isInteger

* skip if empty
  • Loading branch information
htang555 authored and robertrmartinez committed Sep 24, 2019
1 parent 991b94d commit 4be8495
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 7 deletions.
54 changes: 50 additions & 4 deletions modules/datablocksBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as utils from '../src/utils';
import { registerBidder } from '../src/adapters/bidderFactory';
import { BANNER, NATIVE } from '../src/mediaTypes';
import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes';
import { parse as parseUrl } from '../src/url';
const NATIVE_MAP = {
'body': 2,
Expand Down Expand Up @@ -43,12 +43,17 @@ const NATIVE_IMAGE = [{
}
}];

const VIDEO_PARAMS = ['mimes', 'minduration', 'maxduration', 'protocols', 'w', 'h', 'startdelay',
'placement', 'linearity', 'skip', 'skipmin', 'skipafter', 'sequence', 'battr', 'maxextended',
'minbitrate', 'maxbitrate', 'boxingallowed', 'playbackmethod', 'playbackend', 'delivery',
'pos', 'companionad', 'api', 'companiontype', 'ext'];

export const spec = {
supportedMediaTypes: [BANNER, NATIVE],
supportedMediaTypes: [BANNER, NATIVE, VIDEO],
code: 'datablocks',
isBidRequestValid: function(bid) {
return !!(bid.params.host && bid.params.sourceId &&
bid.mediaTypes && (bid.mediaTypes.banner || bid.mediaTypes.native));
bid.mediaTypes && (bid.mediaTypes.banner || bid.mediaTypes.native || bid.mediaTypes.video));
},
buildRequests: function(validBidRequests, bidderRequest) {
if (!validBidRequests.length) { return []; }
Expand Down Expand Up @@ -142,6 +147,43 @@ export const spec = {
request: JSON.stringify({native: {assets: nativeAssets}})
};
}
} else if (utils.deepAccess(bidRequest, 'mediaTypes.video')) {
let video = bidRequest.mediaTypes.video;
let sizes = video.playerSize || bidRequest.sizes || [];
if (sizes.length && Array.isArray(sizes[0])) {
imp.video = {
w: sizes[0][0],
h: sizes[0][1]
};
} else if (sizes.length == 2 && !Array.isArray(sizes[0])) {
imp.video = {
w: sizes[0],
h: sizes[1]
};
} else {
return;
}

if (video.durationRangeSec) {
if (Array.isArray(video.durationRangeSec)) {
if (video.durationRangeSec.length == 1) {
imp.video.maxduration = video.durationRangeSec[0];
} else if (video.durationRangeSec.length == 2) {
imp.video.minduration = video.durationRangeSec[0];
imp.video.maxduration = video.durationRangeSec[1];
}
} else {
imp.video.maxduration = video.durationRangeSec;
}
}

if (bidRequest.params.video) {
Object.keys(bidRequest.params.video).forEach(k => {
if (VIDEO_PARAMS.indexOf(k) > -1) {
imp.video[k] = bidRequest.params.video[k];
}
})
}
}
let host = bidRequest.params.host;
let sourceId = bidRequest.params.sourceId;
Expand Down Expand Up @@ -181,7 +223,6 @@ export const spec = {
}
})
});

return requests;

function RtbRequest(device, site, imps) {
Expand Down Expand Up @@ -276,6 +317,11 @@ export const spec = {
}
})
br.native = result;
} else if (imp.video) {
br.mediaType = VIDEO;
br.width = rtbBid.w;
br.height = rtbBid.h;
if (rtbBid.adm) { br.vastXml = rtbBid.adm; } else if (rtbBid.nurl) { br.vastUrl = rtbBid.nurl; }
}
return br;
});
Expand Down
21 changes: 20 additions & 1 deletion modules/datablocksBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Maintainer: support@datablocks.net
# Description

Connects to Datablocks Version 5 Platform
Banner Native and
Banner Native and Video


# Test Parameters
Expand Down Expand Up @@ -47,6 +47,25 @@ Banner Native and
sourceId: 12345,
host: 'prebid.datablocks.net'
}
}, {
code: 'video-div',
mediaTypes : {
video: {
playerSize:[500,400],
durationRangeSec:[15,30],
context: "linear"
}
},
bids: [
{
bidder: 'datablocks',
params: {
sourceId: 12345,
host: 'prebid.datablocks.net',
video: {
mimes:["video/flv"]
}
}
}
]
}
Expand Down
51 changes: 49 additions & 2 deletions test/spec/modules/datablocksBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,35 @@ let nativeBid = {
transactionId: '0a4e9788-4def-4b94-bc25-564d7cac99f6'
}

let videoBid = {
adUnitCode: '/19968336/header-bid-tag-0',
auctionId: '160c78a4-f808-410f-b682-d8728f3a79e1',
bidId: '332045ee374b99',
bidder: 'datablocks',
bidderRequestId: '15d9012765e36d',
mediaTypes: {
video: {
context: 'instream',
playerSize: [501, 400],
durationRangeSec: [15, 60]
}
},
params: {
sourceId: 7560,
host: 'v5demo.datablocks.net',
video: {
minduration: 14
}
},
transactionId: '0a4e9788-4def-4b94-bc25-564d7cac99f7'
}

const bidderRequest = {
auctionId: '8bfef1be-d3ac-4d18-8859-754c7b4cf017',
auctionStart: Date.now(),
biddeCode: 'datablocks',
bidderRequestId: '10c47a5fc3c41',
bids: [bid, bid2, nativeBid],
bids: [bid, bid2, nativeBid, videoBid],
refererInfo: {
numIframes: 0,
reachedTop: true,
Expand Down Expand Up @@ -140,6 +163,18 @@ let resObject = {
crid: '177432',
cat: [],
api: []
}, {
id: '1090738575',
impid: '15d9012765e36f',
price: 25.000000,
cid: '12345',
adid: '12345',
crid: '123456',
nurl: 'http://click.v5demo.datablocks.net/m//?fcid=435235435432',
cat: [],
api: [],
w: 500,
h: 400
}]
}],
cur: 'USD',
Expand Down Expand Up @@ -175,6 +210,11 @@ let bidRequest = {
native: {request: '{"native":{"assets":[{"id":"1","required":true,"title":{"len":140}},{"id":"2","required":true,"data":{"type":2}},{"id":"3","img":{"w":728,"h":90,"type":3}}]}}'},
secure: false,
tagid: '/19968336/header-bid-tag-0'
}, {
id: '15d9012765e36f',
video: {w: 500, h: 400, minduration: 15, maxduration: 60},
secure: false,
tagid: '/19968336/header-bid-tag-0'
}],
site: {
domain: '',
Expand All @@ -198,7 +238,7 @@ describe('DatablocksAdapter', function() {
});

describe('buildRequests', function() {
let requests = spec.buildRequests([bid, bid2, nativeBid], bidderRequest);
let requests = spec.buildRequests([bid, bid2, nativeBid, videoBid], bidderRequest);
it('Creates an array of request objects', function() {
expect(requests).to.be.an('array').that.is.not.empty;
});
Expand Down Expand Up @@ -232,6 +272,9 @@ describe('DatablocksAdapter', function() {
expect(imp.native.request).to.be.a('string');
let native = JSON.parse(imp.native.request);
expect(native).to.be.a('object');
} else if (imp.video) {
expect(imp).to.have.all.keys('video', 'id', 'secure', 'tagid');
expect(imp.video).to.have.all.keys('w', 'h', 'minduration', 'maxduration')
} else {
expect(true).to.equal(false);
}
Expand Down Expand Up @@ -276,6 +319,10 @@ describe('DatablocksAdapter', function() {
expect(dataItem.native.title).to.be.a('string');
expect(dataItem.native.body).to.be.a('string');
expect(dataItem.native.clickUrl).to.be.a('string');
} else if (dataItem.mediaType == 'video') {
expect(dataItem.vastUrl).to.be.a('string');
expect(dataItem.width).to.be.a('number');
expect(dataItem.height).to.be.a('number');
}
}
it('Returns an empty array if invalid response is passed', function() {
Expand Down

0 comments on commit 4be8495

Please sign in to comment.