diff --git a/modules/marsmediaBidAdapter.js b/modules/marsmediaBidAdapter.js new file mode 100644 index 00000000000..09eb4ac6c75 --- /dev/null +++ b/modules/marsmediaBidAdapter.js @@ -0,0 +1,130 @@ +import * as utils from '../src/utils'; +import {registerBidder} from '../src/adapters/bidderFactory'; +const BIDDER_CODE = 'marsmedia'; + +function getDomain() { + if (!utils.inIframe()) { + return window.location.hostname + } + let origins = window.document.location.ancestorOrigins + if (origins && origins.length > 0) { + return origins[origins.length - 1] + } +} + +export const spec = { + code: BIDDER_CODE, + aliases: ['mars'], + isBidRequestValid: function(bid) { + return (bid.params.publisherID !== null); + }, + buildRequests: function(validBidRequests, bidderRequest) { + try { + let protocol = (window.location.protocol === 'https:'); + const parse = getSize(validBidRequests[0].sizes); + const publisherId = validBidRequests[0].params.publisherID; + const payload = { + id: validBidRequests[0].bidId, + cur: ['USD'], + + language: window.navigator.userLanguage || window.navigator.language, + site: { + id: publisherId, + domain: getDomain(), + page: document.URL, + ref: document.referrer, + publisher: { + id: publisherId, + domain: getDomain() + } + }, + imp: [{ + id: utils.getUniqueIdentifierStr(), + banner: { + w: parse.width, + h: parse.height, + secure: protocol + }, + bidfloor: parseFloat(validBidRequests[0].params.floor) > 0 ? validBidRequests[0].params.floor : 0 + }], + device: { + ua: navigator.userAgent + }, + user: { + id: publisherId + }, + publisher: { + id: publisherId, + domain: getDomain() + } + }; + + if (bidderRequest && bidderRequest.gdprConsent) { + payload.gdpr = { + applies: bidderRequest.gdprConsent.gdprApplies, + consent: bidderRequest.gdprConsent.consentString + }; + } + + return { + method: 'POST', + url: '//bid306.rtbsrv.com/bidder/?bid=3mhdom', + data: JSON.stringify(payload) + }; + } catch (e) { + utils.logError(e, {validBidRequests, bidderRequest}); + } + }, + interpretResponse: function(serverResponse, bidRequest) { + const bidResponses = []; + let res = serverResponse.body; + if (!res) { + return [] + } + + for (let x = 0; x < res.seatbid.length; x++) { + var bidAd = res.seatbid[x].bid[0]; + + bidResponses.push({ + requestId: res.id, + cpm: Number(bidAd.price), + width: bidAd.w, + height: bidAd.h, + ad: bidAd.adm, + ttl: 60, + creativeId: bidAd.cid, + netRevenue: true, + currency: 'USD' + }) + } + + return bidResponses; + }, + getUserSyncs: function(syncOptions, serverResponses) { + return []; + } +}; + +function getSize(requestSizes) { + const parsed = {}; + const size = utils.parseSizesInput(requestSizes)[0]; + + if (typeof size !== 'string') { + return parsed; + } + + const parsedSize = size.toUpperCase().split('X'); + const width = parseInt(parsedSize[0], 10); + if (width) { + parsed.width = width; + } + + const height = parseInt(parsedSize[1], 10); + if (height) { + parsed.height = height; + } + + return parsed; +} + +registerBidder(spec); diff --git a/modules/marsmediaBidAdapter.md b/modules/marsmediaBidAdapter.md new file mode 100644 index 00000000000..fee962f9173 --- /dev/null +++ b/modules/marsmediaBidAdapter.md @@ -0,0 +1,32 @@ +# Overview + +``` +Module Name: Mars Media Group (mars.media) Bidder Adapter +Module Type: Bidder Adapter +Maintainer: vladi@mars.media +``` + +# Description + +Prebid adapter for Mars Media Group RTB. Requires approval and account setup. + +# Test Parameters + +## Web +``` + var adUnits = [ + { + code: 'test-div', + sizes: [[300, 250]], + bids: [ + { + bidder: "marsmedia", + params: { + publisherID: 9999, + floor: 0.11 + } + } + ] + } + ]; +``` \ No newline at end of file diff --git a/test/spec/modules/marsmediaBidAdapter_spec.js b/test/spec/modules/marsmediaBidAdapter_spec.js new file mode 100644 index 00000000000..a58857e0f3f --- /dev/null +++ b/test/spec/modules/marsmediaBidAdapter_spec.js @@ -0,0 +1,122 @@ +import { expect } from 'chai' +import { spec, _getPlatform } from 'modules/marsmediaBidAdapter' +import { newBidder } from 'src/adapters/bidderFactory' + +describe('marsmediaBidAdapter', function () { + const adapter = newBidder(spec) + + let bidRequest = { + 'bidId': '123', + 'sizes': [[ 300, 250 ]], + 'params': { + 'publisherID': 9999, + 'floor': 0.1 + } + } + + describe('codes', function () { + it('should return a bidder code of marsmedia', function () { + expect(spec.code).to.equal('marsmedia') + }) + it('should alias mars', function () { + expect(spec.aliases.length > 0 && spec.aliases[0] === 'mars').to.be.true + }) + }) + + describe('isBidRequestValid', function () { + it('should return true if all params present', function () { + expect(spec.isBidRequestValid(bidRequest)).to.be.true + }) + + it('should return false if any parameter missing', function () { + expect(spec.isBidRequestValid(Object.assign(bidRequest, { params: { publisherID: null } }))).to.be.false + }) + }) + + describe('buildRequests', function () { + let req = spec.buildRequests([ bidRequest ], { refererInfo: { } }) + let rdata + + it('should return request object', function () { + expect(req).to.not.be.null + }) + + it('should build request data', function () { + expect(req.data).to.not.be.null + }) + + it('should include one request', function () { + rdata = JSON.parse(req.data) + expect(rdata.imp.length).to.equal(1) + }) + + it('should include all publisher params', function () { + let r = rdata.imp[0] + expect(r.publisherID !== null).to.be.true + }) + }) + + describe('interpretResponse', function () { + let response; + beforeEach(function () { + response = { + body: { + 'id': '37386aade21a71', + 'seatbid': [{ + 'bid': [{ + 'id': '1', + 'impid': '1', + 'cid': '1', + 'price': 0.1, + 'nurl': '', + 'adm': '', + 'w': 320, + 'h': 250 + }] + }] + } + }; + }); + + it('should get the correct bid response', function () { + let expectedResponse = [{ + 'requestId': '37386aade21a71', + 'cpm': 0.1, + 'width': 320, + 'height': 250, + 'creativeId': '1', + 'currency': 'USD', + 'netRevenue': true, + 'ad': ``, + 'ttl': 60 + }]; + + let result = spec.interpretResponse(response); + expect(result[0]).to.deep.equal(expectedResponse[0]); + }); + + it('handles empty bid response', function () { + let response = { + body: '' + }; + let result = spec.interpretResponse(response); + expect(result.length).to.equal(0); + }); + }); + + describe('getUserSyncs', function () { + /* it('should return iframe sync', function () { + let sync = spec.getUserSyncs({ iframeEnabled: true }) + expect(sync.length).to.equal(1) + expect(sync[0].type === 'iframe') + expect(typeof sync[0].url === 'string') + }) + + it('should return pixel sync', function () { + let sync = spec.getUserSyncs({ pixelEnabled: true }) + expect(sync.length).to.equal(1) + expect(sync[0].type === 'image') + expect(typeof sync[0].url === 'string') + }) */ + }) +})