Skip to content

Commit

Permalink
Add moulty mediatypes support
Browse files Browse the repository at this point in the history
  • Loading branch information
m.sorochuk committed Jan 23, 2018
1 parent 5d427d4 commit 95fe42d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
37 changes: 26 additions & 11 deletions modules/vertamediaBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as utils from 'src/utils';
import {registerBidder} from 'src/adapters/bidderFactory';
import {VIDEO, BANNER} from 'src/mediaTypes';
import {Renderer} from 'src/Renderer';
import findIndex from 'core-js/library/fn/array/find-index';

const URL = '//hb2.vertamedia.com/auction/';
const BIDDER_CODE = 'vertamedia';
Expand All @@ -27,7 +28,7 @@ export const spec = {
bidderRequest,
method: 'GET',
url: URL
}
};
});
},

Expand All @@ -40,9 +41,6 @@ export const spec = {
interpretResponse: function (serverResponse, {bidderRequest}) {
serverResponse = serverResponse.body;
const isInvalidValidResp = !serverResponse || !serverResponse.bids || !serverResponse.bids.length;
const videoMediaType = utils.deepAccess(bidderRequest.bids[0], 'mediaTypes.video');
const context = utils.deepAccess(bidderRequest.bids[0], 'mediaTypes.video.context');
const mediaType = !videoMediaType ? DISPLAY : context === OUTSTREAM ? OUTSTREAM : VIDEO;

let bids = [];

Expand All @@ -56,18 +54,23 @@ export const spec = {
}

serverResponse.bids.forEach(serverBid => {
if (serverBid.cpm !== 0) {
const bid = createBid(mediaType, serverBid);
const requestId = findIndex(bidderRequest.bids, (bidRequest) => {
return bidRequest.bidId === serverBid.requestId;
});

if (serverBid.cpm !== 0 && requestId !== -1) {
const bid = createBid(serverBid, getMediaType(bidderRequest.bids[requestId]));

bids.push(bid);
}
});

return bids;
},
}
};

/**
* Prepare all parameters for request
* Parse mediaType
* @param bid {object}
* @returns {object}
*/
Expand All @@ -85,6 +88,18 @@ function prepareRTBRequestParams(bid) {
};
}

/**
* Prepare all parameters for request
* @param bidderRequest {object}
* @returns {object}
*/
function getMediaType(bidderRequest) {
const videoMediaType = utils.deepAccess(bidderRequest, 'mediaTypes.video');
const context = utils.deepAccess(bidderRequest, 'mediaTypes.video.context');

return !videoMediaType ? DISPLAY : context === OUTSTREAM ? OUTSTREAM : VIDEO;
}

/**
* Prepare size for request
* @param requestSizes {array}
Expand All @@ -108,11 +123,11 @@ function getSize(requestSizes) {

/**
* Configure new bid by response
* @param mediaType {string}
* @param bidResponse {object}
* @param mediaType {Object}
* @returns {object}
*/
function createBid(mediaType, bidResponse) {
function createBid(bidResponse, mediaType) {
let bid = {
requestId: bidResponse.requestId,
creativeId: bidResponse.cmpId,
Expand Down Expand Up @@ -155,7 +170,7 @@ function newRenderer(requestId) {
const renderer = Renderer.install({
id: requestId,
url: '//player.vertamedia.com/outstream-unit/2.01/outstream.min.js',
loaded: false,
loaded: false
});

renderer.setRender(outstreamRender);
Expand Down
7 changes: 4 additions & 3 deletions test/spec/modules/vertamediaBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ const SERVER_DISPLAY_RESPONSE = {

const videoBidderRequest = {
bidderCode: 'bidderCode',
bids: [{mediaTypes: {video: {}}}]
bids: [{mediaTypes: {video: {}}, bidId: '2e41f65424c87c'}]
};

const displayBidderRequest = {
bidderCode: 'bidderCode',
bids: [{}]
bids: [{bidId: '2e41f65424c87c'}]
};

const videoEqResponse = [{
Expand Down Expand Up @@ -194,7 +194,8 @@ describe('vertamediaBidAdapter', () => {

function bidServerResponseCheck() {
const result = spec.interpretResponse({body: serverResponse}, {bidderRequest});

console.log(result);
console.log(eqResponse);
expect(result).to.deep.equal(eqResponse);
}

Expand Down

0 comments on commit 95fe42d

Please sign in to comment.