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 bid adapter #3302

Merged
merged 1 commit into from
Nov 16, 2018
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
50 changes: 50 additions & 0 deletions modules/otmBidAdapter.js
Original file line number Diff line number Diff line change
@@ -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);
38 changes: 38 additions & 0 deletions modules/otmBidAdapter.md
Original file line number Diff line number Diff line change
@@ -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
60 changes: 60 additions & 0 deletions test/spec/modules/otmBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -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');
});
});