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

Add nextMilleniumBidAdapter #3249

Merged
merged 2 commits into from
Nov 12, 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
85 changes: 85 additions & 0 deletions modules/nextMilleniumBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import * as utils from 'src/utils';
import { registerBidder } from 'src/adapters/bidderFactory';
import { BANNER } from 'src/mediaTypes';

const BIDDER_CODE = 'nextMillenium';
const HOST = 'https://brainlyads.com';
const CURRENCY = 'USD';
const TIME_TO_LIVE = 360;

export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER],

isBidRequestValid: function(bid) {
return !!(
bid.params.placement_id && utils.isNumber(bid.params.placement_id)
);
},

buildRequests: function(validBidRequests) {
let requests = [];

utils._each(validBidRequests, function(bid) {
requests.push({
method: 'POST',
url: HOST + '/hb/s2s',
options: {
contentType: 'application/json',
withCredentials: true
},
data: JSON.stringify({
placement_id: utils.getBidIdParameter('placement_id', bid.params)
}),
bidId: bid.bidId
});
});

return requests;
},

interpretResponse: function(serverResponse, bidRequest) {
try {
const bidResponse = serverResponse.body;
const bidResponses = [];

if (Number(bidResponse.cpm) > 0) {
bidResponses.push({
requestId: bidRequest.bidId,
cpm: bidResponse.cpm,
width: bidResponse.width,
height: bidResponse.height,
creativeId: bidResponse.creativeId,
currency: CURRENCY,
netRevenue: false,
ttl: TIME_TO_LIVE,
ad: bidResponse.ad
});
}

return bidResponses;
} catch (err) {
utils.logError(err);
return [];
}
},

getUserSyncs: function(syncOptions) {
const syncs = []
if (syncOptions.iframeEnabled) {
syncs.push({
type: 'iframe',
url: HOST + '/hb/s2s/matching'
});
}

if (syncOptions.pixelEnabled) {
syncs.push({
type: 'image',
url: HOST + '/hb/s2s/matching'
});
}
return syncs;
}
};
registerBidder(spec);
28 changes: 28 additions & 0 deletions modules/nextMilleniumBidAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Overview
```
Module Name: NextMillenium Bid Adapter
Module Type: Bidder Adapter
Maintainer: mikhail.ivanchenko@iageengineering.net
```

# Description
Module that connects to NextMillenium's server for bids.
Currently module supports only banner mediaType.

# Test Parameters
```
var adUnits = [{
code: '/test/div',
mediaTypes: {
banner: {
sizes: [[300, 250]]
}
},
bids: [{
bidder: 'nextMillenium',
params: {
placement_id: -1
}
}]
}];
```
91 changes: 91 additions & 0 deletions test/spec/modules/nextMilleniumBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { expect } from 'chai';
import { spec } from 'modules/nextMilleniumBidAdapter';

describe('nextMilleniumBidAdapterTests', function() {
let bidRequestData = {
bids: [
{
bidId: 'transaction_1234',
bidder: 'nextMillenium',
params: {
placement_id: 12345
},
sizes: [[300, 250]]
}
]
};
let request = [];

it('validate_pub_params', function() {
expect(
spec.isBidRequestValid({
bidder: 'nextMillenium',
params: {
placement_id: 12345
}
})
).to.equal(true);
});

it('validate_generated_params', function() {
let bidRequestData = [
{
bidId: 'bid1234',
bidder: 'nextMillenium',
params: { placement_id: -1 },
sizes: [[300, 250]]
}
];
let request = spec.buildRequests(bidRequestData);
expect(request[0].bidId).to.equal('bid1234');
});

it('validate_getUserSyncs_function', function() {
expect(spec.getUserSyncs({ iframeEnabled: true })).to.have.lengthOf(1);
expect(spec.getUserSyncs({ iframeEnabled: false })).to.have.lengthOf(0);

let pixel = spec.getUserSyncs({ iframeEnabled: true });
expect(pixel[0].type).to.equal('iframe');
expect(pixel[0].url).to.equal('https://brainlyads.com/hb/s2s/matching');
});

it('validate_response_params', function() {
let serverResponse = {
body: {
cpm: 1.7,
width: 300,
height: 250,
creativeId: 'p35t0enob6twbt9mofjc8e',
ad: 'Hello! It\'s a test ad!'
}
};

let bids = spec.interpretResponse(serverResponse, bidRequestData.bids[0]);
expect(bids).to.have.lengthOf(1);

let bid = bids[0];

expect(bid.creativeId).to.equal('p35t0enob6twbt9mofjc8e');
expect(bid.ad).to.equal('Hello! It\'s a test ad!');
expect(bid.cpm).to.equal(1.7);
expect(bid.width).to.equal(300);
expect(bid.height).to.equal(250);
expect(bid.currency).to.equal('USD');
});

it('validate_response_params_with passback', function() {
let serverResponse = {
body: [
{
hash: '1e100887dd614b0909bf6c49ba7f69fdd1360437',
content: 'Ad html passback',
size: [300, 250],
is_passback: 1
}
]
};
let bids = spec.interpretResponse(serverResponse);

expect(bids).to.have.lengthOf(0);
});
});