From 60d2f0fc81bb3fdbf76b5a93db10fe9b03976d83 Mon Sep 17 00:00:00 2001 From: Mikhail Ivanchenko Date: Mon, 12 Nov 2018 18:21:50 +0300 Subject: [PATCH] Add nextMilleniumBidAdapter (#3249) * Add nextMilleniumBidAdapter * fix bugs --- modules/nextMilleniumBidAdapter.js | 85 +++++++++++++++++ modules/nextMilleniumBidAdapter.md | 28 ++++++ .../modules/nextMilleniumBidAdapter_spec.js | 91 +++++++++++++++++++ 3 files changed, 204 insertions(+) create mode 100644 modules/nextMilleniumBidAdapter.js create mode 100644 modules/nextMilleniumBidAdapter.md create mode 100644 test/spec/modules/nextMilleniumBidAdapter_spec.js diff --git a/modules/nextMilleniumBidAdapter.js b/modules/nextMilleniumBidAdapter.js new file mode 100644 index 00000000000..0d91d58cd49 --- /dev/null +++ b/modules/nextMilleniumBidAdapter.js @@ -0,0 +1,85 @@ +import * as utils from 'src/utils'; +import { registerBidder } from 'src/adapters/bidderFactory'; +import { BANNER } from 'src/mediaTypes'; + +const BIDDER_CODE = 'nextMillenium'; +const HOST = 'https://brainlyads.com'; +const CURRENCY = 'USD'; +const TIME_TO_LIVE = 360; + +export const spec = { + code: BIDDER_CODE, + supportedMediaTypes: [BANNER], + + isBidRequestValid: function(bid) { + return !!( + bid.params.placement_id && utils.isNumber(bid.params.placement_id) + ); + }, + + buildRequests: function(validBidRequests) { + let requests = []; + + utils._each(validBidRequests, function(bid) { + requests.push({ + method: 'POST', + url: HOST + '/hb/s2s', + options: { + contentType: 'application/json', + withCredentials: true + }, + data: JSON.stringify({ + placement_id: utils.getBidIdParameter('placement_id', bid.params) + }), + bidId: bid.bidId + }); + }); + + return requests; + }, + + interpretResponse: function(serverResponse, bidRequest) { + try { + const bidResponse = serverResponse.body; + const bidResponses = []; + + if (Number(bidResponse.cpm) > 0) { + bidResponses.push({ + requestId: bidRequest.bidId, + cpm: bidResponse.cpm, + width: bidResponse.width, + height: bidResponse.height, + creativeId: bidResponse.creativeId, + currency: CURRENCY, + netRevenue: false, + ttl: TIME_TO_LIVE, + ad: bidResponse.ad + }); + } + + return bidResponses; + } catch (err) { + utils.logError(err); + return []; + } + }, + + getUserSyncs: function(syncOptions) { + const syncs = [] + if (syncOptions.iframeEnabled) { + syncs.push({ + type: 'iframe', + url: HOST + '/hb/s2s/matching' + }); + } + + if (syncOptions.pixelEnabled) { + syncs.push({ + type: 'image', + url: HOST + '/hb/s2s/matching' + }); + } + return syncs; + } +}; +registerBidder(spec); diff --git a/modules/nextMilleniumBidAdapter.md b/modules/nextMilleniumBidAdapter.md new file mode 100644 index 00000000000..a89e7e30822 --- /dev/null +++ b/modules/nextMilleniumBidAdapter.md @@ -0,0 +1,28 @@ +# Overview +``` +Module Name: NextMillenium Bid Adapter +Module Type: Bidder Adapter +Maintainer: mikhail.ivanchenko@iageengineering.net +``` + +# Description +Module that connects to NextMillenium's server for bids. +Currently module supports only banner mediaType. + +# Test Parameters +``` + var adUnits = [{ + code: '/test/div', + mediaTypes: { + banner: { + sizes: [[300, 250]] + } + }, + bids: [{ + bidder: 'nextMillenium', + params: { + placement_id: -1 + } + }] + }]; +``` \ No newline at end of file diff --git a/test/spec/modules/nextMilleniumBidAdapter_spec.js b/test/spec/modules/nextMilleniumBidAdapter_spec.js new file mode 100644 index 00000000000..74c8ff5dfd9 --- /dev/null +++ b/test/spec/modules/nextMilleniumBidAdapter_spec.js @@ -0,0 +1,91 @@ +import { expect } from 'chai'; +import { spec } from 'modules/nextMilleniumBidAdapter'; + +describe('nextMilleniumBidAdapterTests', function() { + let bidRequestData = { + bids: [ + { + bidId: 'transaction_1234', + bidder: 'nextMillenium', + params: { + placement_id: 12345 + }, + sizes: [[300, 250]] + } + ] + }; + let request = []; + + it('validate_pub_params', function() { + expect( + spec.isBidRequestValid({ + bidder: 'nextMillenium', + params: { + placement_id: 12345 + } + }) + ).to.equal(true); + }); + + it('validate_generated_params', function() { + let bidRequestData = [ + { + bidId: 'bid1234', + bidder: 'nextMillenium', + params: { placement_id: -1 }, + sizes: [[300, 250]] + } + ]; + let request = spec.buildRequests(bidRequestData); + expect(request[0].bidId).to.equal('bid1234'); + }); + + it('validate_getUserSyncs_function', function() { + expect(spec.getUserSyncs({ iframeEnabled: true })).to.have.lengthOf(1); + expect(spec.getUserSyncs({ iframeEnabled: false })).to.have.lengthOf(0); + + let pixel = spec.getUserSyncs({ iframeEnabled: true }); + expect(pixel[0].type).to.equal('iframe'); + expect(pixel[0].url).to.equal('https://brainlyads.com/hb/s2s/matching'); + }); + + it('validate_response_params', function() { + let serverResponse = { + body: { + cpm: 1.7, + width: 300, + height: 250, + creativeId: 'p35t0enob6twbt9mofjc8e', + ad: 'Hello! It\'s a test ad!' + } + }; + + let bids = spec.interpretResponse(serverResponse, bidRequestData.bids[0]); + expect(bids).to.have.lengthOf(1); + + let bid = bids[0]; + + expect(bid.creativeId).to.equal('p35t0enob6twbt9mofjc8e'); + expect(bid.ad).to.equal('Hello! It\'s a test ad!'); + expect(bid.cpm).to.equal(1.7); + expect(bid.width).to.equal(300); + expect(bid.height).to.equal(250); + expect(bid.currency).to.equal('USD'); + }); + + it('validate_response_params_with passback', function() { + let serverResponse = { + body: [ + { + hash: '1e100887dd614b0909bf6c49ba7f69fdd1360437', + content: 'Ad html passback', + size: [300, 250], + is_passback: 1 + } + ] + }; + let bids = spec.interpretResponse(serverResponse); + + expect(bids).to.have.lengthOf(0); + }); +});