From 7f51878cf3febf017eaff377d14a69a52a4aac24 Mon Sep 17 00:00:00 2001 From: Fedor Belov Date: Thu, 10 Jan 2019 22:49:02 +0300 Subject: [PATCH] OTM adapter update (#3407) * otm * ALF-95 * otm: modify adapter to support migration to a new ssp * otm: fixed spec --- modules/otmBidAdapter.js | 60 ++++++++++++++----------- modules/otmBidAdapter.md | 4 +- test/spec/modules/otmBidAdapter_spec.js | 41 ++++++++++------- 3 files changed, 60 insertions(+), 45 deletions(-) diff --git a/modules/otmBidAdapter.js b/modules/otmBidAdapter.js index 000985e2889f..fe320104a26f 100644 --- a/modules/otmBidAdapter.js +++ b/modules/otmBidAdapter.js @@ -5,46 +5,56 @@ export const spec = { code: 'otm', supportedMediaTypes: [BANNER], isBidRequestValid: function (bid) { - return !!bid.params.pid && !!bid.params.tid; + return !!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, + tz: getTz(), + w: bid.sizes[0][0], + h: bid.sizes[0][1], + s: bid.params.tid, + bidid: bid.bidId, + transactionid: bid.transactionId, + auctionid: bid.auctionId, + bidfloor: bid.params.bidfloor }; - return {method: 'GET', url: 'https://ads2.otm-r.com/banner/hb', data: params} + return {method: 'GET', url: 'https://ssp.otm-r.com/adjson', data: params} }); return requests; }, interpretResponse: function (serverResponse, bidRequest) { - if (!serverResponse || !serverResponse.body || !serverResponse.body.ad) { + if (!serverResponse || !serverResponse.body) { 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 - }]; + const answer = []; + + serverResponse.body.forEach(bid => { + if (bid.ad) { + answer.push({ + requestId: bid.bidid, + cpm: bid.cpm, + width: bid.w, + height: bid.h, + creativeId: bid.creativeid, + currency: bid.currency || 'RUB', + netRevenue: true, + ad: bid.ad, + ttl: bid.ttl, + transactionId: bid.transactionid + }); + } + }); + + return answer; }, }; +function getTz() { + return new Date().getTimezoneOffset(); +} + registerBidder(spec); diff --git a/modules/otmBidAdapter.md b/modules/otmBidAdapter.md index e51d73443dd0..4962d3a80521 100644 --- a/modules/otmBidAdapter.md +++ b/modules/otmBidAdapter.md @@ -21,8 +21,7 @@ About us : http://otm-r.com { bidder: "otm", params: { - pid: 1, - tid: "demo", + tid: "99", bidfloor: 20 } } @@ -33,6 +32,5 @@ About us : http://otm-r.com 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 index fa047f38109a..0fe81a512cb3 100644 --- a/test/spec/modules/otmBidAdapter_spec.js +++ b/test/spec/modules/otmBidAdapter_spec.js @@ -1,13 +1,12 @@ -import { expect } from 'chai'; -import { spec } from 'modules/otmBidAdapter'; +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', + tid: '123', bidfloor: 20 } })).to.equal(true); @@ -18,8 +17,7 @@ describe('otmBidAdapterTests', function () { bidId: 'bid1234', bidder: 'otm', params: { - pid: 1, - tid: 'demo', + tid: '123', bidfloor: 20 }, sizes: [[240, 400]] @@ -28,7 +26,7 @@ describe('otmBidAdapterTests', function () { let request = spec.buildRequests(bidRequestData); let req_data = request[0].data; - expect(req_data.bidId).to.equal('bid1234'); + expect(req_data.bidid).to.equal('bid1234'); }); it('validate_response_params', function () { @@ -39,22 +37,31 @@ describe('otmBidAdapterTests', function () { }; let serverResponse = { - body: { - price: 1.12, - ad: 'Ad html', - size: '250x600' - } + body: [ + { + 'auctionid': '3c6f8e22-541b-485c-9214-e974d9fb1b6f', + 'cpm': 847.097, + 'ad': 'test html', + 'w': 240, + 'h': 400, + 'currency': 'RUB', + 'ttl': 300, + 'creativeid': '1_7869053', + 'bidid': '101f211def7c99', + 'transactionid': 'transaction_id_1' + } + ] }; 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.cpm).to.equal(847.097); expect(bid.currency).to.equal('RUB'); - expect(bid.width).to.equal('250'); - expect(bid.height).to.equal('600'); + expect(bid.width).to.equal(240); + expect(bid.height).to.equal(400); expect(bid.netRevenue).to.equal(true); - expect(bid.requestId).to.equal('bid1234'); - expect(bid.ad).to.equal('Ad html'); + expect(bid.requestId).to.equal('101f211def7c99'); + expect(bid.ad).to.equal('test html'); }); });