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

Optimera added optional device param (#4105). #4106

Merged
merged 3 commits into from
Aug 29, 2019
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
34 changes: 18 additions & 16 deletions modules/optimeraBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { registerBidder } from '../src/adapters/bidderFactory';
import { deepAccess } from '../src/utils';

const BIDDER_CODE = 'optimera';
const SCORES_BASE_URL = 'https://dyv1bugovvq1g.cloudfront.net/';
Expand All @@ -11,12 +12,11 @@ export const spec = {
* @param {bidRequest} bid The bid params to validate.
* @return boolean True if this is a valid bid, and false otherwise.
*/
isBidRequestValid: function (bidRequest) {
isBidRequestValid (bidRequest) {
if (typeof bidRequest.params !== 'undefined' && typeof bidRequest.params.clientID !== 'undefined') {
return true;
} else {
return false;
}
return false;
},
/**
* Make a server request from the list of BidRequests.
Expand All @@ -27,18 +27,19 @@ export const spec = {
* @param {validBidRequests[]} - an array of bids
* @return ServerRequest Info describing the request to the server.
*/
buildRequests: function (validBidRequests) {
let optimeraHost = window.location.host;
let optimeraPathName = window.location.pathname;
buildRequests (validBidRequests) {
const optimeraHost = window.location.host;
const optimeraPathName = window.location.pathname;
if (typeof validBidRequests[0].params.clientID !== 'undefined') {
let clientID = validBidRequests[0].params.clientID;
let scoresURL = SCORES_BASE_URL + clientID + '/' + optimeraHost + optimeraPathName + '.js';
const { clientID } = validBidRequests[0].params;
const scoresURL = `${SCORES_BASE_URL + clientID}/${optimeraHost}${optimeraPathName}.js`;
return {
method: 'GET',
url: scoresURL,
payload: validBidRequests,
};
}
return {};
},
/**
* Unpack the response from the server into a list of bids.
Expand All @@ -49,24 +50,25 @@ export const spec = {
* @param {*} serverResponse A successful response from the server.
* @return {Bid[]} An array of bids which were nested inside the server.
*/
interpretResponse: function (serverResponse, bidRequest) {
let validBids = bidRequest.payload;
let bidResponses = [];
interpretResponse (serverResponse, bidRequest) {
const validBids = bidRequest.payload;
const bidResponses = [];
let dealId = '';
if (typeof serverResponse.body !== 'undefined') {
let scores = serverResponse.body;
for (let i = 0; i < validBids.length; i++) {
const scores = serverResponse.body;
for (let i = 0; i < validBids.length; i += 1) {
if (typeof validBids[i].params.clientID !== 'undefined') {
if (validBids[i].adUnitCode in scores) {
dealId = scores[validBids[i].adUnitCode];
const deviceDealId = deepAccess(scores, `device.${validBids[i].params.device}.${validBids[i].adUnitCode}`);
dealId = deviceDealId || scores[validBids[i].adUnitCode];
}
let bidResponse = {
const bidResponse = {
requestId: validBids[i].bidId,
ad: '<div></div>',
cpm: 0.01,
width: 0,
height: 0,
dealId: dealId,
dealId,
ttl: 300,
creativeId: '1',
netRevenue: '0',
Expand Down
6 changes: 4 additions & 2 deletions modules/optimeraBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ Module that adds ad placement visibility scores for DFP.
{
bidder: 'optimera',
params: {
clientID: '9999'
clientID: '9999',
device: 'mo'
}
}]
},{
Expand All @@ -29,7 +30,8 @@ Module that adds ad placement visibility scores for DFP.
{
bidder: 'optimera',
params: {
clientID: '9999'
clientID: '9999',
device: 'mo'
}
}]
}];
Expand Down
26 changes: 25 additions & 1 deletion test/spec/modules/optimeraBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('OptimeraAdapter', function () {

describe('interpretResponse', function () {
let serverResponse = {};
serverResponse.body = JSON.parse('{"div-0":["RB_K","728x90K"], "timestamp":["RB_K","1507565666"]}');
serverResponse.body = JSON.parse('{"div-0":["RB_K","728x90K"], "timestamp":["RB_K","1507565666"], "device": { "de": { "div-0":["A1","728x90K"] }, "mo": { "div-0":["RB_K","728x90K"] }, "tb": { "div-0":["RB_K","728x90K"] } } }');
var bidRequest = {
'method': 'get',
'payload': [
Expand All @@ -72,4 +72,28 @@ describe('OptimeraAdapter', function () {
expect(bidResponses[0].dealId[1]).to.equal('728x90K');
});
});

describe('interpretResponse with optional device param', function () {
let serverResponse = {};
serverResponse.body = JSON.parse('{"div-0":["RB_K","728x90K"], "timestamp":["RB_K","1507565666"], "device": { "de": { "div-0":["A1","728x90K"] }, "mo": { "div-0":["RB_K","728x90K"] }, "tb": { "div-0":["RB_K","728x90K"] } } }');
var bidRequest = {
'method': 'get',
'payload': [
{
'bidder': 'optimera',
'params': {
'clientID': '0',
'device': 'de'
},
'adUnitCode': 'div-0',
'bidId': '307440db8538ab'
}
]
}
it('interpresResponse fires', function () {
let bidResponses = spec.interpretResponse(serverResponse, bidRequest);
expect(bidResponses[0].dealId[0]).to.equal('A1');
expect(bidResponses[0].dealId[1]).to.equal('728x90K');
});
});
});