From 8d73f6643e15677b81a134b22e7e065cc9928236 Mon Sep 17 00:00:00 2001 From: Francesco Date: Thu, 2 Mar 2017 00:42:18 -0600 Subject: [PATCH 01/10] Bidfluence Adapter --- adapters.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/adapters.json b/adapters.json index dc7796ea482..f63d3dac6f2 100644 --- a/adapters.json +++ b/adapters.json @@ -7,6 +7,7 @@ "adform", "adkernel", "admedia", + "bidfluence", "vertamedia", "aol", "appnexus", @@ -29,7 +30,7 @@ "rhythmone", "rubicon", "smartyads", - "smartadserver", + "smartadserver", "sekindoUM", "sonobi", "sovrn", From abc88f905984eb98c6fd4406cd2d85b9cfbcaea1 Mon Sep 17 00:00:00 2001 From: Francesco Date: Thu, 2 Mar 2017 00:45:03 -0600 Subject: [PATCH 02/10] Bidfluence adapter --- src/adapters/bidfluence.js | 72 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/adapters/bidfluence.js diff --git a/src/adapters/bidfluence.js b/src/adapters/bidfluence.js new file mode 100644 index 00000000000..e78253aa410 --- /dev/null +++ b/src/adapters/bidfluence.js @@ -0,0 +1,72 @@ +var bidmanager = require('../bidmanager.js'); +var bidfactory = require('../bidfactory.js'); +var utils = require('../utils.js'); + +var BidderNameAdapter = function BidderNameAdapter() { + + var bfPbjsCB = []; + window.bfPbjsCB = function (bfr) { + bfPbjsCB["" + bfr.cbID](bfr); + }; + + //Callback + var bidfluenceCB = function (bfr) { + var bidObject = null; + + if (bfr.cpm > 0) { + bidObject = bidfactory.createBid(1); + bidObject.bidderCode = 'bidfluence'; + bidObject.cpm = bfr.cpm; + bidObject.ad = bfr.ad; + bidObject.width = bfr.width; + bidObject.height = bfr.height; + } else { + bidObject = bidfactory.createBid(2); + bidObject.bidderCode = 'bidfluence'; + } + bidmanager.addBidResponse(bfr.placementCode, bidObject); + }; + + function _callBids(params) { + var bfbids = params.bids || []; + for (var i = 0; i < bfbids.length; i++) { + var bid = bfbids[i]; + call(bid); + } + } + + function call(bid) { + + var cbID = utils.getUniqueIdentifierStr(); + var adunitId = utils.getBidIdParameter('adunitId', bid.params); + /* jshint ignore:start */ + var publisherId = utils.getBidIdParameter('pubId', bid.params); + var reservePrice = utils.getBidIdParameter('reservePrice', bid.params);//This is optional. For dynamic reserve price only. + var pbjsBfobj = { + cbID: cbID, + placementCode: bid.placementCode + }; + /* jshint ignore:end */ + var s = document.createElement('script'); + s.async = true; + s.id = adunitId; + s.onload = function () { + /* jshint ignore:start */ + FORGE.init([adunitId, publisherId, pbjsBfobj, reservePrice]); + FORGE.fire(); + /* jshint ignore:end */ + }; + s.src = "//bidfluence.azureedge.net/forge.js"; 0 + + var b = document.getElementsByTagName('head')[0]; + b.parentNode.insertBefore(s, b); + + bfPbjsCB[cbID] = bidfluenceCB; + } + + return { + callBids: _callBids + }; +}; + +module.exports = BidderNameAdapter; \ No newline at end of file From b3d8475d76af91e0d27d291a6f28da028a13bb97 Mon Sep 17 00:00:00 2001 From: Francesco Date: Thu, 2 Mar 2017 03:21:34 -0600 Subject: [PATCH 03/10] Fixed callback name --- src/adapters/bidfluence.js | 118 +++++++++++++++++-------------------- 1 file changed, 54 insertions(+), 64 deletions(-) diff --git a/src/adapters/bidfluence.js b/src/adapters/bidfluence.js index e78253aa410..13a09497d8f 100644 --- a/src/adapters/bidfluence.js +++ b/src/adapters/bidfluence.js @@ -1,72 +1,62 @@ -var bidmanager = require('../bidmanager.js'); -var bidfactory = require('../bidfactory.js'); -var utils = require('../utils.js'); - -var BidderNameAdapter = function BidderNameAdapter() { - - var bfPbjsCB = []; - window.bfPbjsCB = function (bfr) { - bfPbjsCB["" + bfr.cbID](bfr); - }; - - //Callback - var bidfluenceCB = function (bfr) { - var bidObject = null; +const bidmanager = require('../bidmanager.js'); +const bidfactory = require('../bidfactory.js'); +const utils = require('../utils.js'); + +var BidfluenceAdapter = function BidfluenceAdapter() { + + //Callback + window.bfPbjsCB = function (bfr) { + var bidObject = null; + + if (bfr.cpm > 0) { + bidObject = bidfactory.createBid(1); + bidObject.bidderCode = 'bidfluence'; + bidObject.cpm = bfr.cpm; + bidObject.ad = bfr.ad; + bidObject.width = bfr.width; + bidObject.height = bfr.height; + } else { + bidObject = bidfactory.createBid(2); + bidObject.bidderCode = 'bidfluence'; + } + bidmanager.addBidResponse(bfr.placementCode, bidObject); + }; - if (bfr.cpm > 0) { - bidObject = bidfactory.createBid(1); - bidObject.bidderCode = 'bidfluence'; - bidObject.cpm = bfr.cpm; - bidObject.ad = bfr.ad; - bidObject.width = bfr.width; - bidObject.height = bfr.height; - } else { - bidObject = bidfactory.createBid(2); - bidObject.bidderCode = 'bidfluence'; + function _callBids(params) { + var bfbids = params.bids || []; + for (var i = 0; i < bfbids.length; i++) { + var bid = bfbids[i]; + call(bid); + } } - bidmanager.addBidResponse(bfr.placementCode, bidObject); - }; - function _callBids(params) { - var bfbids = params.bids || []; - for (var i = 0; i < bfbids.length; i++) { - var bid = bfbids[i]; - call(bid); + function call(bid) { + + var adunitId = utils.getBidIdParameter('adunitId', bid.params); + /* jshint ignore:start */ + var publisherId = utils.getBidIdParameter('pubId', bid.params); + var reservePrice = utils.getBidIdParameter('reservePrice', bid.params);//This is optional. For dynamic reserve price only. + var pbjsBfobj = { + placementCode: bid.placementCode + }; + /* jshint ignore:end */ + var s = document.createElement('script'); + s.async = true; + s.id = adunitId; + s.onload = function () { + /* jshint ignore:start */ + FORGE.init([adunitId, publisherId, pbjsBfobj, reservePrice]); + FORGE.fire(); + /* jshint ignore:end */ + }; + s.src = "//bidfluence.azureedge.net/forge.js"; + var b = document.getElementsByTagName('head')[0]; + b.parentNode.insertBefore(s, b); } - } - - function call(bid) { - var cbID = utils.getUniqueIdentifierStr(); - var adunitId = utils.getBidIdParameter('adunitId', bid.params); - /* jshint ignore:start */ - var publisherId = utils.getBidIdParameter('pubId', bid.params); - var reservePrice = utils.getBidIdParameter('reservePrice', bid.params);//This is optional. For dynamic reserve price only. - var pbjsBfobj = { - cbID: cbID, - placementCode: bid.placementCode + return { + callBids: _callBids }; - /* jshint ignore:end */ - var s = document.createElement('script'); - s.async = true; - s.id = adunitId; - s.onload = function () { - /* jshint ignore:start */ - FORGE.init([adunitId, publisherId, pbjsBfobj, reservePrice]); - FORGE.fire(); - /* jshint ignore:end */ - }; - s.src = "//bidfluence.azureedge.net/forge.js"; 0 - - var b = document.getElementsByTagName('head')[0]; - b.parentNode.insertBefore(s, b); - - bfPbjsCB[cbID] = bidfluenceCB; - } - - return { - callBids: _callBids - }; }; -module.exports = BidderNameAdapter; \ No newline at end of file +module.exports = BidfluenceAdapter; From a099b3aa3504c5114f6d774a17207f3d21c2f628 Mon Sep 17 00:00:00 2001 From: Francesco Date: Thu, 2 Mar 2017 03:36:21 -0600 Subject: [PATCH 04/10] Final review --- src/adapters/bidfluence.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/adapters/bidfluence.js b/src/adapters/bidfluence.js index 13a09497d8f..8db115e1901 100644 --- a/src/adapters/bidfluence.js +++ b/src/adapters/bidfluence.js @@ -7,7 +7,6 @@ var BidfluenceAdapter = function BidfluenceAdapter() { //Callback window.bfPbjsCB = function (bfr) { var bidObject = null; - if (bfr.cpm > 0) { bidObject = bidfactory.createBid(1); bidObject.bidderCode = 'bidfluence'; @@ -31,11 +30,10 @@ var BidfluenceAdapter = function BidfluenceAdapter() { } function call(bid) { - var adunitId = utils.getBidIdParameter('adunitId', bid.params); /* jshint ignore:start */ var publisherId = utils.getBidIdParameter('pubId', bid.params); - var reservePrice = utils.getBidIdParameter('reservePrice', bid.params);//This is optional. For dynamic reserve price only. + var reservePrice = utils.getBidIdParameter('reservePrice', bid.params); var pbjsBfobj = { placementCode: bid.placementCode }; @@ -58,5 +56,4 @@ var BidfluenceAdapter = function BidfluenceAdapter() { callBids: _callBids }; }; - module.exports = BidfluenceAdapter; From d1b2b1cad206ca92e5418b657e706c827a5591ae Mon Sep 17 00:00:00 2001 From: Francesco Date: Thu, 2 Mar 2017 03:38:16 -0600 Subject: [PATCH 05/10] First commit, Test passed --- test/spec/adapters/bidfluence_spec.js | 74 +++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 test/spec/adapters/bidfluence_spec.js diff --git a/test/spec/adapters/bidfluence_spec.js b/test/spec/adapters/bidfluence_spec.js new file mode 100644 index 00000000000..e2da722d791 --- /dev/null +++ b/test/spec/adapters/bidfluence_spec.js @@ -0,0 +1,74 @@ +describe('Bidfluence Adapter', () => { + const expect = require('chai').expect; + const adapter = require('src/adapters/bidfluence'); + const bidmanager = require('src/bidmanager'); + + var REQUEST = { + bidderCode: "bidfluence", + sizes: [[300, 250]], + placementCode: "div-1", + bids: [{ + bidder: 'bidfluence', + params: { + pubId: "747efe9c-5f8a-4b6e-872b-8e9939816298", + adunitId: "c4bbd807-7d22-485f-80f1-ba008ef1c619" + } + }] + }; + + var RESPONSE = { + ad: "ad-code", + cpm: 0.9, + width: 300, + height: 250, + placementCode: "div-1" + }; + + var NO_RESPONSE = { + ad: "ad-code", + cpm: 0, + width: 300, + height: 250, + placementCode: "div-1" + }; + + it('Should exist and be a function', function () { + expect(window.bfPbjsCB).to.exist.and.to.be.a('function'); + }); + + it('Shoud push a valid bid', () => { + + var stubAddBidResponse = sinon.stub(bidmanager, "addBidResponse"); + pbjs._bidsRequested.push(REQUEST); + adapter(); + window.bfPbjsCB(RESPONSE); + + var bidPlacementCode1 = stubAddBidResponse.getCall(0).args[0]; + var bidObject1 = stubAddBidResponse.getCall(0).args[1]; + + expect(bidPlacementCode1).to.equal("div-1",); + expect(bidObject1.getStatusCode()).to.equal(1); + expect(bidObject1.bidderCode).to.equal('bidfluence'); + + stubAddBidResponse.restore(); + }); + + it('Shoud push an empty bid', () => { + + var stubAddBidResponse = sinon.stub(bidmanager, "addBidResponse"); + pbjs._bidsRequested.push(REQUEST); + adapter(); + + window.bfPbjsCB(NO_RESPONSE); + + var bidPlacementCode1 = stubAddBidResponse.getCall(0).args[0]; + var bidObject1 = stubAddBidResponse.getCall(0).args[1]; + + expect(bidPlacementCode1).to.equal("div-1",); + expect(bidObject1.getStatusCode()).to.equal(2); + expect(bidObject1.bidderCode).to.equal('bidfluence'); + + stubAddBidResponse.restore(); + + }); +}); From 79513118231ed0f18ae56f8b906054e10de1b52d Mon Sep 17 00:00:00 2001 From: Francesco Date: Wed, 8 Mar 2017 04:39:58 -0600 Subject: [PATCH 06/10] Addressed change request (all but the loader one) -Changed window with $$PREBID_GLOBAL$$ -Added bid request as second param to match request response pair -Didn't change the loader since does not support custom Id to script element, necessary for our code to work. --- src/adapters/bidfluence.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/adapters/bidfluence.js b/src/adapters/bidfluence.js index 8db115e1901..529f36aa49f 100644 --- a/src/adapters/bidfluence.js +++ b/src/adapters/bidfluence.js @@ -3,21 +3,23 @@ const bidfactory = require('../bidfactory.js'); const utils = require('../utils.js'); var BidfluenceAdapter = function BidfluenceAdapter() { - //Callback - window.bfPbjsCB = function (bfr) { + + $$PREBID_GLOBAL$$.bfPbjsCB = function (bfr) { + var bidRequest = utils.getBidRequest(bfr.cbID); var bidObject = null; if (bfr.cpm > 0) { - bidObject = bidfactory.createBid(1); + bidObject = bidfactory.createBid(1, bidRequest); bidObject.bidderCode = 'bidfluence'; bidObject.cpm = bfr.cpm; bidObject.ad = bfr.ad; bidObject.width = bfr.width; bidObject.height = bfr.height; } else { - bidObject = bidfactory.createBid(2); + bidObject = bidfactory.createBid(2, bidRequest); bidObject.bidderCode = 'bidfluence'; } + bidmanager.addBidResponse(bfr.placementCode, bidObject); }; @@ -35,9 +37,11 @@ var BidfluenceAdapter = function BidfluenceAdapter() { var publisherId = utils.getBidIdParameter('pubId', bid.params); var reservePrice = utils.getBidIdParameter('reservePrice', bid.params); var pbjsBfobj = { - placementCode: bid.placementCode + placementCode: bid.placementCode, + cbID: bid.bidId }; /* jshint ignore:end */ + var s = document.createElement('script'); s.async = true; s.id = adunitId; @@ -56,4 +60,5 @@ var BidfluenceAdapter = function BidfluenceAdapter() { callBids: _callBids }; }; + module.exports = BidfluenceAdapter; From 510cc0fb17cb956e4000b279bb6f329cd87fa3dd Mon Sep 17 00:00:00 2001 From: Francesco Date: Wed, 8 Mar 2017 05:14:50 -0600 Subject: [PATCH 07/10] Update reflecting the adapter changes. --- test/spec/adapters/bidfluence_spec.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/spec/adapters/bidfluence_spec.js b/test/spec/adapters/bidfluence_spec.js index e2da722d791..75d6aa98fdf 100644 --- a/test/spec/adapters/bidfluence_spec.js +++ b/test/spec/adapters/bidfluence_spec.js @@ -33,7 +33,7 @@ describe('Bidfluence Adapter', () => { }; it('Should exist and be a function', function () { - expect(window.bfPbjsCB).to.exist.and.to.be.a('function'); + expect($$PREBID_GLOBAL$$.bfPbjsCB).to.exist.and.to.be.a('function'); }); it('Shoud push a valid bid', () => { @@ -41,7 +41,7 @@ describe('Bidfluence Adapter', () => { var stubAddBidResponse = sinon.stub(bidmanager, "addBidResponse"); pbjs._bidsRequested.push(REQUEST); adapter(); - window.bfPbjsCB(RESPONSE); + $$PREBID_GLOBAL$$.bfPbjsCB(RESPONSE); var bidPlacementCode1 = stubAddBidResponse.getCall(0).args[0]; var bidObject1 = stubAddBidResponse.getCall(0).args[1]; @@ -59,7 +59,7 @@ describe('Bidfluence Adapter', () => { pbjs._bidsRequested.push(REQUEST); adapter(); - window.bfPbjsCB(NO_RESPONSE); + $$PREBID_GLOBAL$$.bfPbjsCB(NO_RESPONSE); var bidPlacementCode1 = stubAddBidResponse.getCall(0).args[0]; var bidObject1 = stubAddBidResponse.getCall(0).args[1]; From 1bcde3b6794ea8a76b4e8005fdcc3aa1b15ce9a9 Mon Sep 17 00:00:00 2001 From: Francesco Date: Wed, 8 Mar 2017 20:49:18 -0600 Subject: [PATCH 08/10] Final review, completed update requests. --- src/adapters/bidfluence.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/adapters/bidfluence.js b/src/adapters/bidfluence.js index 529f36aa49f..10aec505e23 100644 --- a/src/adapters/bidfluence.js +++ b/src/adapters/bidfluence.js @@ -1,9 +1,11 @@ const bidmanager = require('../bidmanager.js'); const bidfactory = require('../bidfactory.js'); const utils = require('../utils.js'); +const adloader = require('../adloader'); var BidfluenceAdapter = function BidfluenceAdapter() { - //Callback + + const scriptUrl = "//bidfluence.azureedge.net/forge.js"; $$PREBID_GLOBAL$$.bfPbjsCB = function (bfr) { var bidRequest = utils.getBidRequest(bfr.cbID); @@ -42,18 +44,14 @@ var BidfluenceAdapter = function BidfluenceAdapter() { }; /* jshint ignore:end */ - var s = document.createElement('script'); - s.async = true; - s.id = adunitId; - s.onload = function () { + + var cb = function () { /* jshint ignore:start */ FORGE.init([adunitId, publisherId, pbjsBfobj, reservePrice]); - FORGE.fire(); /* jshint ignore:end */ }; - s.src = "//bidfluence.azureedge.net/forge.js"; - var b = document.getElementsByTagName('head')[0]; - b.parentNode.insertBefore(s, b); + + adloader.loadScript(scriptUrl, cb); } return { From 899fc40eb2c528b5cabe50cc1efc17b4cdedca26 Mon Sep 17 00:00:00 2001 From: Francesco Date: Wed, 8 Mar 2017 21:04:12 -0600 Subject: [PATCH 09/10] Fixed Indentation --- src/adapters/bidfluence.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/adapters/bidfluence.js b/src/adapters/bidfluence.js index 10aec505e23..ceaaa5b56e2 100644 --- a/src/adapters/bidfluence.js +++ b/src/adapters/bidfluence.js @@ -34,8 +34,8 @@ var BidfluenceAdapter = function BidfluenceAdapter() { } function call(bid) { + /* jshint ignore:start */ var adunitId = utils.getBidIdParameter('adunitId', bid.params); - /* jshint ignore:start */ var publisherId = utils.getBidIdParameter('pubId', bid.params); var reservePrice = utils.getBidIdParameter('reservePrice', bid.params); var pbjsBfobj = { @@ -43,20 +43,16 @@ var BidfluenceAdapter = function BidfluenceAdapter() { cbID: bid.bidId }; /* jshint ignore:end */ - - + var cb = function () { /* jshint ignore:start */ FORGE.init([adunitId, publisherId, pbjsBfobj, reservePrice]); /* jshint ignore:end */ }; - adloader.loadScript(scriptUrl, cb); } - return { callBids: _callBids }; }; - module.exports = BidfluenceAdapter; From 1e2327412df815eed8c9d1fa90ae24d493202b24 Mon Sep 17 00:00:00 2001 From: Francesco Date: Wed, 8 Mar 2017 21:24:53 -0600 Subject: [PATCH 10/10] Fixed global variable causing validation error. --- src/adapters/bidfluence.js | 87 +++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 44 deletions(-) diff --git a/src/adapters/bidfluence.js b/src/adapters/bidfluence.js index ceaaa5b56e2..e5253e09878 100644 --- a/src/adapters/bidfluence.js +++ b/src/adapters/bidfluence.js @@ -5,54 +5,53 @@ const adloader = require('../adloader'); var BidfluenceAdapter = function BidfluenceAdapter() { - const scriptUrl = "//bidfluence.azureedge.net/forge.js"; - - $$PREBID_GLOBAL$$.bfPbjsCB = function (bfr) { - var bidRequest = utils.getBidRequest(bfr.cbID); - var bidObject = null; - if (bfr.cpm > 0) { - bidObject = bidfactory.createBid(1, bidRequest); - bidObject.bidderCode = 'bidfluence'; - bidObject.cpm = bfr.cpm; - bidObject.ad = bfr.ad; - bidObject.width = bfr.width; - bidObject.height = bfr.height; - } else { - bidObject = bidfactory.createBid(2, bidRequest); - bidObject.bidderCode = 'bidfluence'; - } - - bidmanager.addBidResponse(bfr.placementCode, bidObject); - }; + const scriptUrl = "//bidfluence.azureedge.net/forge.js"; - function _callBids(params) { - var bfbids = params.bids || []; - for (var i = 0; i < bfbids.length; i++) { - var bid = bfbids[i]; - call(bid); - } + $$PREBID_GLOBAL$$.bfPbjsCB = function (bfr) { + var bidRequest = utils.getBidRequest(bfr.cbID); + var bidObject = null; + if (bfr.cpm > 0) { + bidObject = bidfactory.createBid(1, bidRequest); + bidObject.bidderCode = 'bidfluence'; + bidObject.cpm = bfr.cpm; + bidObject.ad = bfr.ad; + bidObject.width = bfr.width; + bidObject.height = bfr.height; + } else { + bidObject = bidfactory.createBid(2, bidRequest); + bidObject.bidderCode = 'bidfluence'; } - function call(bid) { - /* jshint ignore:start */ - var adunitId = utils.getBidIdParameter('adunitId', bid.params); - var publisherId = utils.getBidIdParameter('pubId', bid.params); - var reservePrice = utils.getBidIdParameter('reservePrice', bid.params); - var pbjsBfobj = { - placementCode: bid.placementCode, - cbID: bid.bidId - }; - /* jshint ignore:end */ - - var cb = function () { - /* jshint ignore:start */ - FORGE.init([adunitId, publisherId, pbjsBfobj, reservePrice]); - /* jshint ignore:end */ - }; - adloader.loadScript(scriptUrl, cb); + bidmanager.addBidResponse(bfr.placementCode, bidObject); + }; + + function _callBids(params) { + var bfbids = params.bids || []; + for (var i = 0; i < bfbids.length; i++) { + var bid = bfbids[i]; + call(bid); } - return { - callBids: _callBids + } + function call(bid) { + + var adunitId = utils.getBidIdParameter('adunitId', bid.params); + var publisherId = utils.getBidIdParameter('pubId', bid.params); + var reservePrice = utils.getBidIdParameter('reservePrice', bid.params); + var pbjsBfobj = { + placementCode: bid.placementCode, + cbID: bid.bidId + }; + + var cb = function () { + /* globals FORGE */ + FORGE.init([adunitId, publisherId, pbjsBfobj, reservePrice]); }; + + adloader.loadScript(scriptUrl, cb); + } + return { + callBids: _callBids + }; }; + module.exports = BidfluenceAdapter;