Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OTM adapter update #3407

Merged
merged 5 commits into from
Jan 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 35 additions & 25 deletions modules/otmBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
4 changes: 1 addition & 3 deletions modules/otmBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ About us : http://otm-r.com
{
bidder: "otm",
params: {
pid: 1,
tid: "demo",
tid: "99",
bidfloor: 20
}
}
Expand All @@ -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
41 changes: 24 additions & 17 deletions test/spec/modules/otmBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -18,8 +17,7 @@ describe('otmBidAdapterTests', function () {
bidId: 'bid1234',
bidder: 'otm',
params: {
pid: 1,
tid: 'demo',
tid: '123',
bidfloor: 20
},
sizes: [[240, 400]]
Expand All @@ -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 () {
Expand All @@ -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': '<html><body>test html</body></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('<html><body>test html</body></html>');
});
});