Skip to content

Commit 87e84b8

Browse files
mcallarimsm0504
authored andcommitted
Optimera added optional device param (#4105). (#4106)
* Optimera added optional device param (#4105). * Updating to use deepAccess util method (#4105). * Condensing dealId check (#4105).
1 parent 099a723 commit 87e84b8

File tree

3 files changed

+47
-19
lines changed

3 files changed

+47
-19
lines changed

modules/optimeraBidAdapter.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { registerBidder } from '../src/adapters/bidderFactory';
2+
import { deepAccess } from '../src/utils';
23

34
const BIDDER_CODE = 'optimera';
45
const SCORES_BASE_URL = 'https://dyv1bugovvq1g.cloudfront.net/';
@@ -11,12 +12,11 @@ export const spec = {
1112
* @param {bidRequest} bid The bid params to validate.
1213
* @return boolean True if this is a valid bid, and false otherwise.
1314
*/
14-
isBidRequestValid: function (bidRequest) {
15+
isBidRequestValid (bidRequest) {
1516
if (typeof bidRequest.params !== 'undefined' && typeof bidRequest.params.clientID !== 'undefined') {
1617
return true;
17-
} else {
18-
return false;
1918
}
19+
return false;
2020
},
2121
/**
2222
* Make a server request from the list of BidRequests.
@@ -27,18 +27,19 @@ export const spec = {
2727
* @param {validBidRequests[]} - an array of bids
2828
* @return ServerRequest Info describing the request to the server.
2929
*/
30-
buildRequests: function (validBidRequests) {
31-
let optimeraHost = window.location.host;
32-
let optimeraPathName = window.location.pathname;
30+
buildRequests (validBidRequests) {
31+
const optimeraHost = window.location.host;
32+
const optimeraPathName = window.location.pathname;
3333
if (typeof validBidRequests[0].params.clientID !== 'undefined') {
34-
let clientID = validBidRequests[0].params.clientID;
35-
let scoresURL = SCORES_BASE_URL + clientID + '/' + optimeraHost + optimeraPathName + '.js';
34+
const { clientID } = validBidRequests[0].params;
35+
const scoresURL = `${SCORES_BASE_URL + clientID}/${optimeraHost}${optimeraPathName}.js`;
3636
return {
3737
method: 'GET',
3838
url: scoresURL,
3939
payload: validBidRequests,
4040
};
4141
}
42+
return {};
4243
},
4344
/**
4445
* Unpack the response from the server into a list of bids.
@@ -49,24 +50,25 @@ export const spec = {
4950
* @param {*} serverResponse A successful response from the server.
5051
* @return {Bid[]} An array of bids which were nested inside the server.
5152
*/
52-
interpretResponse: function (serverResponse, bidRequest) {
53-
let validBids = bidRequest.payload;
54-
let bidResponses = [];
53+
interpretResponse (serverResponse, bidRequest) {
54+
const validBids = bidRequest.payload;
55+
const bidResponses = [];
5556
let dealId = '';
5657
if (typeof serverResponse.body !== 'undefined') {
57-
let scores = serverResponse.body;
58-
for (let i = 0; i < validBids.length; i++) {
58+
const scores = serverResponse.body;
59+
for (let i = 0; i < validBids.length; i += 1) {
5960
if (typeof validBids[i].params.clientID !== 'undefined') {
6061
if (validBids[i].adUnitCode in scores) {
61-
dealId = scores[validBids[i].adUnitCode];
62+
const deviceDealId = deepAccess(scores, `device.${validBids[i].params.device}.${validBids[i].adUnitCode}`);
63+
dealId = deviceDealId || scores[validBids[i].adUnitCode];
6264
}
63-
let bidResponse = {
65+
const bidResponse = {
6466
requestId: validBids[i].bidId,
6567
ad: '<div></div>',
6668
cpm: 0.01,
6769
width: 0,
6870
height: 0,
69-
dealId: dealId,
71+
dealId,
7072
ttl: 300,
7173
creativeId: '1',
7274
netRevenue: '0',

modules/optimeraBidAdapter.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ Module that adds ad placement visibility scores for DFP.
1919
{
2020
bidder: 'optimera',
2121
params: {
22-
clientID: '9999'
22+
clientID: '9999',
23+
device: 'mo'
2324
}
2425
}]
2526
},{
@@ -29,7 +30,8 @@ Module that adds ad placement visibility scores for DFP.
2930
{
3031
bidder: 'optimera',
3132
params: {
32-
clientID: '9999'
33+
clientID: '9999',
34+
device: 'mo'
3335
}
3436
}]
3537
}];

test/spec/modules/optimeraBidAdapter_spec.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ describe('OptimeraAdapter', function () {
5252

5353
describe('interpretResponse', function () {
5454
let serverResponse = {};
55-
serverResponse.body = JSON.parse('{"div-0":["RB_K","728x90K"], "timestamp":["RB_K","1507565666"]}');
55+
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"] } } }');
5656
var bidRequest = {
5757
'method': 'get',
5858
'payload': [
@@ -72,4 +72,28 @@ describe('OptimeraAdapter', function () {
7272
expect(bidResponses[0].dealId[1]).to.equal('728x90K');
7373
});
7474
});
75+
76+
describe('interpretResponse with optional device param', function () {
77+
let serverResponse = {};
78+
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"] } } }');
79+
var bidRequest = {
80+
'method': 'get',
81+
'payload': [
82+
{
83+
'bidder': 'optimera',
84+
'params': {
85+
'clientID': '0',
86+
'device': 'de'
87+
},
88+
'adUnitCode': 'div-0',
89+
'bidId': '307440db8538ab'
90+
}
91+
]
92+
}
93+
it('interpresResponse fires', function () {
94+
let bidResponses = spec.interpretResponse(serverResponse, bidRequest);
95+
expect(bidResponses[0].dealId[0]).to.equal('A1');
96+
expect(bidResponses[0].dealId[1]).to.equal('728x90K');
97+
});
98+
});
7599
});

0 commit comments

Comments
 (0)