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 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
84 changes: 84 additions & 0 deletions modules/optimeraBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import {registerBidder} from 'src/adapters/bidderFactory';
const BIDDER_CODE = 'optimera';
const SCORES_BASE_URL = 'https://s3.amazonaws.com/elasticbeanstalk-us-east-1-397719490216/json/client/';

export const spec = {
code: BIDDER_CODE,
/**
* Determines whether or not the given bid request is valid.
*
* @param {bidRequest} bid The bid params to validate.
* @return boolean True if this is a valid bid, and false otherwise.
*/
isBidRequestValid: function (bidRequest) {
if (typeof bidRequest.params !== 'undefined' && typeof bidRequest.params.clientID !== 'undefined') {
return true;
} else {
return false;
}
},
/**
* Make a server request from the list of BidRequests.
*
* We call the existing scores data file for ad slot placement scores.
* These scores will be added to the dealId to be pushed to DFP.
*
* @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;
let timestamp = Math.round(new Date().getTime() / 1000);
if (typeof validBidRequests[0].params.clientID !== 'undefined') {
let clientID = validBidRequests[0].params.clientID;
let scoresURL = SCORES_BASE_URL + clientID + '/' + optimeraHost + optimeraPathName + '.js';
return {
method: 'GET',
url: scoresURL,
payload: validBidRequests,
data: {'t': timestamp}
};
}
},
/**
* Unpack the response from the server into a list of bids.
*
* Some required bid params are not needed for this so default
* values are used.
*
* @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 = [];
let dealId = '';
if (typeof serverResponse.body !== 'undefined') {
let scores = serverResponse.body;
for (let i = 0; i < validBids.length; i++) {
if (typeof validBids[i].params.clientID !== 'undefined') {
if (validBids[i].adUnitCode in scores) {
dealId = scores[validBids[i].adUnitCode];
}
let 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;
}
}

registerBidder(spec);
36 changes: 36 additions & 0 deletions modules/optimeraBidAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Overview

```
Module Name: Optimera Bidder Adapter
Module Type: Bidder Adapter
Maintainer: kcandiotti@optimera.nyc
```

# Description

Module that adds ad placement visibility scores for DFP.

# Test Parameters
```
var adUnits = [{
code: 'div-1',
sizes: [[300, 250], [300,600]],
bids: [
{
bidder: 'optimera',
params: {
clientID: '0'
}
}]
},{
code: 'div-0',
sizes: [[728, 90]],
bids: [
{
bidder: 'optimera',
params: {
clientID: '0'
}
}]
}];
```
76 changes: 76 additions & 0 deletions test/spec/modules/optimeraBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { expect } from 'chai';
import { spec } from 'modules/optimeraBidAdapter';
import { newBidder } from 'src/adapters/bidderFactory';

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

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

describe('isBidRequestValid', () => {
let bid = {
'bidder': 'optimera',
'params': {
'clientID': '0'
},
'adUnitCode': 'div-0',
'sizes': [[300, 250], [300, 600]],
'bidId': '30b31c1838de1e',
'bidderRequestId': '22edbae2733bf6',
'auctionId': '1d1a030790a475',
};

it('should return true when required params found', () => {
expect(spec.isBidRequestValid(bid)).to.equal(true);
});
})

describe('buildRequests', () => {
let bid = [
{
'adUnitCode': 'div-0',
'auctionId': '1ab30503e03994',
'bidId': '313e0afede8cdb',
'bidder': 'optimera',
'bidderRequestId': '202be1ce3f6194',
'params': {
'clientID': '0'
}
}
];
it('buildRequests fires', () => {
let request = spec.buildRequests(bid);
expect(request).to.exist;
expect(request.method).to.equal('GET');
expect(request.payload).to.exist;
expect(request.data.t).to.exist;
});
})

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