diff --git a/modules/optimeraBidAdapter.js b/modules/optimeraBidAdapter.js new file mode 100644 index 00000000000..e77526cfdf1 --- /dev/null +++ b/modules/optimeraBidAdapter.js @@ -0,0 +1,81 @@ +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.custom != 'undefined' && typeof bidRequest.params.custom.clientID != 'undefined') { + return true; + } else { + return false; + } + }, + /** + * Make a server request from the list of BidRequests. + * + * @param {validBidRequests[]} - an array of bids + * @return ServerRequest Info describing the request to the server. + */ + buildRequests: function (validBidRequests) { + var optimeraHost = window.location.host; + var optimeraPathName = window.location.pathname; + var timestamp = Math.round(new Date().getTime() / 1000); + if (typeof validBidRequests[0].params.custom.clientID != 'undefined') { + var clientID = validBidRequests[0].params.custom.clientID; + var 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) { + var scores = serverResponse.body.replace('window.oVa = ', ''); + scores = scores.replace(';', ''); + scores = JSON.parse(scores); + 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]; + } + var bidResponse = { + requestId: validBids[i].bidId, + ad: '
', + cpm: 0.01, + width: 0, + height: 0, + dealId: dealId, + ttl: 300, + creativeId: '1', + netRevenue: '0', + currency: 'USD' + }; + bidResponses.push(bidResponse); + } + } + return bidResponses; + } +} + +registerBidder(spec); diff --git a/modules/optimeraBidAdapter.md b/modules/optimeraBidAdapter.md new file mode 100644 index 00000000000..d8a196372be --- /dev/null +++ b/modules/optimeraBidAdapter.md @@ -0,0 +1,40 @@ +# 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: { + custom:{ + clientID: '0' + } + } + }] + },{ + code: 'div-0', + sizes: [[728, 90]], + bids: [ + { + bidder: 'optimera', + params: { + custom:{ + clientID: '0' + } + } + }] + }]; +``` diff --git a/test/spec/modules/optimeraBidAdapter_spec.js b/test/spec/modules/optimeraBidAdapter_spec.js new file mode 100644 index 00000000000..57d43957874 --- /dev/null +++ b/test/spec/modules/optimeraBidAdapter_spec.js @@ -0,0 +1,83 @@ +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': { + 'custom': { + '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': { + 'custom': { + '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 = 'window.oVa = {"div-0":["RB_K","728x90K"], "timestamp":["RB_K","1507565666"]};'; + var bidRequest = { + 'method': 'get', + 'payload': [ + { + 'bidder': 'optimera', + 'params': { + 'custom': { + 'clientID': '0' + } + }, + 'adUnitCode': 'div-0', + 'bidId': '307440db8538ab' + } + ] + } + it('interpresResponse fires', () => { + window.oDv = window.oDv || []; + let bidResponses = spec.interpretResponse(serverResponse, bidRequest); + expect(bidResponses[0].dealId[0]).to.equal('RB_K'); + expect(bidResponses[0].dealId[1]).to.equal('728x90K'); + }); + }); +});