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 Adapter for 1.0. #1961

Merged
merged 3 commits into from
Jan 23, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
46 changes: 20 additions & 26 deletions modules/optimeraBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {registerBidder} from 'src/adapters/bidderFactory';
import * as utils from 'src/utils';
const BIDDER_CODE = 'optimera';
const SCORES_BASE_URL = 'https://s3.amazonaws.com/elasticbeanstalk-us-east-1-397719490216/json/client/';

Expand Down Expand Up @@ -52,35 +51,30 @@ export const spec = {
* @return {Bid[]} An array of bids which were nested inside the server.
*/
interpretResponse: function (serverResponse, bidRequest) {
var scores = serverResponse.body.replace('window.oVa = ', '');
scores = scores.replace(';', '');
try {
scores = JSON.parse(scores);
} catch (_error) {
scores = [];
utils.logError(_error);
}
var validBids = bidRequest.payload;
var bidResponses = [];
var dealId = '';
for (var i = 0; i < validBids.length; i++) {
if (typeof validBids[i].params.custom.clientID != 'undefined') {
if (validBids[i].adUnitCode in scores) {
dealId = scores[validBids[i].adUnitCode];
if (typeof serverResponse.body != 'undefined') {
Copy link
Member

Choose a reason for hiding this comment

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

prefer triple equality.

var scores = serverResponse.body;
Copy link
Member

Choose a reason for hiding this comment

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

prefer const | let

for (var i = 0; i < validBids.length; i++) {
if (typeof validBids[i].params.custom.clientID != 'undefined') {
Copy link
Member

Choose a reason for hiding this comment

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

not safe access to clientID (in case custom is undefined`)

if (validBids[i].adUnitCode in scores) {
dealId = scores[validBids[i].adUnitCode];
}
var bidResponse = {
requestId: validBids[i].bidId,
ad: '<div></div>',
cpm: 0.01,
width: 0,
height: 0,
dealId: dealId,
ttl: 300,
creativeId: '1',
netRevenue: '0',
currency: 'USD'
};
bidResponses.push(bidResponse);
}
var bidResponse = {
requestId: validBids[i].bidId,
ad: '<div></div>',
cpm: 0.01,
width: 0,
height: 0,
dealId: dealId,
ttl: 300,
creativeId: '1',
netRevenue: '0',
currency: 'USD'
};
bidResponses.push(bidResponse);
}
}
return bidResponses;
Expand Down
2 changes: 1 addition & 1 deletion test/spec/modules/optimeraBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe('OptimeraAdapter', () => {

describe('interpretResponse', () => {
let serverResponse = {};
serverResponse.body = 'window.oVa = {"div-0":["RB_K","728x90K"], "timestamp":["RB_K","1507565666"]};';
serverResponse.body = JSON.parse('{"div-0":["RB_K","728x90K"], "timestamp":["RB_K","1507565666"]}');
var bidRequest = {
'method': 'get',
'payload': [
Expand Down