Skip to content

Commit

Permalink
cedato bid adapter instream video support (#4153)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkh13 authored and robertrmartinez committed Sep 16, 2019
1 parent 29066dd commit f60799f
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 35 deletions.
119 changes: 88 additions & 31 deletions modules/cedatoBidAdapter.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 } from '../src/mediaTypes';
import { BANNER, VIDEO } from '../src/mediaTypes';

const BIDDER_CODE = 'cedato';
const BID_URL = '//h.cedatoplayer.com/hb';
Expand All @@ -14,7 +14,7 @@ const NET_REVENUE = true;

export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER],
supportedMediaTypes: [BANNER, VIDEO],

isBidRequestValid: function(bid) {
return !!(
Expand All @@ -31,19 +31,23 @@ export const spec = {
const params = req.params;
const at = FIRST_PRICE;
const site = { id: params.player_id, domain: document.domain };
const device = { ua: navigator.userAgent, ip: '' };
const device = { ua: navigator.userAgent };
const user = { id: getUserID() }
const currency = CURRENCY;
const tmax = bidderRequest.timeout;

const imp = bidRequests.map(req => {
const banner = { 'format': getFormats(utils.deepAccess(req, 'mediaTypes.banner.sizes')) };
const banner = getMediaType(req, 'banner');
const video = getMediaType(req, 'video');
const bidfloor = params.bidfloor;
const bidId = req.bidId;
const adUnitCode = req.adUnitCode;

return {
bidId,
banner,
video,
adUnitCode,
bidfloor,
};
});
Expand All @@ -68,38 +72,24 @@ export const spec = {

return {
method: 'POST',
url: BID_URL,
url: params.bid_url || BID_URL,
data: JSON.stringify(payload),
bidderRequest
};
},

interpretResponse: function(resp) {
if (resp.body === '') return [];

const bids = resp.body.seatbid[0].bid.map(bid => {
const cpm = bid.price;
const requestId = bid.uuid;
const width = bid.w;
const height = bid.h;
const creativeId = bid.crid;
const dealId = bid.dealid;
const currency = resp.body.cur;
const netRevenue = NET_REVENUE;
const ttl = TTL;
const ad = bid.adm;
interpretResponse: function(resp, {bidderRequest}) {
resp = resp.body;
const bids = [];

return {
cpm,
requestId,
width,
height,
creativeId,
dealId,
currency,
netRevenue,
ttl,
ad,
};
if (!resp) {
return bids;
}

resp.seatbid[0].bid.map(serverBid => {
const bid = newBid(serverBid, bidderRequest);
bid.currency = resp.cur;
bids.push(bid);
});

return bids;
Expand All @@ -116,6 +106,73 @@ export const spec = {
}
}

function getMediaType(req, type) {
const { mediaTypes } = req;

if (!mediaTypes) {
return;
}

switch (type) {
case 'banner':
if (mediaTypes.banner) {
const { sizes } = mediaTypes.banner;
return {
format: getFormats(sizes)
};
}
break;

case 'video':
if (mediaTypes.video) {
const { playerSize, context } = mediaTypes.video;
return {
context: context,
format: getFormats(playerSize)
};
}
}
}

function newBid(serverBid, bidderRequest) {
const bidRequest = utils.getBidRequest(serverBid.uuid, [bidderRequest]);

const cpm = serverBid.price;
const requestId = serverBid.uuid;
const width = serverBid.w;
const height = serverBid.h;
const creativeId = serverBid.crid;
const dealId = serverBid.dealid;
const mediaType = serverBid.media_type;
const netRevenue = NET_REVENUE;
const ttl = TTL;

const bid = {
cpm,
requestId,
width,
height,
mediaType,
creativeId,
dealId,
netRevenue,
ttl,
};

if (mediaType == 'video') {
const videoContext = utils.deepAccess(bidRequest, 'mediaTypes.video.context');

if (videoContext == 'instream') {
bid.vastUrl = serverBid.vast_url;
bid.vastImpUrl = serverBid.notify_url;
}
} else {
bid.ad = serverBid.adm;
}

return bid;
}

const getSync = (type, gdprConsent) => {
const uuid = getUserID();
const syncUrl = SYNC_URL;
Expand Down
12 changes: 8 additions & 4 deletions test/spec/modules/cedatoBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {spec} from 'modules/cedatoBidAdapter';
describe('the cedato adapter', function () {
function getValidBidObject() {
return {
bidId: 123,
bidId: '2f4a613a702b6c',
mediaTypes: {
banner: {
sizes: [[300, 250]]
Expand Down Expand Up @@ -48,9 +48,10 @@ describe('the cedato adapter', function () {
});

describe('interpretResponse', function() {
var serverResponse;
var bid, serverResponse, bidderRequest;

beforeEach(function() {
bid = getValidBidObject();
serverResponse = {
body: {
bidid: '0.36157306192821',
Expand All @@ -65,7 +66,7 @@ describe('the cedato adapter', function () {
},
id: '0.75549202124378',
adomain: 'cedato.com',
uuid: '2f4a613a702b6c',
uuid: bid.bidId,
crid: '1450133326',
adm: "<div id=\"cedato-unit\"></div>\n<script src=\"https://p.cedatoplayer.com/zplayer.js?p=952030718&cb=874433&d=localhost\" type=\"text/javascript\"></script>\n<img src='//h.cedatoplayer.com/hbwon?cb=874433&p=0.1&pi=952030718&w=300&h=250&s=952030718&d=localhost&u=a4657bf1-c373-4676-b79a-0d9de0129e38&ab=2' width=\"1\" height=\"1\"/>\n",
h: 250,
Expand All @@ -77,10 +78,13 @@ describe('the cedato adapter', function () {
cur: 'USD'
}
};
bidderRequest = {
bids: [bid]
};
});

it('should return an array of bid responses', function() {
var responses = spec.interpretResponse(serverResponse);
var responses = spec.interpretResponse(serverResponse, {bidderRequest});
expect(responses).to.be.an('array').with.length(1);
});
});
Expand Down

0 comments on commit f60799f

Please sign in to comment.