Skip to content

Commit

Permalink
otm (#3302)
Browse files Browse the repository at this point in the history
  • Loading branch information
fedotxxl authored and jsnellbaker committed Nov 16, 2018
1 parent e1fb3a8 commit 155dd8a
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 0 deletions.
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');
});
});

0 comments on commit 155dd8a

Please sign in to comment.