diff --git a/modules/cedatoBidAdapter.js b/modules/cedatoBidAdapter.js index 155e6eda107..d81ae858869 100644 --- a/modules/cedatoBidAdapter.js +++ b/modules/cedatoBidAdapter.js @@ -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'; @@ -14,7 +14,7 @@ const NET_REVENUE = true; export const spec = { code: BIDDER_CODE, - supportedMediaTypes: [BANNER], + supportedMediaTypes: [BANNER, VIDEO], isBidRequestValid: function(bid) { return !!( @@ -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, }; }); @@ -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; @@ -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; diff --git a/test/spec/modules/cedatoBidAdapter_spec.js b/test/spec/modules/cedatoBidAdapter_spec.js index d6c1333c262..969c06a64a2 100644 --- a/test/spec/modules/cedatoBidAdapter_spec.js +++ b/test/spec/modules/cedatoBidAdapter_spec.js @@ -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]] @@ -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', @@ -65,7 +66,7 @@ describe('the cedato adapter', function () { }, id: '0.75549202124378', adomain: 'cedato.com', - uuid: '2f4a613a702b6c', + uuid: bid.bidId, crid: '1450133326', adm: "
\n\n\n", h: 250, @@ -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); }); });