diff --git a/modules/rtbsolutionsBidAdapter.js b/modules/rtbsolutionsBidAdapter.js new file mode 100644 index 00000000000..ad75b9de25a --- /dev/null +++ b/modules/rtbsolutionsBidAdapter.js @@ -0,0 +1,100 @@ +import { registerBidder } from '../src/adapters/bidderFactory'; +import * as utils from '../src/utils'; +import { ajax } from '../src/ajax'; + +const BIDDER_CODE = 'rtbsolutions'; +const ENDPOINT_URL = 'https://dsp-eu-lb.rtbsolutions.pro/bid/hb'; + +export const spec = { + version: '1.0', + code: BIDDER_CODE, + aliases: ['rtbss'], // short code + nurls: {}, + isBidRequestValid: function(bid) { + return !!bid.params.blockId; + }, + buildRequests: function(validBidRequests, bidderRequest) { + let req = []; + + bidderRequest.bids.forEach(item => { + const width = item.sizes[0][0]; + const height = item.sizes[0][1]; + + let imp = { + referer: bidderRequest.refererInfo.referer, + ua: navigator.userAgent, + lang: this.getLanguage(), + domain: this.getDomain(), + width: width, + height: height, + type: 'banner', + }; + + if (item.params.s1 !== undefined) imp.s1 = item.params.s1; + if (item.params.s2 !== undefined) imp.s2 = item.params.s2; + if (item.params.s3 !== undefined) imp.s3 = item.params.s3; + if (item.params.s4 !== undefined) imp.s4 = item.params.s4; + + req.push({ + bid_id: item.bidId, + block_id: item.params.blockId, + ver: this.version, + imp + }); + }); + + return { + method: 'POST', + url: ENDPOINT_URL, + data: req, + options: { + contentType: 'application/json' + } + } + }, + interpretResponse: function(serverResponse, request) { + const bidResponses = []; + + serverResponse.body.forEach(item => { + this.nurls[item.bid_id] = item.nurl; + + const bidResponse = { + requestId: item.bid_id, + cpm: item.cpm, + width: item.width, + height: item.height, + creativeId: item.creative_id, + currency: item.currency, + netRevenue: true, + ttl: 360, + ad: item.ad, + }; + + bidResponses.push(bidResponse); + }); + + return bidResponses; + }, + onBidWon: function(bid) { + ajax(this.nurls[bid.requestId], null); + }, + + getLanguage() { + const language = navigator.language ? 'language' : 'userLanguage'; + const lang2 = navigator[language].split('-')[0]; + if (lang2.length === 2 || lang2.length === 3) { + return lang2; + } + return ''; + }, + getDomain() { + if (!utils.inIframe()) { + return window.location.hostname + } + let origins = window.document.location.ancestorOrigins; + if (origins && origins.length > 0) { + return origins[origins.length - 1] + } + } +}; +registerBidder(spec); diff --git a/modules/rtbsolutionsBidAdapter.md b/modules/rtbsolutionsBidAdapter.md new file mode 100644 index 00000000000..e671de306a0 --- /dev/null +++ b/modules/rtbsolutionsBidAdapter.md @@ -0,0 +1,128 @@ +# Overview + +Module Name: Rtbsolutions Bidder Adapter +Module Type: Bidder Adapter +Maintainer: info@rtbsolutions.pro + +# Description + +You can use this adapter to get a bid from rtbsolutions. + +About us: http://rtbsolutions.pro + + +# Test Parameters +```javascript + var adUnits = [ + { + code: '/19968336/header-bid-tag-1', + mediaTypes: { + banner: { + sizes: sizes + } + }, + bids: [{ + bidder: 'rtbsolutions', + params: { + blockId: 777, + s1: 'sub_1', + s2: 'sub_2', + s3: 'sub_3', + s4: 'sub_4' + } + }] + }]; +``` + +Where: + +* blockId - Block ID from platform (required) +* s1..s4 - Sub Id (optional) + +# Example page + +```html + + + + + Prebid + + + + + +

Prebid

+
Div-1
+
+ +
+ + +``` diff --git a/test/spec/modules/rtbsolutionsBidAdapter_spec.js b/test/spec/modules/rtbsolutionsBidAdapter_spec.js new file mode 100644 index 00000000000..a9ffcd2ce4b --- /dev/null +++ b/test/spec/modules/rtbsolutionsBidAdapter_spec.js @@ -0,0 +1,62 @@ +import { expect } from 'chai'; +import { spec } from 'modules/rtbsolutionsBidAdapter'; + +describe('rtbsolutionsBidAdapterTests', function () { + it('validate_pub_params_1', function () { + expect(spec.isBidRequestValid({ + bidder: 'rtbsolutions', + params: { + blockId: 777 + } + })).to.equal(true); + }); + it('validate_pub_params_2', function () { + expect(spec.isBidRequestValid({ + bidder: 'rtbsolutions', + params: { + s1: 'test' + } + })).to.equal(false); + }); + it('validate_generated_params', function () { + let bidderRequest = { + bids: [], + refererInfo: { + referer: '' + } + }; + bidderRequest.bids.push({ + bidId: 'bid1234', + bidder: 'rtbsolutions', + params: {blockId: 777}, + sizes: [[240, 400]] + }); + let request = spec.buildRequests(true, bidderRequest); + let req_data = request.data[0]; + expect(req_data.bid_id).to.equal('bid1234'); + }); + it('validate_response_params', function () { + let serverResponse = { + body: [{ + ad: 'Ad html', + bid_id: 'bid1234', + cpm: 1, + creative_id: 1, + height: 480, + nurl: 'http://test.test', + width: 640, + currency: 'USD', + }] + }; + let bids = spec.interpretResponse(serverResponse); + expect(bids).to.have.lengthOf(1); + let bid = bids[0]; + expect(bid.cpm).to.equal(1); + expect(bid.currency).to.equal('USD'); + expect(bid.width).to.equal(640); + expect(bid.height).to.equal(480); + expect(bid.netRevenue).to.equal(true); + expect(bid.requestId).to.equal('bid1234'); + expect(bid.ad).to.equal('Ad html'); + }); +});