Skip to content

Commit

Permalink
updated telaria bid adapter to use player size provided by the bid.me…
Browse files Browse the repository at this point in the history
…diaTypes.video.playerSize instead of bid.sizes.

prebid#3331
  • Loading branch information
Vinay Prasad committed Dec 13, 2018
1 parent 81ec17a commit cebc764
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 27 deletions.
29 changes: 15 additions & 14 deletions modules/telariaBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as utils from 'src/utils';
import * as bidfactory from 'src/bidfactory';
import {registerBidder} from 'src/adapters/bidderFactory';
import {config} from 'src/config';
import {VIDEO} from '../src/mediaTypes';
import {STATUS} from 'src/constants';

Expand All @@ -24,17 +23,18 @@ export const spec = {
/**
* Make a server request from the list of BidRequests.
* @param validBidRequests list of valid bid requests that have passed isBidRequestValid check
* @param bidderRequest
* @returns {Array} of url objects
*/
buildRequests: function (validBidRequests) {
buildRequests: function (validBidRequests, bidderRequest) {
let requests = [];

validBidRequests.forEach(bid => {
let url = generateUrl(bid);
let url = generateUrl(bid, bidderRequest);
if (url) {
requests.push({
method: 'GET',
url: generateUrl(bid),
url: generateUrl(bid, bidderRequest),
bidId: bid.bidId,
vastUrl: url.split('&fmt=json')[0]
});
Expand Down Expand Up @@ -112,21 +112,22 @@ export const spec = {
* Generates the url based on the parameters given. Sizes, supplyCode & adCode are required.
* The format is: [L,W] or [[L1,W1],...]
* @param bid
* @param bidderRequest
* @returns {string}
*/
function generateUrl(bid) {
function generateUrl(bid, bidderRequest) {
let width, height;
if (!bid.sizes) {
let playerSize = (bid.mediaTypes && bid.mediaTypes.video && bid.mediaTypes.video.playerSize);
if (!playerSize) {
return '';
}

if (utils.isArray(bid.sizes) && (bid.sizes.length === 2) && (!isNaN(bid.sizes[0]) && !isNaN(bid.sizes[1]))) {
width = bid.sizes[0];
height = bid.sizes[1];
} else if (typeof bid.sizes === 'object') {
// take the primary (first) size from the array
width = bid.sizes[0][0];
height = bid.sizes[0][1];
if (utils.isArray(playerSize) && (playerSize.length === 2) && (!isNaN(playerSize[0]) && !isNaN(playerSize[1]))) {
width = playerSize[0];
height = playerSize[1];
} else if (typeof playerSize === 'object') {
width = playerSize[0][0];
height = playerSize[0][1];
}
if (width && height && bid.params.supplyCode && bid.params.adCode) {
let scheme = ((document.location.protocol === 'https:') ? 'https' : 'http') + '://';
Expand All @@ -146,7 +147,7 @@ function generateUrl(bid) {
}

url += ('&transactionId=' + bid.transactionId);
url += ('&referrer=' + config.getConfig('pageUrl') || utils.getTopWindowUrl());
url += ('&referrer=' + encodeURIComponent(bidderRequest.refererInfo.referer));

return (url + '&fmt=json');
}
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.

48 changes: 36 additions & 12 deletions test/spec/modules/telariaBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ const SUPPLY_CODE = 'ssp-demo-rm6rh';
const SIZES = [640, 480];
const REQUEST = {
'code': 'video1',
'sizes': [640, 480],
'mediaTypes': {
'video': {
'playerSize': [[640, 480]],
'context': 'instream'
}
},
'mediaType': 'video',
'bids': [{
'bidder': 'tremor',
Expand All @@ -19,6 +24,12 @@ const REQUEST = {
}]
};

const BIDDER_REQUEST = {
'refererInfo': {
'referer': 'www.test.com'
}
};

const RESPONSE = {
'cur': 'USD',
'id': '3dba13e35f3d42f998bc7e65fd871889',
Expand Down Expand Up @@ -73,8 +84,13 @@ describe('TelariaAdapter', () => {

describe('buildRequests', () => {
const stub = [{
mediaTypes: {
video: {
playerSize: [[640, 480]],
context: 'instream'
}
},
bidder: 'tremor',
sizes: [[300, 250], [300, 600]],
params: {
supplyCode: 'ssp-demo-rm6rh',
adCode: 'ssp-!demo!-lufip',
Expand All @@ -87,12 +103,12 @@ describe('TelariaAdapter', () => {
});

it('requires supply code, ad code and sizes to make a request', () => {
const tempRequest = spec.buildRequests(stub);
const tempRequest = spec.buildRequests(stub, BIDDER_REQUEST);
expect(tempRequest.length).to.equal(1);
});

it('generates an array of requests with 4 params, method, url, bidId and vastUrl', () => {
const tempRequest = spec.buildRequests(stub);
const tempRequest = spec.buildRequests(stub, BIDDER_REQUEST);

expect(tempRequest.length).to.equal(1);
expect(tempRequest[0].method).to.equal('GET');
Expand All @@ -103,24 +119,27 @@ describe('TelariaAdapter', () => {

it('requires sizes to make a request', () => {
let tempBid = stub;
tempBid[0].sizes = null;
const tempRequest = spec.buildRequests(tempBid);
tempBid[0].mediaTypes.video.playerSize = null;
const tempRequest = spec.buildRequests(tempBid, BIDDER_REQUEST);

expect(tempRequest.length).to.equal(0);
});

it('generates a valid request with sizes as an array of two elements', () => {
let tempBid = stub;
tempBid[0].sizes = [640, 480];
expect(spec.buildRequests(tempBid).length).to.equal(1);
tempBid[0].mediaTypes.video.playerSize = [640, 480];
tempBid[0].params.adCode = 'ssp-!demo!-lufip';
tempBid[0].params.supplyCode = 'ssp-demo-rm6rh';
let builtRequests = spec.buildRequests(tempBid, BIDDER_REQUEST);
expect(builtRequests.length).to.equal(1);
});

it('requires ad code and supply code to make a request', () => {
let tempBid = stub;
tempBid[0].params.adCode = null;
tempBid[0].params.supplyCode = null;

const tempRequest = spec.buildRequests(tempBid);
const tempRequest = spec.buildRequests(tempBid, BIDDER_REQUEST);

expect(tempRequest.length).to.equal(0);
});
Expand All @@ -129,8 +148,13 @@ describe('TelariaAdapter', () => {
describe('interpretResponse', () => {
const responseStub = RESPONSE;
const stub = [{
mediaTypes: {
video: {
playerSize: [[640, 480]],
context: 'instream'
}
},
bidder: 'tremor',
sizes: [[300, 250], [300, 600]],
params: {
supplyCode: 'ssp-demo-rm6rh',
adCode: 'ssp-!demo!-lufip',
Expand All @@ -143,7 +167,7 @@ describe('TelariaAdapter', () => {
'getStatusCode', 'getSize', 'requestId', 'cpm', 'creativeId', 'vastXml',
'vastUrl', 'currency', 'netRevenue', 'ttl', 'ad'];

let bidRequest = spec.buildRequests(stub)[0];
let bidRequest = spec.buildRequests(stub, BIDDER_REQUEST)[0];
bidRequest.bidId = '1234';
let result = spec.interpretResponse({body: responseStub}, bidRequest);
expect(Object.keys(result[0])).to.have.members(expectedResponseKeys);
Expand All @@ -153,7 +177,7 @@ describe('TelariaAdapter', () => {
let tempResponse = responseStub;
tempResponse.seatbid = [];

let bidRequest = spec.buildRequests(stub)[0];
let bidRequest = spec.buildRequests(stub, BIDDER_REQUEST)[0];
bidRequest.bidId = '1234';

let result = spec.interpretResponse({body: tempResponse}, bidRequest);
Expand Down

0 comments on commit cebc764

Please sign in to comment.