Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(module): multi size request #5007

Merged
merged 3 commits into from
Apr 2, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 52 additions & 42 deletions modules/vidazooBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as utils from '../src/utils.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {BANNER} from '../src/mediaTypes.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER } from '../src/mediaTypes.js';

export const URL = 'https://prebid.cootlogix.com';
const BIDDER_CODE = 'vidazoo';
const CURRENCY = 'USD';
Expand All @@ -19,25 +20,29 @@ function isBidRequestValid(bid) {
return !!(params.cId && params.pId);
}

function buildRequest(bid, topWindowUrl, size, bidderRequest) {
const {params, bidId} = bid;
const {bidFloor, cId, pId, ext} = params;
// Prebid's util function returns AppNexus style sizes (i.e. 300x250)
const [width, height] = size.split('x');

const dto = {
method: 'GET',
url: `${URL}/prebid/${cId}`,
data: {
url: encodeURIComponent(topWindowUrl),
cb: Date.now(),
bidFloor: bidFloor,
bidId: bidId,
publisherId: pId,
consent: bidderRequest.gdprConsent && bidderRequest.gdprConsent.consentString,
width,
height
function buildRequest(bid, topWindowUrl, sizes, bidderRequest) {
const { params, bidId } = bid;
const { bidFloor, cId, pId, ext } = params;
let data = {
url: encodeURIComponent(topWindowUrl),
cb: Date.now(),
bidFloor: bidFloor,
bidId: bidId,
publisherId: pId,
sizes: sizes,
};
if (bidderRequest.gdprConsent) {
if (bidderRequest.gdprConsent.consentString) {
data.gdprConsent = bidderRequest.gdprConsent.consentString;
}
if (bidderRequest.gdprConsent.gdprApplies !== undefined) {
data.gdpr = bidderRequest.gdprConsent.gdprApplies ? 1 : 0;
}
}
const dto = {
method: 'POST',
url: `${URL}/prebid/multi/${cId}`,
data: data
};

utils._each(ext, (value, key) => {
Expand All @@ -52,10 +57,8 @@ function buildRequests(validBidRequests, bidderRequest) {
const requests = [];
validBidRequests.forEach(validBidRequest => {
const sizes = utils.parseSizesInput(validBidRequest.sizes);
sizes.forEach(size => {
const request = buildRequest(validBidRequest, topWindowUrl, size, bidderRequest);
requests.push(request);
});
const request = buildRequest(validBidRequest, topWindowUrl, sizes, bidderRequest);
requests.push(request);
});
return requests;
}
Expand All @@ -64,30 +67,37 @@ function interpretResponse(serverResponse, request) {
if (!serverResponse || !serverResponse.body) {
return [];
}
const {creativeId, ad, price, exp} = serverResponse.body;
if (!ad || !price) {
return [];
}
const {bidId, width, height} = request.data;
const { bidId } = request.data;
const { results } = serverResponse.body;

let output = [];

try {
return [{
requestId: bidId,
cpm: price,
width: width,
height: height,
creativeId: creativeId,
currency: CURRENCY,
netRevenue: true,
ttl: exp || TTL_SECONDS,
ad: ad
}];
results.forEach(result => {
const { creativeId, ad, price, exp, width, height, currency } = result;
if (!ad || !price) {
return;
}
output.push({
requestId: bidId,
cpm: price,
width: width,
height: height,
creativeId: creativeId,
currency: currency || CURRENCY,
netRevenue: true,
ttl: exp || TTL_SECONDS,
ad: ad
})
});
return output;
} catch (e) {
return [];
}
}

function getUserSyncs(syncOptions, responses) {
const {iframeEnabled, pixelEnabled} = syncOptions;
const { iframeEnabled, pixelEnabled } = syncOptions;

if (iframeEnabled) {
return [{
Expand All @@ -100,7 +110,7 @@ function getUserSyncs(syncOptions, responses) {
const lookup = {};
const syncs = [];
responses.forEach(response => {
const {body} = response;
const { body } = response;
const cookies = body ? body.cookies || [] : [];
cookies.forEach(cookie => {
switch (cookie.type) {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 24 additions & 37 deletions test/spec/modules/vidazooBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {expect} from 'chai';
import {spec as adapter, URL} from 'modules/vidazooBidAdapter.js';
import { expect } from 'chai';
import { spec as adapter, URL } from 'modules/vidazooBidAdapter.js';
import * as utils from 'src/utils.js';

const BID = {
Expand Down Expand Up @@ -31,16 +31,20 @@ const BIDDER_REQUEST = {

const SERVER_RESPONSE = {
body: {
'ad': '<iframe>console.log("hello world")</iframe>',
'price': 0.8,
'creativeId': '12610997325162499419',
'exp': 30,
'cookies': [{
'src': 'https://sync.com',
'type': 'iframe'
}, {
'src': 'https://sync.com',
'type': 'img'
results: [{
'ad': '<iframe>console.log("hello world")</iframe>',
'price': 0.8,
'creativeId': '12610997325162499419',
'exp': 30,
width: 300,
height: 250,
'cookies': [{
'src': 'https://sync.com',
'type': 'iframe'
}, {
'src': 'https://sync.com',
'type': 'img'
}]
}]
}
};
Expand Down Expand Up @@ -119,30 +123,13 @@ describe('VidazooBidAdapter', function () {

it('should build request for each size', function () {
const requests = adapter.buildRequests([BID], BIDDER_REQUEST);
expect(requests).to.have.length(2);
expect(requests).to.have.length(1);
expect(requests[0]).to.deep.equal({
method: 'GET',
url: `${URL}/prebid/59db6b3b4ffaa70004f45cdc`,
method: 'POST',
url: `${URL}/prebid/multi/59db6b3b4ffaa70004f45cdc`,
data: {
consent: 'consent_string',
width: '300',
height: '250',
url: 'https%3A%2F%2Fwww.greatsite.com',
cb: 1000,
bidFloor: 0.1,
bidId: '2d52001cabd527',
publisherId: '59ac17c192832d0011283fe3',
'ext.param1': 'loremipsum',
'ext.param2': 'dolorsitamet',
}
});
expect(requests[1]).to.deep.equal({
method: 'GET',
url: `${URL}/prebid/59db6b3b4ffaa70004f45cdc`,
data: {
consent: 'consent_string',
width: '300',
height: '600',
gdprConsent: 'consent_string',
sizes: ['300x250', '300x600'],
url: 'https%3A%2F%2Fwww.greatsite.com',
cb: 1000,
bidFloor: 0.1,
Expand All @@ -166,12 +153,12 @@ describe('VidazooBidAdapter', function () {
});

it('should return empty array when there is no ad', function () {
const responses = adapter.interpretResponse({price: 1, ad: ''});
const responses = adapter.interpretResponse({ price: 1, ad: '' });
expect(responses).to.be.empty;
});

it('should return empty array when there is no price', function () {
const responses = adapter.interpretResponse({price: null, ad: 'great ad'});
const responses = adapter.interpretResponse({ price: null, ad: 'great ad' });
expect(responses).to.be.empty;
});

Expand All @@ -193,7 +180,7 @@ describe('VidazooBidAdapter', function () {

it('should take default TTL', function () {
const serverResponse = utils.deepClone(SERVER_RESPONSE);
delete serverResponse.body.exp;
delete serverResponse.body.results[0].exp;
const responses = adapter.interpretResponse(serverResponse, REQUEST);
expect(responses).to.have.length(1);
expect(responses[0].ttl).to.equal(300);
Expand Down