From 58983e6416ee702d02d80d1bceff4b3b248177ea Mon Sep 17 00:00:00 2001 From: Aiholkin Date: Wed, 28 Oct 2020 21:49:29 +0200 Subject: [PATCH 01/15] initial --- modules/lunamediahbBidAdapter.js | 104 ++++++ modules/lunamediahbBidAdapter.md | 80 +++++ .../modules/lunamediahbBidAdapter_spec.js | 304 ++++++++++++++++++ 3 files changed, 488 insertions(+) create mode 100644 modules/lunamediahbBidAdapter.js create mode 100644 modules/lunamediahbBidAdapter.md create mode 100644 test/spec/modules/lunamediahbBidAdapter_spec.js diff --git a/modules/lunamediahbBidAdapter.js b/modules/lunamediahbBidAdapter.js new file mode 100644 index 00000000000..2d5d34ec066 --- /dev/null +++ b/modules/lunamediahbBidAdapter.js @@ -0,0 +1,104 @@ +import {registerBidder} from '../src/adapters/bidderFactory.js'; +import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js'; +import * as utils from '../src/utils.js'; + +const BIDDER_CODE = 'lunamediahb'; +const AD_URL = 'https://balancer.lmgssp.com/?c=o&m=multi'; + +function isBidResponseValid(bid) { + if (!bid.requestId || !bid.cpm || !bid.creativeId || + !bid.ttl || !bid.currency) { + return false; + } + switch (bid.mediaType) { + case BANNER: + return Boolean(bid.width && bid.height && bid.ad); + case VIDEO: + return Boolean(bid.vastUrl); + case NATIVE: + return Boolean(bid.native && bid.native.impressionTrackers); + default: + return false; + } +} + +export const spec = { + code: BIDDER_CODE, + supportedMediaTypes: [BANNER, VIDEO, NATIVE], + + isBidRequestValid: (bid) => { + return Boolean(bid.bidId && bid.params && !isNaN(parseInt(bid.params.placementId))); + }, + + buildRequests: (validBidRequests = [], bidderRequest) => { + let winTop = window; + let location; + try { + location = new URL(bidderRequest.refererInfo.referer) + winTop = window.top; + } catch (e) { + location = winTop.location; + utils.logMessage(e); + }; + + const placements = []; + const request = { + 'deviceWidth': winTop.screen.width, + 'deviceHeight': winTop.screen.height, + 'language': (navigator && navigator.language) ? navigator.language.split('-')[0] : '', + 'secure': 1, + 'host': location.host, + 'page': location.pathname, + 'placements': placements + }; + + if (bidderRequest) { + if (bidderRequest.uspConsent) { + request.ccpa = bidderRequest.uspConsent; + } + if (bidderRequest.gdprConsent) { + request.gdpr = bidderRequest.gdprConsent + } + } + + const len = validBidRequests.length; + for (let i = 0; i < len; i++) { + const bid = validBidRequests[i]; + const placement = { + placementId: bid.params.placementId, + bidId: bid.bidId, + traffic: bid.params.traffic || BANNER, + schain: bid.schain || {}, + }; + + if (bid.mediaTypes && bid.mediaTypes[BANNER] && bid.mediaTypes[BANNER].sizes) { + placement.sizes = bid.mediaTypes[BANNER].sizes; + } else if (bid.mediaTypes && bid.mediaTypes[VIDEO] && bid.mediaTypes[VIDEO].playerSize) { + placement.wPlayer = bid.mediaTypes[VIDEO].playerSize[0]; + placement.hPlayer = bid.mediaTypes[VIDEO].playerSize[1]; + } else if (bid.mediaTypes && bid.mediaTypes[NATIVE]) { + placement.native = bid.mediaTypes[NATIVE]; + } + placements.push(placement); + } + + return { + method: 'POST', + url: AD_URL, + data: request + }; + }, + + interpretResponse: (serverResponse) => { + let response = []; + for (let i = 0; i < serverResponse.body.length; i++) { + let resItem = serverResponse.body[i]; + if (isBidResponseValid(resItem)) { + response.push(resItem); + } + } + return response; + }, +}; + +registerBidder(spec); diff --git a/modules/lunamediahbBidAdapter.md b/modules/lunamediahbBidAdapter.md new file mode 100644 index 00000000000..da4013122f1 --- /dev/null +++ b/modules/lunamediahbBidAdapter.md @@ -0,0 +1,80 @@ +# Overview + +``` +Module Name: lunamedia Bidder Adapter +Module Type: lunamedia Bidder Adapter +Maintainer: support@lunamedia.io +``` + +# Description + +Module that connects to lunamedia demand sources + +# Test Parameters +``` + var adUnits = [ + // Will return static test banner + { + code: 'adunit1', + mediaTypes: { + banner: { + sizes: [[300, 250]], + } + }, + bids: [ + { + bidder: 'luna', + params: { + placementId: 0, + traffic: 'banner' + } + } + ] + }, + // Will return test vast xml. All video params are stored under placement in publishers UI + { + code: 'addunit2', + mediaTypes: { + video: { + playerSize: [640, 480], + context: 'instream' + } + }, + bids: [ + { + bidder: 'luna', + params: { + placementId: 0, + traffic: 'video' + } + } + ] + }, + { + code: 'addunit3', + mediaTypes: { + native: { + title: { + required: true + }, + body: { + required: true + }, + icon: { + required: true, + size: [64, 64] + } + } + }, + bids: [ + { + bidder: 'luna', + params: { + placementId: 0, + traffic: 'native' + } + } + ] + } + ]; +``` diff --git a/test/spec/modules/lunamediahbBidAdapter_spec.js b/test/spec/modules/lunamediahbBidAdapter_spec.js new file mode 100644 index 00000000000..ba0e6626f1c --- /dev/null +++ b/test/spec/modules/lunamediahbBidAdapter_spec.js @@ -0,0 +1,304 @@ +import {expect} from 'chai'; +import {spec} from '../../../modules/lunamediahbBidAdapter.js'; +import { BANNER, VIDEO, NATIVE } from '../../../src/mediaTypes.js'; + +describe('KrushmediabBidAdapter', function () { + const bid = { + bidId: '23fhj33i987f', + bidder: 'luna', + mediaTypes: { + [BANNER]: { + sizes: [[300, 250]] + } + }, + params: { + placementId: 783, + traffic: BANNER + } + }; + + const bidderRequest = { + refererInfo: { + referer: 'test.com' + } + }; + + describe('isBidRequestValid', function () { + it('Should return true if there are bidId, params and key parameters present', function () { + expect(spec.isBidRequestValid(bid)).to.be.true; + }); + it('Should return false if at least one of parameters is not present', function () { + delete bid.params.placementId; + expect(spec.isBidRequestValid(bid)).to.be.false; + }); + }); + + describe('buildRequests', function () { + let serverRequest = spec.buildRequests([bid], bidderRequest); + it('Creates a ServerRequest object with method, URL and data', function () { + expect(serverRequest).to.exist; + expect(serverRequest.method).to.exist; + expect(serverRequest.url).to.exist; + expect(serverRequest.data).to.exist; + }); + it('Returns POST method', function () { + expect(serverRequest.method).to.equal('POST'); + }); + it('Returns valid URL', function () { + expect(serverRequest.url).to.equal('https://balancer.lmgssp.com/?c=o&m=multi'); + }); + it('Returns valid data if array of bids is valid', function () { + let data = serverRequest.data; + expect(data).to.be.an('object'); + expect(data).to.have.all.keys('deviceWidth', 'deviceHeight', 'language', 'secure', 'host', 'page', 'placements'); + expect(data.deviceWidth).to.be.a('number'); + expect(data.deviceHeight).to.be.a('number'); + expect(data.language).to.be.a('string'); + expect(data.secure).to.be.within(0, 1); + expect(data.host).to.be.a('string'); + expect(data.page).to.be.a('string'); + expect(data.gdpr).to.not.exist; + expect(data.ccpa).to.not.exist; + let placement = data['placements'][0]; + expect(placement).to.have.keys('placementId', 'bidId', 'traffic', 'sizes', 'schain'); + expect(placement.placementId).to.equal(783); + expect(placement.bidId).to.equal('23fhj33i987f'); + expect(placement.traffic).to.equal(BANNER); + expect(placement.schain).to.be.an('object'); + expect(placement.sizes).to.be.an('array'); + }); + + it('Returns valid data for mediatype video', function () { + const playerSize = [300, 300]; + bid.mediaTypes = {}; + bid.params.traffic = VIDEO; + bid.mediaTypes[VIDEO] = { + playerSize + }; + serverRequest = spec.buildRequests([bid], bidderRequest); + let data = serverRequest.data; + expect(data).to.be.an('object'); + let placement = data['placements'][0]; + expect(placement).to.be.an('object'); + expect(placement).to.have.keys('placementId', 'bidId', 'traffic', 'wPlayer', 'hPlayer', 'schain'); + expect(placement.traffic).to.equal(VIDEO); + expect(placement.wPlayer).to.equal(playerSize[0]); + expect(placement.hPlayer).to.equal(playerSize[1]); + }); + + it('Returns valid data for mediatype native', function () { + const native = { + title: { + required: true + }, + body: { + required: true + }, + icon: { + required: true, + size: [64, 64] + } + }; + + bid.mediaTypes = {}; + bid.params.traffic = NATIVE; + bid.mediaTypes[NATIVE] = native; + serverRequest = spec.buildRequests([bid], bidderRequest); + let data = serverRequest.data; + expect(data).to.be.an('object'); + let placement = data['placements'][0]; + expect(placement).to.be.an('object'); + expect(placement).to.have.keys('placementId', 'bidId', 'traffic', 'native', 'schain'); + expect(placement.traffic).to.equal(NATIVE); + expect(placement.native).to.equal(native); + }); + + it('Returns data with gdprConsent and without uspConsent', function () { + bidderRequest.gdprConsent = 'test'; + serverRequest = spec.buildRequests([bid], bidderRequest); + let data = serverRequest.data; + expect(data.gdpr).to.exist; + expect(data.gdpr).to.be.a('string'); + expect(data.gdpr).to.equal(bidderRequest.gdprConsent); + expect(data.ccpa).to.not.exist; + delete bidderRequest.gdprConsent; + }); + + it('Returns data with uspConsent and without gdprConsent', function () { + bidderRequest.uspConsent = 'test'; + serverRequest = spec.buildRequests([bid], bidderRequest); + let data = serverRequest.data; + expect(data.ccpa).to.exist; + expect(data.ccpa).to.be.a('string'); + expect(data.ccpa).to.equal(bidderRequest.uspConsent); + expect(data.gdpr).to.not.exist; + }); + + it('Returns empty data if no valid requests are passed', function () { + serverRequest = spec.buildRequests([]); + let data = serverRequest.data; + expect(data.placements).to.be.an('array').that.is.empty; + }); + }); + describe('interpretResponse', function () { + it('Should interpret banner response', function () { + const banner = { + body: [{ + mediaType: 'banner', + width: 300, + height: 250, + cpm: 0.4, + ad: 'Test', + requestId: '23fhj33i987f', + ttl: 120, + creativeId: '2', + netRevenue: true, + currency: 'USD', + dealId: '1' + }] + }; + let bannerResponses = spec.interpretResponse(banner); + expect(bannerResponses).to.be.an('array').that.is.not.empty; + let dataItem = bannerResponses[0]; + expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'ad', 'ttl', 'creativeId', + 'netRevenue', 'currency', 'dealId', 'mediaType'); + expect(dataItem.requestId).to.equal('23fhj33i987f'); + expect(dataItem.cpm).to.equal(0.4); + expect(dataItem.width).to.equal(300); + expect(dataItem.height).to.equal(250); + expect(dataItem.ad).to.equal('Test'); + expect(dataItem.ttl).to.equal(120); + expect(dataItem.creativeId).to.equal('2'); + expect(dataItem.netRevenue).to.be.true; + expect(dataItem.currency).to.equal('USD'); + }); + it('Should interpret video response', function () { + const video = { + body: [{ + vastUrl: 'test.com', + mediaType: 'video', + cpm: 0.5, + requestId: '23fhj33i987f', + ttl: 120, + creativeId: '2', + netRevenue: true, + currency: 'USD', + dealId: '1' + }] + }; + let videoResponses = spec.interpretResponse(video); + expect(videoResponses).to.be.an('array').that.is.not.empty; + + let dataItem = videoResponses[0]; + expect(dataItem).to.have.all.keys('requestId', 'cpm', 'vastUrl', 'ttl', 'creativeId', + 'netRevenue', 'currency', 'dealId', 'mediaType'); + expect(dataItem.requestId).to.equal('23fhj33i987f'); + expect(dataItem.cpm).to.equal(0.5); + expect(dataItem.vastUrl).to.equal('test.com'); + expect(dataItem.ttl).to.equal(120); + expect(dataItem.creativeId).to.equal('2'); + expect(dataItem.netRevenue).to.be.true; + expect(dataItem.currency).to.equal('USD'); + }); + it('Should interpret native response', function () { + const native = { + body: [{ + mediaType: 'native', + native: { + clickUrl: 'test.com', + title: 'Test', + image: 'test.com', + impressionTrackers: ['test.com'], + }, + ttl: 120, + cpm: 0.4, + requestId: '23fhj33i987f', + creativeId: '2', + netRevenue: true, + currency: 'USD', + }] + }; + let nativeResponses = spec.interpretResponse(native); + expect(nativeResponses).to.be.an('array').that.is.not.empty; + + let dataItem = nativeResponses[0]; + expect(dataItem).to.have.keys('requestId', 'cpm', 'ttl', 'creativeId', 'netRevenue', 'currency', 'mediaType', 'native'); + expect(dataItem.native).to.have.keys('clickUrl', 'impressionTrackers', 'title', 'image') + expect(dataItem.requestId).to.equal('23fhj33i987f'); + expect(dataItem.cpm).to.equal(0.4); + expect(dataItem.native.clickUrl).to.equal('test.com'); + expect(dataItem.native.title).to.equal('Test'); + expect(dataItem.native.image).to.equal('test.com'); + expect(dataItem.native.impressionTrackers).to.be.an('array').that.is.not.empty; + expect(dataItem.native.impressionTrackers[0]).to.equal('test.com'); + expect(dataItem.ttl).to.equal(120); + expect(dataItem.creativeId).to.equal('2'); + expect(dataItem.netRevenue).to.be.true; + expect(dataItem.currency).to.equal('USD'); + }); + it('Should return an empty array if invalid banner response is passed', function () { + const invBanner = { + body: [{ + width: 300, + cpm: 0.4, + ad: 'Test', + requestId: '23fhj33i987f', + ttl: 120, + creativeId: '2', + netRevenue: true, + currency: 'USD', + dealId: '1' + }] + }; + + let serverResponses = spec.interpretResponse(invBanner); + expect(serverResponses).to.be.an('array').that.is.empty; + }); + it('Should return an empty array if invalid video response is passed', function () { + const invVideo = { + body: [{ + mediaType: 'video', + cpm: 0.5, + requestId: '23fhj33i987f', + ttl: 120, + creativeId: '2', + netRevenue: true, + currency: 'USD', + dealId: '1' + }] + }; + let serverResponses = spec.interpretResponse(invVideo); + expect(serverResponses).to.be.an('array').that.is.empty; + }); + it('Should return an empty array if invalid native response is passed', function () { + const invNative = { + body: [{ + mediaType: 'native', + clickUrl: 'test.com', + title: 'Test', + impressionTrackers: ['test.com'], + ttl: 120, + requestId: '23fhj33i987f', + creativeId: '2', + netRevenue: true, + currency: 'USD', + }] + }; + let serverResponses = spec.interpretResponse(invNative); + expect(serverResponses).to.be.an('array').that.is.empty; + }); + it('Should return an empty array if invalid response is passed', function () { + const invalid = { + body: [{ + ttl: 120, + creativeId: '2', + netRevenue: true, + currency: 'USD', + dealId: '1' + }] + }; + let serverResponses = spec.interpretResponse(invalid); + expect(serverResponses).to.be.an('array').that.is.empty; + }); + }); +}); From ffd3f5773bd868969b198950943ebaa5889d0537 Mon Sep 17 00:00:00 2001 From: Aiholkin Date: Wed, 28 Oct 2020 22:05:16 +0200 Subject: [PATCH 02/15] initial --- modules/lunamediahbBidAdapter.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/lunamediahbBidAdapter.md b/modules/lunamediahbBidAdapter.md index da4013122f1..20472a90486 100644 --- a/modules/lunamediahbBidAdapter.md +++ b/modules/lunamediahbBidAdapter.md @@ -23,7 +23,7 @@ Module that connects to lunamedia demand sources }, bids: [ { - bidder: 'luna', + bidder: 'lunamediahb', params: { placementId: 0, traffic: 'banner' @@ -42,7 +42,7 @@ Module that connects to lunamedia demand sources }, bids: [ { - bidder: 'luna', + bidder: 'lunamediahb', params: { placementId: 0, traffic: 'video' @@ -68,7 +68,7 @@ Module that connects to lunamedia demand sources }, bids: [ { - bidder: 'luna', + bidder: 'lunamediahb', params: { placementId: 0, traffic: 'native' From 46faf720f403a3d3810c2ecf60c66359056a2396 Mon Sep 17 00:00:00 2001 From: Aiholkin Date: Wed, 28 Oct 2020 22:08:10 +0200 Subject: [PATCH 03/15] initial --- test/spec/modules/lunamediahbBidAdapter_spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/spec/modules/lunamediahbBidAdapter_spec.js b/test/spec/modules/lunamediahbBidAdapter_spec.js index ba0e6626f1c..e9f88935ed5 100644 --- a/test/spec/modules/lunamediahbBidAdapter_spec.js +++ b/test/spec/modules/lunamediahbBidAdapter_spec.js @@ -2,10 +2,10 @@ import {expect} from 'chai'; import {spec} from '../../../modules/lunamediahbBidAdapter.js'; import { BANNER, VIDEO, NATIVE } from '../../../src/mediaTypes.js'; -describe('KrushmediabBidAdapter', function () { +describe('LunamediaHBBidAdapter', function () { const bid = { bidId: '23fhj33i987f', - bidder: 'luna', + bidder: 'lunamediahb', mediaTypes: { [BANNER]: { sizes: [[300, 250]] From f23844c0b1d48a543fd86be5bbc8ed79b6c9ba45 Mon Sep 17 00:00:00 2001 From: lunamedia <73552749+lunamedia@users.noreply.github.com> Date: Wed, 4 Nov 2020 11:42:40 +0200 Subject: [PATCH 04/15] Update lunamediahbBidAdapter.js Define traffic type by mediatype property --- modules/lunamediahbBidAdapter.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/modules/lunamediahbBidAdapter.js b/modules/lunamediahbBidAdapter.js index 2d5d34ec066..7b7fa941d63 100644 --- a/modules/lunamediahbBidAdapter.js +++ b/modules/lunamediahbBidAdapter.js @@ -27,7 +27,7 @@ export const spec = { supportedMediaTypes: [BANNER, VIDEO, NATIVE], isBidRequestValid: (bid) => { - return Boolean(bid.bidId && bid.params && !isNaN(parseInt(bid.params.placementId))); + return Boolean(bid.bidId && bid.params && bid.mediaTypes && !isNaN(parseInt(bid.params.placementId))); }, buildRequests: (validBidRequests = [], bidderRequest) => { @@ -67,17 +67,20 @@ export const spec = { const placement = { placementId: bid.params.placementId, bidId: bid.bidId, - traffic: bid.params.traffic || BANNER, schain: bid.schain || {}, }; + const mediaType = bid.mediaTypes - if (bid.mediaTypes && bid.mediaTypes[BANNER] && bid.mediaTypes[BANNER].sizes) { + if (mediaType && bid.mediaTypes[BANNER] && bid.mediaTypes[BANNER].sizes) { placement.sizes = bid.mediaTypes[BANNER].sizes; - } else if (bid.mediaTypes && bid.mediaTypes[VIDEO] && bid.mediaTypes[VIDEO].playerSize) { + placement.traffic = BANNER; + } else if (mediaType && bid.mediaTypes[VIDEO] && bid.mediaTypes[VIDEO].playerSize) { placement.wPlayer = bid.mediaTypes[VIDEO].playerSize[0]; placement.hPlayer = bid.mediaTypes[VIDEO].playerSize[1]; - } else if (bid.mediaTypes && bid.mediaTypes[NATIVE]) { + placement.traffic = VIDEO; + } else if (mediaType && bid.mediaTypes[NATIVE]) { placement.native = bid.mediaTypes[NATIVE]; + placement.traffic = NATIVE; } placements.push(placement); } From 33fa84a200b5592bdfa893506cd975a53bc716b5 Mon Sep 17 00:00:00 2001 From: lunamedia <73552749+lunamedia@users.noreply.github.com> Date: Wed, 4 Nov 2020 11:44:24 +0200 Subject: [PATCH 05/15] Update lunamediahbBidAdapter.md Remove unnecessary parameter --- modules/lunamediahbBidAdapter.md | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/modules/lunamediahbBidAdapter.md b/modules/lunamediahbBidAdapter.md index 20472a90486..3c94592b86e 100644 --- a/modules/lunamediahbBidAdapter.md +++ b/modules/lunamediahbBidAdapter.md @@ -25,8 +25,7 @@ Module that connects to lunamedia demand sources { bidder: 'lunamediahb', params: { - placementId: 0, - traffic: 'banner' + placementId: 0 } } ] @@ -44,8 +43,7 @@ Module that connects to lunamedia demand sources { bidder: 'lunamediahb', params: { - placementId: 0, - traffic: 'video' + placementId: 0 } } ] @@ -70,8 +68,7 @@ Module that connects to lunamedia demand sources { bidder: 'lunamediahb', params: { - placementId: 0, - traffic: 'native' + placementId: 0 } } ] From 740cfd625937b8fdfe2ceaf49b5ed2f30e4024f4 Mon Sep 17 00:00:00 2001 From: lunamedia <73552749+lunamedia@users.noreply.github.com> Date: Wed, 4 Nov 2020 11:46:58 +0200 Subject: [PATCH 06/15] Update lunamediahbBidAdapter_spec.js Test for usage of mediatype for traffic definition --- test/spec/modules/lunamediahbBidAdapter_spec.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/spec/modules/lunamediahbBidAdapter_spec.js b/test/spec/modules/lunamediahbBidAdapter_spec.js index e9f88935ed5..ec1b09a0ea6 100644 --- a/test/spec/modules/lunamediahbBidAdapter_spec.js +++ b/test/spec/modules/lunamediahbBidAdapter_spec.js @@ -12,8 +12,7 @@ describe('LunamediaHBBidAdapter', function () { } }, params: { - placementId: 783, - traffic: BANNER + placementId: 783 } }; @@ -71,7 +70,6 @@ describe('LunamediaHBBidAdapter', function () { it('Returns valid data for mediatype video', function () { const playerSize = [300, 300]; bid.mediaTypes = {}; - bid.params.traffic = VIDEO; bid.mediaTypes[VIDEO] = { playerSize }; @@ -101,7 +99,6 @@ describe('LunamediaHBBidAdapter', function () { }; bid.mediaTypes = {}; - bid.params.traffic = NATIVE; bid.mediaTypes[NATIVE] = native; serverRequest = spec.buildRequests([bid], bidderRequest); let data = serverRequest.data; From a95033737a073fcc9d8203c1c1844c2a63bdc1f9 Mon Sep 17 00:00:00 2001 From: lunamedia <73552749+lunamedia@users.noreply.github.com> Date: Wed, 4 Nov 2020 22:23:30 +0200 Subject: [PATCH 07/15] Update lunamediahbBidAdapter.md --- modules/lunamediahbBidAdapter.md | 50 +++++++++++--------------------- 1 file changed, 17 insertions(+), 33 deletions(-) diff --git a/modules/lunamediahbBidAdapter.md b/modules/lunamediahbBidAdapter.md index 3c94592b86e..eef72e9b26f 100644 --- a/modules/lunamediahbBidAdapter.md +++ b/modules/lunamediahbBidAdapter.md @@ -13,44 +13,16 @@ Module that connects to lunamedia demand sources # Test Parameters ``` var adUnits = [ - // Will return static test banner { - code: 'adunit1', - mediaTypes: { + code:'1', + mediaTypes:{ banner: { sizes: [[300, 250]], - } - }, - bids: [ - { - bidder: 'lunamediahb', - params: { - placementId: 0 - } - } - ] - }, - // Will return test vast xml. All video params are stored under placement in publishers UI - { - code: 'addunit2', - mediaTypes: { + }, video: { playerSize: [640, 480], context: 'instream' - } - }, - bids: [ - { - bidder: 'lunamediahb', - params: { - placementId: 0 - } - } - ] - }, - { - code: 'addunit3', - mediaTypes: { + }, native: { title: { required: true @@ -64,7 +36,19 @@ Module that connects to lunamedia demand sources } } }, - bids: [ + bids:[ + { + bidder: 'lunamediahb', + params: { + placementId: 0 + } + }, + { + bidder: 'lunamediahb', + params: { + placementId: 0 + } + }, { bidder: 'lunamediahb', params: { From 28dbaa17496c84bffbb8dafce5151d17f2278b7a Mon Sep 17 00:00:00 2001 From: lunamedia <73552749+lunamedia@users.noreply.github.com> Date: Thu, 5 Nov 2020 12:41:59 +0200 Subject: [PATCH 08/15] Update lunamediahbBidAdapter.js fix native parse --- modules/lunamediahbBidAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/lunamediahbBidAdapter.js b/modules/lunamediahbBidAdapter.js index 7b7fa941d63..e890199fea9 100644 --- a/modules/lunamediahbBidAdapter.js +++ b/modules/lunamediahbBidAdapter.js @@ -16,7 +16,7 @@ function isBidResponseValid(bid) { case VIDEO: return Boolean(bid.vastUrl); case NATIVE: - return Boolean(bid.native && bid.native.impressionTrackers); + return Boolean(bid.impressionTrackers); default: return false; } From 39de8276bb4e4408ac2bd25d62c1e1e7342265f4 Mon Sep 17 00:00:00 2001 From: lunamedia <73552749+lunamedia@users.noreply.github.com> Date: Thu, 5 Nov 2020 12:47:37 +0200 Subject: [PATCH 09/15] Update lunamediahbBidAdapter_spec.js --- .../modules/lunamediahbBidAdapter_spec.js | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/test/spec/modules/lunamediahbBidAdapter_spec.js b/test/spec/modules/lunamediahbBidAdapter_spec.js index ec1b09a0ea6..e000722f0b7 100644 --- a/test/spec/modules/lunamediahbBidAdapter_spec.js +++ b/test/spec/modules/lunamediahbBidAdapter_spec.js @@ -201,12 +201,10 @@ describe('LunamediaHBBidAdapter', function () { const native = { body: [{ mediaType: 'native', - native: { - clickUrl: 'test.com', - title: 'Test', - image: 'test.com', - impressionTrackers: ['test.com'], - }, + clickUrl: 'test.com', + title: 'Test', + image: 'test.com', + impressionTrackers: ['test.com'], ttl: 120, cpm: 0.4, requestId: '23fhj33i987f', @@ -219,15 +217,14 @@ describe('LunamediaHBBidAdapter', function () { expect(nativeResponses).to.be.an('array').that.is.not.empty; let dataItem = nativeResponses[0]; - expect(dataItem).to.have.keys('requestId', 'cpm', 'ttl', 'creativeId', 'netRevenue', 'currency', 'mediaType', 'native'); - expect(dataItem.native).to.have.keys('clickUrl', 'impressionTrackers', 'title', 'image') + expect(dataItem).to.have.keys('requestId', 'cpm', 'ttl', 'creativeId', 'netRevenue', 'currency', 'mediaType', 'clickUrl', 'impressionTrackers', 'title', 'image'); expect(dataItem.requestId).to.equal('23fhj33i987f'); expect(dataItem.cpm).to.equal(0.4); - expect(dataItem.native.clickUrl).to.equal('test.com'); - expect(dataItem.native.title).to.equal('Test'); - expect(dataItem.native.image).to.equal('test.com'); - expect(dataItem.native.impressionTrackers).to.be.an('array').that.is.not.empty; - expect(dataItem.native.impressionTrackers[0]).to.equal('test.com'); + expect(dataItem.clickUrl).to.equal('test.com'); + expect(dataItem.title).to.equal('Test'); + expect(dataItem.image).to.equal('test.com'); + expect(dataItem.impressionTrackers).to.be.an('array').that.is.not.empty; + expect(dataItem.impressionTrackers[0]).to.equal('test.com'); expect(dataItem.ttl).to.equal(120); expect(dataItem.creativeId).to.equal('2'); expect(dataItem.netRevenue).to.be.true; From cb0d7ea9daad0d8c785b4334ca3eab85ff105ea0 Mon Sep 17 00:00:00 2001 From: Aiholkin Date: Thu, 5 Nov 2020 13:34:21 +0200 Subject: [PATCH 10/15] rever native changes --- modules/lunamediahbBidAdapter.js | 15 ++++------ .../modules/lunamediahbBidAdapter_spec.js | 28 +++++++++++-------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/modules/lunamediahbBidAdapter.js b/modules/lunamediahbBidAdapter.js index e890199fea9..2d5d34ec066 100644 --- a/modules/lunamediahbBidAdapter.js +++ b/modules/lunamediahbBidAdapter.js @@ -16,7 +16,7 @@ function isBidResponseValid(bid) { case VIDEO: return Boolean(bid.vastUrl); case NATIVE: - return Boolean(bid.impressionTrackers); + return Boolean(bid.native && bid.native.impressionTrackers); default: return false; } @@ -27,7 +27,7 @@ export const spec = { supportedMediaTypes: [BANNER, VIDEO, NATIVE], isBidRequestValid: (bid) => { - return Boolean(bid.bidId && bid.params && bid.mediaTypes && !isNaN(parseInt(bid.params.placementId))); + return Boolean(bid.bidId && bid.params && !isNaN(parseInt(bid.params.placementId))); }, buildRequests: (validBidRequests = [], bidderRequest) => { @@ -67,20 +67,17 @@ export const spec = { const placement = { placementId: bid.params.placementId, bidId: bid.bidId, + traffic: bid.params.traffic || BANNER, schain: bid.schain || {}, }; - const mediaType = bid.mediaTypes - if (mediaType && bid.mediaTypes[BANNER] && bid.mediaTypes[BANNER].sizes) { + if (bid.mediaTypes && bid.mediaTypes[BANNER] && bid.mediaTypes[BANNER].sizes) { placement.sizes = bid.mediaTypes[BANNER].sizes; - placement.traffic = BANNER; - } else if (mediaType && bid.mediaTypes[VIDEO] && bid.mediaTypes[VIDEO].playerSize) { + } else if (bid.mediaTypes && bid.mediaTypes[VIDEO] && bid.mediaTypes[VIDEO].playerSize) { placement.wPlayer = bid.mediaTypes[VIDEO].playerSize[0]; placement.hPlayer = bid.mediaTypes[VIDEO].playerSize[1]; - placement.traffic = VIDEO; - } else if (mediaType && bid.mediaTypes[NATIVE]) { + } else if (bid.mediaTypes && bid.mediaTypes[NATIVE]) { placement.native = bid.mediaTypes[NATIVE]; - placement.traffic = NATIVE; } placements.push(placement); } diff --git a/test/spec/modules/lunamediahbBidAdapter_spec.js b/test/spec/modules/lunamediahbBidAdapter_spec.js index e000722f0b7..e9f88935ed5 100644 --- a/test/spec/modules/lunamediahbBidAdapter_spec.js +++ b/test/spec/modules/lunamediahbBidAdapter_spec.js @@ -12,7 +12,8 @@ describe('LunamediaHBBidAdapter', function () { } }, params: { - placementId: 783 + placementId: 783, + traffic: BANNER } }; @@ -70,6 +71,7 @@ describe('LunamediaHBBidAdapter', function () { it('Returns valid data for mediatype video', function () { const playerSize = [300, 300]; bid.mediaTypes = {}; + bid.params.traffic = VIDEO; bid.mediaTypes[VIDEO] = { playerSize }; @@ -99,6 +101,7 @@ describe('LunamediaHBBidAdapter', function () { }; bid.mediaTypes = {}; + bid.params.traffic = NATIVE; bid.mediaTypes[NATIVE] = native; serverRequest = spec.buildRequests([bid], bidderRequest); let data = serverRequest.data; @@ -201,10 +204,12 @@ describe('LunamediaHBBidAdapter', function () { const native = { body: [{ mediaType: 'native', - clickUrl: 'test.com', - title: 'Test', - image: 'test.com', - impressionTrackers: ['test.com'], + native: { + clickUrl: 'test.com', + title: 'Test', + image: 'test.com', + impressionTrackers: ['test.com'], + }, ttl: 120, cpm: 0.4, requestId: '23fhj33i987f', @@ -217,14 +222,15 @@ describe('LunamediaHBBidAdapter', function () { expect(nativeResponses).to.be.an('array').that.is.not.empty; let dataItem = nativeResponses[0]; - expect(dataItem).to.have.keys('requestId', 'cpm', 'ttl', 'creativeId', 'netRevenue', 'currency', 'mediaType', 'clickUrl', 'impressionTrackers', 'title', 'image'); + expect(dataItem).to.have.keys('requestId', 'cpm', 'ttl', 'creativeId', 'netRevenue', 'currency', 'mediaType', 'native'); + expect(dataItem.native).to.have.keys('clickUrl', 'impressionTrackers', 'title', 'image') expect(dataItem.requestId).to.equal('23fhj33i987f'); expect(dataItem.cpm).to.equal(0.4); - expect(dataItem.clickUrl).to.equal('test.com'); - expect(dataItem.title).to.equal('Test'); - expect(dataItem.image).to.equal('test.com'); - expect(dataItem.impressionTrackers).to.be.an('array').that.is.not.empty; - expect(dataItem.impressionTrackers[0]).to.equal('test.com'); + expect(dataItem.native.clickUrl).to.equal('test.com'); + expect(dataItem.native.title).to.equal('Test'); + expect(dataItem.native.image).to.equal('test.com'); + expect(dataItem.native.impressionTrackers).to.be.an('array').that.is.not.empty; + expect(dataItem.native.impressionTrackers[0]).to.equal('test.com'); expect(dataItem.ttl).to.equal(120); expect(dataItem.creativeId).to.equal('2'); expect(dataItem.netRevenue).to.be.true; From d16d4188049983ecc31b886a4b92b675857290eb Mon Sep 17 00:00:00 2001 From: Aiholkin Date: Fri, 6 Nov 2020 10:41:24 +0200 Subject: [PATCH 11/15] remove traffic param --- modules/lunamediahbBidAdapter.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/modules/lunamediahbBidAdapter.js b/modules/lunamediahbBidAdapter.js index 2d5d34ec066..390c5c6ea93 100644 --- a/modules/lunamediahbBidAdapter.js +++ b/modules/lunamediahbBidAdapter.js @@ -67,17 +67,20 @@ export const spec = { const placement = { placementId: bid.params.placementId, bidId: bid.bidId, - traffic: bid.params.traffic || BANNER, schain: bid.schain || {}, }; - + const mediaType = bid.mediaTypes + if (bid.mediaTypes && bid.mediaTypes[BANNER] && bid.mediaTypes[BANNER].sizes) { placement.sizes = bid.mediaTypes[BANNER].sizes; + placement.traffic = BANNER; } else if (bid.mediaTypes && bid.mediaTypes[VIDEO] && bid.mediaTypes[VIDEO].playerSize) { placement.wPlayer = bid.mediaTypes[VIDEO].playerSize[0]; placement.hPlayer = bid.mediaTypes[VIDEO].playerSize[1]; + placement.traffic = VIDEO; } else if (bid.mediaTypes && bid.mediaTypes[NATIVE]) { placement.native = bid.mediaTypes[NATIVE]; + placement.traffic = NATIVE; } placements.push(placement); } From f766e34a354df69b088b2cf6f1f39205eddce254 Mon Sep 17 00:00:00 2001 From: Aiholkin Date: Fri, 6 Nov 2020 10:43:01 +0200 Subject: [PATCH 12/15] remove traffic param --- modules/lunamediahbBidAdapter.md | 45 ++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/modules/lunamediahbBidAdapter.md b/modules/lunamediahbBidAdapter.md index eef72e9b26f..184dd846a9d 100644 --- a/modules/lunamediahbBidAdapter.md +++ b/modules/lunamediahbBidAdapter.md @@ -18,18 +18,41 @@ Module that connects to lunamedia demand sources mediaTypes:{ banner: { sizes: [[300, 250]], - }, + } + }, + bids:[ + { + bidder: 'lunamediahb', + params: { + placementId: 0 + } + } + ] + }, + { + code:'1', + mediaTypes:{ video: { playerSize: [640, 480], context: 'instream' - }, + } + }, + bids:[ + { + bidder: 'lunamediahb', + params: { + placementId: 0 + } + } + ] + }, + { + code:'1', + mediaTypes:{ native: { title: { required: true }, - body: { - required: true - }, icon: { required: true, size: [64, 64] @@ -37,18 +60,6 @@ Module that connects to lunamedia demand sources } }, bids:[ - { - bidder: 'lunamediahb', - params: { - placementId: 0 - } - }, - { - bidder: 'lunamediahb', - params: { - placementId: 0 - } - }, { bidder: 'lunamediahb', params: { From 603a96709c708a2d5908e6b084f88285f64565ec Mon Sep 17 00:00:00 2001 From: Aiholkin Date: Fri, 6 Nov 2020 10:46:44 +0200 Subject: [PATCH 13/15] remove traffic param --- modules/lunamediahbBidAdapter.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/lunamediahbBidAdapter.js b/modules/lunamediahbBidAdapter.js index 390c5c6ea93..00f7a9a056c 100644 --- a/modules/lunamediahbBidAdapter.js +++ b/modules/lunamediahbBidAdapter.js @@ -71,15 +71,15 @@ export const spec = { }; const mediaType = bid.mediaTypes - if (bid.mediaTypes && bid.mediaTypes[BANNER] && bid.mediaTypes[BANNER].sizes) { - placement.sizes = bid.mediaTypes[BANNER].sizes; + if (mediaType && mediaType[BANNER] && mediaType[BANNER].sizes) { + placement.sizes = mediaType[BANNER].sizes; placement.traffic = BANNER; - } else if (bid.mediaTypes && bid.mediaTypes[VIDEO] && bid.mediaTypes[VIDEO].playerSize) { - placement.wPlayer = bid.mediaTypes[VIDEO].playerSize[0]; - placement.hPlayer = bid.mediaTypes[VIDEO].playerSize[1]; + } else if (mediaType && mediaType[VIDEO] && mediaType[VIDEO].playerSize) { + placement.wPlayer = mediaType[VIDEO].playerSize[0]; + placement.hPlayer = mediaType[VIDEO].playerSize[1]; placement.traffic = VIDEO; - } else if (bid.mediaTypes && bid.mediaTypes[NATIVE]) { - placement.native = bid.mediaTypes[NATIVE]; + } else if (mediaType && mediaType[NATIVE]) { + placement.native = mediaType[NATIVE]; placement.traffic = NATIVE; } placements.push(placement); From 7736791b4a0a5dcb568feaa8af945c98b1808d33 Mon Sep 17 00:00:00 2001 From: Aiholkin Date: Tue, 23 Mar 2021 13:23:23 +0200 Subject: [PATCH 14/15] add video context handling --- modules/lunamediahbBidAdapter.js | 13 ++++++++----- test/spec/modules/lunamediahbBidAdapter_spec.js | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/modules/lunamediahbBidAdapter.js b/modules/lunamediahbBidAdapter.js index 00f7a9a056c..448230e977a 100644 --- a/modules/lunamediahbBidAdapter.js +++ b/modules/lunamediahbBidAdapter.js @@ -14,7 +14,7 @@ function isBidResponseValid(bid) { case BANNER: return Boolean(bid.width && bid.height && bid.ad); case VIDEO: - return Boolean(bid.vastUrl); + return Boolean(bid.vastUrl) || Boolean(bid.vastXml); case NATIVE: return Boolean(bid.native && bid.native.impressionTrackers); default: @@ -70,14 +70,17 @@ export const spec = { schain: bid.schain || {}, }; const mediaType = bid.mediaTypes - + if (mediaType && mediaType[BANNER] && mediaType[BANNER].sizes) { placement.sizes = mediaType[BANNER].sizes; placement.traffic = BANNER; - } else if (mediaType && mediaType[VIDEO] && mediaType[VIDEO].playerSize) { - placement.wPlayer = mediaType[VIDEO].playerSize[0]; - placement.hPlayer = mediaType[VIDEO].playerSize[1]; + } else if (mediaType && mediaType[VIDEO]) { + if (mediaType[VIDEO].playerSize) { + placement.wPlayer = mediaType[VIDEO].playerSize[0]; + placement.hPlayer = mediaType[VIDEO].playerSize[1]; + } placement.traffic = VIDEO; + placement.videoContext = mediaType[VIDEO].context || 'instream' } else if (mediaType && mediaType[NATIVE]) { placement.native = mediaType[NATIVE]; placement.traffic = NATIVE; diff --git a/test/spec/modules/lunamediahbBidAdapter_spec.js b/test/spec/modules/lunamediahbBidAdapter_spec.js index e9f88935ed5..a787077b84f 100644 --- a/test/spec/modules/lunamediahbBidAdapter_spec.js +++ b/test/spec/modules/lunamediahbBidAdapter_spec.js @@ -80,7 +80,7 @@ describe('LunamediaHBBidAdapter', function () { expect(data).to.be.an('object'); let placement = data['placements'][0]; expect(placement).to.be.an('object'); - expect(placement).to.have.keys('placementId', 'bidId', 'traffic', 'wPlayer', 'hPlayer', 'schain'); + expect(placement).to.have.keys('placementId', 'bidId', 'traffic', 'wPlayer', 'hPlayer', 'schain', 'videoContext'); expect(placement.traffic).to.equal(VIDEO); expect(placement.wPlayer).to.equal(playerSize[0]); expect(placement.hPlayer).to.equal(playerSize[1]); From 107ed9af5526e6b7cea0398de9874407b9376af5 Mon Sep 17 00:00:00 2001 From: Aiholkin Date: Tue, 23 Mar 2021 13:39:03 +0200 Subject: [PATCH 15/15] add video context handling --- modules/lunamediahbBidAdapter.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/modules/lunamediahbBidAdapter.md b/modules/lunamediahbBidAdapter.md index 184dd846a9d..7deca33db18 100644 --- a/modules/lunamediahbBidAdapter.md +++ b/modules/lunamediahbBidAdapter.md @@ -46,6 +46,23 @@ Module that connects to lunamedia demand sources } ] }, + { + code:'1', + mediaTypes:{ + video: { + playerSize: [640, 480], + context: 'outstream' + } + }, + bids:[ + { + bidder: 'lunamediahb', + params: { + placementId: 0 + } + } + ] + }, { code:'1', mediaTypes:{