Skip to content

Commit

Permalink
Modified the Telaria Bid Adapter to use bid.mediaTypes.video.playerSi…
Browse files Browse the repository at this point in the history
…ze instead of bid.sizes (prebid#3377)

* Added telaria bid adapter

* more documentation

* Added more test cases. And improved some code in the adapter

* Removed the check for optional params, they are handled in the server. Also updated certain param names used in  the test spec.

* added some spaces to fix CircleCI tests

* added some spaces to fix CircleCI tests

* fixed code indentation in /spec/AnalyticsAdapter_spec.js which causing the CircleCI tests to fail.

* Reverted the changes

* merged with prebid master.

* creative Id is required when we build a response but our server doesn't always have the crid, so using a sentinel value when we don't have the crid.

* - removed an un used method
- Removed the package-lock file.

* merging to master

* updated telaria bid adapter to use player size provided by the bid.mediaTypes.video.playerSize instead of bid.sizes.

prebid#3331

* - removed the requirement for having player size
- updated the test spec to reflect the above change
- removed changes to the package-lock.json file.

* added a param to the ad call url to let us know that the request is coming via hb.

* to lower casing the bidder code.
  • Loading branch information
telariaEng authored and olafbuitelaar committed Jan 3, 2019
1 parent 90bd1c0 commit ef606ad
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 55 deletions.
50 changes: 29 additions & 21 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 @@ -84,7 +84,7 @@ export const spec = {
utils.logError(errorMessage);
} else if (bidResult.seatbid && bidResult.seatbid.length > 0) {
bidResult.seatbid[0].bid.forEach(tag => {
bids.push(createBid(STATUS.GOOD, bidderRequest, tag, width, height, bidResult.seatbid[0].seat));
bids.push(createBid(STATUS.GOOD, bidderRequest, tag, width, height, bidResult.seatbid[0].seat.toLowerCase()));
});
}

Expand Down Expand Up @@ -112,28 +112,36 @@ 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) {
let width, height;
if (!bid.sizes) {
return '';
function generateUrl(bid, bidderRequest) {
let playerSize = (bid.mediaTypes && bid.mediaTypes.video && bid.mediaTypes.video.playerSize);
if (!playerSize) {
utils.logWarn('Although player size isn\'t required it is highly recommended');
}

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];
let width, height;
if (playerSize) {
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) {

if (bid.params.supplyCode && bid.params.adCode) {
let scheme = ((document.location.protocol === 'https:') ? 'https' : 'http') + '://';
let url = scheme + bid.params.supplyCode + ENDPOINT + '?adCode=' + bid.params.adCode;

url += ('&playerWidth=' + width);
url += ('&playerHeight=' + height);
if (width) {
url += ('&playerWidth=' + width);
}
if (height) {
url += ('&playerHeight=' + height);
}

for (let key in bid.params) {
if (bid.params.hasOwnProperty(key) && bid.params[key]) {
Expand All @@ -145,8 +153,8 @@ function generateUrl(bid) {
url += ('&srcPageUrl=' + encodeURIComponent(document.location.href));
}

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

return (url + '&fmt=json');
}
Expand Down
92 changes: 58 additions & 34 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 All @@ -34,26 +45,26 @@ const RESPONSE = {
}]
};

describe('TelariaAdapter', function () {
describe('TelariaAdapter', () => {
const adapter = newBidder(spec);

describe('inherited functions', function () {
it('exists and is a function', function () {
describe('inherited functions', () => {
it('exists and is a function', () => {
expect(adapter.callBids).to.exist.and.to.be.a('function');
});
});

describe('isBidRequestValid', function () {
describe('isBidRequestValid', () => {
let bid = REQUEST.bids[0];

it('should return true when required params found', function () {
it('should return true when required params found', () => {
let tempBid = bid;
tempBid.params.adCode = 'ssp-!demo!-lufip';
tempBid.params.supplyCode = 'ssp-demo-rm6rh';
expect(spec.isBidRequestValid(bid)).to.equal(true);
});

it('should return true when required params found', function () {
it('should return true when required params found', () => {
let tempBid = bid;
delete tempBid.params;
tempBid.params = {
Expand All @@ -64,35 +75,40 @@ describe('TelariaAdapter', function () {
expect(spec.isBidRequestValid(tempBid)).to.equal(true);
});

it('should return false when required params are not passed', function () {
it('should return false when required params are not passed', () => {
let tempBid = bid;
tempBid.params = {};
expect(spec.isBidRequestValid(tempBid)).to.equal(false);
});
});

describe('buildRequests', function () {
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',
videoId: 'MyCoolVideo'
}
}];

it('exists and is a function', function () {
it('exists and is a function', () => {
expect(spec.buildRequests).to.exist.and.to.be.a('function');
});

it('requires supply code, ad code and sizes to make a request', function () {
const tempRequest = spec.buildRequests(stub);
it('requires supply code & ad code to make a request', () => {
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', function () {
const tempRequest = spec.buildRequests(stub);
it('generates an array of requests with 4 params, method, url, bidId and vastUrl', () => {
const tempRequest = spec.buildRequests(stub, BIDDER_REQUEST);

expect(tempRequest.length).to.equal(1);
expect(tempRequest[0].method).to.equal('GET');
Expand All @@ -101,77 +117,85 @@ describe('TelariaAdapter', function () {
expect(tempRequest[0].vastUrl).to.exist;
});

it('requires sizes to make a request', function () {
it('doesn\'t require player size but is highly recommended', () => {
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);
expect(tempRequest.length).to.equal(1);
});

it('generates a valid request with sizes as an array of two elements', function () {
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', function () {
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);
});
});

describe('interpretResponse', function () {
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',
videoId: 'MyCoolVideo'
}
}];

it('should get correct bid response', function () {
it('should get correct bid response', () => {
let expectedResponseKeys = ['bidderCode', 'width', 'height', 'statusMessage', 'adId', 'mediaType', 'source',
'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);
});

it('handles nobid responses', function () {
it('handles nobid responses', () => {
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);
expect(result.length).to.equal(0);
});

it('handles invalid responses', function () {
it('handles invalid responses', () => {
let result = spec.interpretResponse(null, {bbidderCode: 'telaria'});
expect(result.length).to.equal(0);
});

it('handles error responses', function () {
it('handles error responses', () => {
let result = spec.interpretResponse({body: {error: 'Invalid request'}}, {bbidderCode: 'telaria'});
expect(result.length).to.equal(0);
});
});

describe('getUserSyncs', function () {
describe('getUserSyncs', () => {
const responses = [{body: RESPONSE}];
responses[0].body.ext = {
telaria: {
Expand All @@ -182,7 +206,7 @@ describe('TelariaAdapter', function () {
}
};

it('should get the correct number of sync urls', function () {
it('should get the correct number of sync urls', () => {
let urls = spec.getUserSyncs({pixelEnabled: true}, responses);
expect(urls.length).to.equal(2);
});
Expand Down

0 comments on commit ef606ad

Please sign in to comment.