From 155dd8a0252ab98ac5f8c7422edfdbf2d14eb99d Mon Sep 17 00:00:00 2001 From: Fedor Belov Date: Fri, 16 Nov 2018 17:11:57 +0300 Subject: [PATCH] otm (#3302) --- modules/otmBidAdapter.js | 50 +++++++++++++++++++++ modules/otmBidAdapter.md | 38 ++++++++++++++++ test/spec/modules/otmBidAdapter_spec.js | 60 +++++++++++++++++++++++++ 3 files changed, 148 insertions(+) create mode 100644 modules/otmBidAdapter.js create mode 100644 modules/otmBidAdapter.md create mode 100644 test/spec/modules/otmBidAdapter_spec.js diff --git a/modules/otmBidAdapter.js b/modules/otmBidAdapter.js new file mode 100644 index 00000000000..000985e2889 --- /dev/null +++ b/modules/otmBidAdapter.js @@ -0,0 +1,50 @@ +import {BANNER} from 'src/mediaTypes'; +import {registerBidder} from 'src/adapters/bidderFactory'; + +export const spec = { + code: 'otm', + supportedMediaTypes: [BANNER], + isBidRequestValid: function (bid) { + return !!bid.params.pid && !!bid.params.tid; + }, + buildRequests: function (bidRequests) { + const requests = bidRequests.map(function (bid) { + const params = { + pid: bid.params.pid, + tid: bid.params.tid, + bidfloor: bid.params.bidfloor, + url: encodeURIComponent(window.location.href), + size: bid.sizes[0][0] + 'x' + bid.sizes[0][1], + resp_type: 'json', + rnd: Math.random(), + bidId: bid.bidId, + }; + + return {method: 'GET', url: 'https://ads2.otm-r.com/banner/hb', data: params} + }); + + return requests; + }, + interpretResponse: function (serverResponse, bidRequest) { + if (!serverResponse || !serverResponse.body || !serverResponse.body.ad) { + return []; + } + + const bid = serverResponse.body; + const sizes = bid.size.split('x'); + + return [{ + requestId: bidRequest.data.bidId, + cpm: bid.price, + width: sizes[0], + height: sizes[1], + creativeId: bidRequest.data.bidId, + currency: bid.currency || 'RUB', + netRevenue: true, + ad: bid.ad, + ttl: 360 + }]; + }, +}; + +registerBidder(spec); diff --git a/modules/otmBidAdapter.md b/modules/otmBidAdapter.md new file mode 100644 index 00000000000..e51d73443dd --- /dev/null +++ b/modules/otmBidAdapter.md @@ -0,0 +1,38 @@ +# Overview + +Module Name: OTM Bidder Adapter +Module Type: Bidder Adapter +Maintainer: ? + +# Description + +You can use this adapter to get a bid from otm-r.com. + +About us : http://otm-r.com + + +# Test Parameters +```javascript + var adUnits = [ + { + code: 'div-otm-example', + sizes: [[320, 480]], + bids: [ + { + bidder: "otm", + params: { + pid: 1, + tid: "demo", + bidfloor: 20 + } + } + ] + } + ]; +``` + +Where: + +* pid - Publisher id +* tid - A tag id (should have low cardinality) +* bidfloor - Floor price diff --git a/test/spec/modules/otmBidAdapter_spec.js b/test/spec/modules/otmBidAdapter_spec.js new file mode 100644 index 00000000000..fa047f38109 --- /dev/null +++ b/test/spec/modules/otmBidAdapter_spec.js @@ -0,0 +1,60 @@ +import { expect } from 'chai'; +import { spec } from 'modules/otmBidAdapter'; + +describe('otmBidAdapterTests', function () { + it('validate_pub_params', function () { + expect(spec.isBidRequestValid({ + bidder: 'otm', + params: { + pid: 1, + tid: 'demo', + bidfloor: 20 + } + })).to.equal(true); + }); + + it('validate_generated_params', function () { + let bidRequestData = [{ + bidId: 'bid1234', + bidder: 'otm', + params: { + pid: 1, + tid: 'demo', + bidfloor: 20 + }, + sizes: [[240, 400]] + }]; + + let request = spec.buildRequests(bidRequestData); + let req_data = request[0].data; + + expect(req_data.bidId).to.equal('bid1234'); + }); + + it('validate_response_params', function () { + let bidRequestData = { + data: { + bidId: 'bid1234' + } + }; + + let serverResponse = { + body: { + price: 1.12, + ad: 'Ad html', + size: '250x600' + } + }; + + let bids = spec.interpretResponse(serverResponse, bidRequestData); + expect(bids).to.have.lengthOf(1); + let bid = bids[0]; + expect(bid.cpm).to.equal(1.12); + expect(bid.currency).to.equal('RUB'); + expect(bid.width).to.equal('250'); + expect(bid.height).to.equal('600'); + expect(bid.netRevenue).to.equal(true); + expect(bid.requestId).to.equal('bid1234'); + expect(bid.ad).to.equal('Ad html'); + }); +});