From 2cc71fb949459478e12730e6e41b6ce265a078ee Mon Sep 17 00:00:00 2001 From: varashellov Date: Tue, 1 Aug 2017 09:38:25 -0700 Subject: [PATCH 01/32] Add PlatformioBidAdapter --- modules/platformioBidAdapter.js | 55 +++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 modules/platformioBidAdapter.js diff --git a/modules/platformioBidAdapter.js b/modules/platformioBidAdapter.js new file mode 100644 index 00000000000..6a4e9a65756 --- /dev/null +++ b/modules/platformioBidAdapter.js @@ -0,0 +1,55 @@ +var bidfactory = require('../bidfactory.js'); +var bidmanager = require('../bidmanager.js'); +var adloader = require('../adloader.js'); +var utils = require('../utils.js'); +var CONSTANTS = require('../constants.json'); + +var PlatformIOAdapter = function PlatformIOAdapter() { + function _callBids(params) { + var bidURL, bids = params.bids || [], requestURL = window.location.protocol + '//adx1js.s3.amazonaws.com/pb_ortb.js?cb=' + new Date().getTime() + '&ver=1&'; + + for (var i = 0; i < bids.length; i++) { + var requestParams = {}, bid = bids[i]; + + requestParams.pub_id = bid.params.pubId; + requestParams.placement_id = bid.params.placementId; + requestParams.site_id = bid.params.siteId; + + var parseSized = utils.parseSizesInput(bid.sizes), arrSize = parseSized[0].split('x'); + + requestParams.width = arrSize[0]; + requestParams.height = arrSize[1]; + requestParams.callback = 'pbjs._doPlatformIOCallback'; + requestParams.callback_uid = bid.bidId; + bidURL = requestURL + utils.parseQueryStringParameters(requestParams); + + utils.logMessage('PlatformIO.prebid, Bid ID: ' + bid.bidId + ', Pub ID: ' + bid.params.pubId); + adloader.loadScript(bidURL); + } + } + + pbjs._doPlatformIOCallback = function (response) { + var bidObject, bidRequest, callbackID; + callbackID = response.callback_uid; + bidRequest = utils.getBidRequest(callbackID); + if (response.cpm > 0) { + bidObject = bidfactory.createBid(CONSTANTS.STATUS.GOOD, bidRequest); + bidObject.bidderCode = 'platformio'; + bidObject.cpm = response.cpm; + bidObject.ad = response.tag; + bidObject.width = response.width; + bidObject.height = response.height; + } else { + bidObject = bidfactory.createBid(CONSTANTS.STATUS.NO_BID, bidRequest); + bidObject.bidderCode = 'platformio'; + utils.logMessage('No Bid response from Admachine request: ' + callbackID); + } + bidmanager.addBidResponse(bidRequest.placementCode, bidObject); + }; + + return { + callBids: _callBids + }; +}; + +module.exports = PlatformIOAdapter; From 6801ca138fbdd0187cff957cfcb345e41c985744 Mon Sep 17 00:00:00 2001 From: varashellov Date: Wed, 2 Aug 2017 09:05:18 -0700 Subject: [PATCH 02/32] Update platformioBidAdapter.js --- modules/platformioBidAdapter.js | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/modules/platformioBidAdapter.js b/modules/platformioBidAdapter.js index 6a4e9a65756..2c157d4842b 100644 --- a/modules/platformioBidAdapter.js +++ b/modules/platformioBidAdapter.js @@ -1,21 +1,26 @@ -var bidfactory = require('../bidfactory.js'); -var bidmanager = require('../bidmanager.js'); -var adloader = require('../adloader.js'); -var utils = require('../utils.js'); -var CONSTANTS = require('../constants.json'); +var bidfactory = require('src/bidfactory.js'); +var bidmanager = require('src/bidmanager.js'); +var adloader = require('src/adloader.js'); +var utils = require('src/utils.js'); +var CONSTANTS = require('src/constants.json'); +var adaptermanager = require('src/adaptermanager'); var PlatformIOAdapter = function PlatformIOAdapter() { function _callBids(params) { - var bidURL, bids = params.bids || [], requestURL = window.location.protocol + '//adx1js.s3.amazonaws.com/pb_ortb.js?cb=' + new Date().getTime() + '&ver=1&'; + var bidURL; + var bids = params.bids || []; + var requestURL = window.location.protocol + '//adx1js.s3.amazonaws.com/pb_ortb.js?cb=' + new Date().getTime() + '&ver=1&'; for (var i = 0; i < bids.length; i++) { - var requestParams = {}, bid = bids[i]; + var requestParams = {}; + var bid = bids[i]; requestParams.pub_id = bid.params.pubId; requestParams.placement_id = bid.params.placementId; requestParams.site_id = bid.params.siteId; - var parseSized = utils.parseSizesInput(bid.sizes), arrSize = parseSized[0].split('x'); + var parseSized = utils.parseSizesInput(bid.sizes); + var arrSize = parseSized[0].split('x'); requestParams.width = arrSize[0]; requestParams.height = arrSize[1]; @@ -29,7 +34,9 @@ var PlatformIOAdapter = function PlatformIOAdapter() { } pbjs._doPlatformIOCallback = function (response) { - var bidObject, bidRequest, callbackID; + var bidObject; + var bidRequest; + var callbackID; callbackID = response.callback_uid; bidRequest = utils.getBidRequest(callbackID); if (response.cpm > 0) { @@ -42,7 +49,7 @@ var PlatformIOAdapter = function PlatformIOAdapter() { } else { bidObject = bidfactory.createBid(CONSTANTS.STATUS.NO_BID, bidRequest); bidObject.bidderCode = 'platformio'; - utils.logMessage('No Bid response from Admachine request: ' + callbackID); + utils.logMessage('No Bid response from Platformio request: ' + callbackID); } bidmanager.addBidResponse(bidRequest.placementCode, bidObject); }; @@ -51,5 +58,6 @@ var PlatformIOAdapter = function PlatformIOAdapter() { callBids: _callBids }; }; +adaptermanager.registerBidAdapter(new PlatformIOAdapter(), 'platformio'); module.exports = PlatformIOAdapter; From 9bdcd7e9d1164ef5b5b3760bf16c2b22b29e424c Mon Sep 17 00:00:00 2001 From: varashellov Date: Wed, 2 Aug 2017 09:08:49 -0700 Subject: [PATCH 03/32] Add files via upload --- .../spec/modules/platformioBidAdapter_spec.js | 157 ++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 test/spec/modules/platformioBidAdapter_spec.js diff --git a/test/spec/modules/platformioBidAdapter_spec.js b/test/spec/modules/platformioBidAdapter_spec.js new file mode 100644 index 00000000000..76fa0cfea5a --- /dev/null +++ b/test/spec/modules/platformioBidAdapter_spec.js @@ -0,0 +1,157 @@ +describe('platformio adapter tests', function () { + var expect = require('chai').expect; + var urlParse = require('url-parse'); + var querystringify = require('querystringify'); + var adapter = require('modules/platformioBidAdapter'); + var adLoader = require('src/adloader'); + var bidmanager = require('src/bidmanager'); + + var stubLoadScript; + + beforeEach(function () { + stubLoadScript = sinon.stub(adLoader, 'loadScript'); + }); + + afterEach(function () { + stubLoadScript.restore(); + }); + + describe('creation of bid url', function () { + if (typeof ($$PREBID_GLOBAL$$._bidsReceived) === 'undefined') { + $$PREBID_GLOBAL$$._bidsReceived = []; + } + if (typeof ($$PREBID_GLOBAL$$._bidsRequested) === 'undefined') { + $$PREBID_GLOBAL$$._bidsRequested = []; + } + + it('bid request for single placement', function () { + var params = { + bids: [{ + placementCode: '/19968336/header-bid-tag-0', + sizes: [[300, 250]], + bidId: 'bid1111', + bidder: 'platformio', + params: { pubId: '37054', siteId: '123', placementId: '1234' } + }] + }; + + adapter().callBids(params); + + var bidUrl = stubLoadScript.getCall(0).args[0]; + + sinon.assert.calledOnce(stubLoadScript); + + var parsedBidUrl = urlParse(bidUrl); + var parsedBidUrlQueryString = querystringify.parse(parsedBidUrl.query); + expect(parsedBidUrlQueryString).to.have.property('pub_id').and.to.equal('37054'); + expect(parsedBidUrlQueryString).to.have.property('site_id').and.to.equal('123'); + expect(parsedBidUrlQueryString).to.have.property('placement_id').and.to.equal('1234'); + expect(parsedBidUrlQueryString).to.have.property('width').and.to.equal('300'); + expect(parsedBidUrlQueryString).to.have.property('height').and.to.equal('250'); + }); + }); + + describe('handling bid response', function () { + it('should return complete bid response', function() { + var stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse'); + + var params = { + bids: [{ + placementCode: '/19968336/header-bid-tag-0', + sizes: [[300, 250]], + bidId: 'bid1111', + bidder: 'platformio', + params: { pubId: '37054', siteId: '123', placementId: '1234' } + }] + }; + + var response = { + cpm: 1, + width: 300, + height: 250, + callback_uid: 'bid1111', + tag: '