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

Update for Media.net adapter #2232

Merged
merged 4 commits into from
Mar 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 11 additions & 3 deletions modules/medianetBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { registerBidder } from 'src/adapters/bidderFactory';
import * as utils from 'src/utils';
import { config } from 'src/config';

const BIDDER_CODE = 'medianet';
const BID_URL = 'https://prebid.media.net/rtb/prebid';

$$PREBID_GLOBAL$$.medianetGlobals = {};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ok since no public api functions are being invoked but we encourage adapters to use $$PREBID_GLOBAL$$ as little as possible. localStorage might suit this use case without needing to use the pbjs global


function siteDetails(site) {
site = site || {};

Expand Down Expand Up @@ -35,7 +38,8 @@ function getSize(size) {

function configuredParams(params) {
return {
customer_id: params.cid
customer_id: params.cid,
prebid_version: $$PREBID_GLOBAL$$.version
}
}

Expand All @@ -46,7 +50,8 @@ function slotParams(bidRequest) {
ext: {
dfp_id: bidRequest.adUnitCode
},
banner: transformSizes(bidRequest.sizes)
banner: transformSizes(bidRequest.sizes),
all: bidRequest.params
};

if (bidRequest.params.crid) {
Expand All @@ -65,7 +70,8 @@ function generatePayload(bidRequests) {
site: siteDetails(bidRequests[0].params.site),
ext: configuredParams(bidRequests[0].params),
id: bidRequests[0].auctionId,
imp: bidRequests.map(request => slotParams(request))
imp: bidRequests.map(request => slotParams(request)),
tmax: config.getConfig('bidderTimeout')
}
}

Expand Down Expand Up @@ -103,6 +109,8 @@ export const spec = {
return false;
}

Object.assign($$PREBID_GLOBAL$$.medianetGlobals, !$$PREBID_GLOBAL$$.medianetGlobals.cid && {cid: bid.params.cid});

return true;
},

Expand Down
78 changes: 73 additions & 5 deletions test/spec/modules/medianetBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {expect} from 'chai';
import {spec} from 'modules/medianetBidAdapter';
import { config } from 'src/config';

let VALID_BID_REQUEST = [{
'bidder': 'medianet',
Expand Down Expand Up @@ -68,14 +69,64 @@ let VALID_BID_REQUEST = [{
'bidderRequestId': '1e9b1f07797c1c',
'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d'
}],
VALID_PAYLOAD_INVALID_BIDFLOOR = {
'site': {
'page': 'http://media.net/prebidtest',
'domain': 'media.net',
'ref': 'http://media.net/prebidtest'
},
'ext': {
'customer_id': 'customer_id',
'prebid_version': $$PREBID_GLOBAL$$.version
},
'id': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d',
'imp': [{
'id': '28f8f8130a583e',
'ext': {
'dfp_id': 'div-gpt-ad-1460505748561-0'
},
'banner': [{
'w': 300,
'h': 250
}],
'all': {
'cid': 'customer_id',
'bidfloor': 'abcdef',
'site': {
'page': 'http://media.net/prebidtest',
'domain': 'media.net',
'ref': 'http://media.net/prebidtest'
}
}
}, {
'id': '3f97ca71b1e5c2',
'ext': {
'dfp_id': 'div-gpt-ad-1460505748561-123'
},
'banner': [{
'w': 300,
'h': 251
}],
'all': {
'cid': 'customer_id',
'site': {
'page': 'http://media.net/prebidtest',
'domain': 'media.net',
'ref': 'http://media.net/prebidtest'
}
}
}],
'tmax': config.getConfig('bidderTimeout')
},
VALID_PAYLOAD = {
'site': {
'page': 'http://media.net/prebidtest',
'domain': 'media.net',
'ref': 'http://media.net/prebidtest'
},
'ext': {
'customer_id': 'customer_id'
'customer_id': 'customer_id',
'prebid_version': $$PREBID_GLOBAL$$.version
},
'id': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d',
'imp': [{
Expand All @@ -86,7 +137,15 @@ let VALID_BID_REQUEST = [{
'banner': [{
'w': 300,
'h': 250
}]
}],
'all': {
'cid': 'customer_id',
'site': {
'page': 'http://media.net/prebidtest',
'domain': 'media.net',
'ref': 'http://media.net/prebidtest'
}
}
}, {
'id': '3f97ca71b1e5c2',
'ext': {
Expand All @@ -95,8 +154,17 @@ let VALID_BID_REQUEST = [{
'banner': [{
'w': 300,
'h': 251
}]
}]
}],
'all': {
'cid': 'customer_id',
'site': {
'page': 'http://media.net/prebidtest',
'domain': 'media.net',
'ref': 'http://media.net/prebidtest'
}
}
}],
'tmax': config.getConfig('bidderTimeout')
},
VALID_PARAMS = {
bidder: 'medianet',
Expand Down Expand Up @@ -286,7 +354,7 @@ describe('Media.net bid adapter', () => {

it('should ignore bidfloor if not a valid number', () => {
let bidReq = spec.buildRequests(VALID_BID_REQUEST_INVALID_BIDFLOOR);
expect(JSON.parse(bidReq.data)).to.deep.equal(VALID_PAYLOAD);
expect(JSON.parse(bidReq.data)).to.deep.equal(VALID_PAYLOAD_INVALID_BIDFLOOR);
});
});

Expand Down