-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Bidfluence Adapter * Bidfluence adapter * Fixed callback name * Final review * First commit, Test passed * 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. * Update reflecting the adapter changes. * Final review, completed update requests. * Fixed Indentation * Fixed global variable causing validation error.
- Loading branch information
1 parent
c021464
commit 6d6fb7e
Showing
3 changed files
with
133 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
const bidmanager = require('../bidmanager.js'); | ||
const bidfactory = require('../bidfactory.js'); | ||
const utils = require('../utils.js'); | ||
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); | ||
}; | ||
|
||
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); | ||
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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($$PREBID_GLOBAL$$.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(); | ||
$$PREBID_GLOBAL$$.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(); | ||
|
||
$$PREBID_GLOBAL$$.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(); | ||
|
||
}); | ||
}); |