Skip to content

Commit

Permalink
Nextmillinnium adapter improvement (#6957)
Browse files Browse the repository at this point in the history
* change structure of request and response

* fixes

* remove logInfo

* update doc
  • Loading branch information
Mikhail Ivanchenko authored Jun 7, 2021
1 parent 4ff92fa commit 8cac6d7
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 64 deletions.
72 changes: 31 additions & 41 deletions modules/nextMillenniumBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER } from '../src/mediaTypes.js';

const BIDDER_CODE = 'nextMillennium';
const HOST = 'https://brainlyads.com';
const CURRENCY = 'USD';
const ENDPOINT = 'https://pbs.nextmillmedia.com/openrtb2/auction';
const TIME_TO_LIVE = 360;

export const spec = {
Expand All @@ -13,7 +12,7 @@ export const spec = {

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

Expand All @@ -23,13 +22,19 @@ export const spec = {
utils._each(validBidRequests, function(bid) {
requests.push({
method: 'POST',
url: HOST + '/hb/s2s',
url: ENDPOINT,
options: {
contentType: 'application/json',
withCredentials: true
},
data: JSON.stringify({
placement_id: utils.getBidIdParameter('placement_id', bid.params)
'ext': {
'prebid': {
'storedrequest': {
'id': utils.getBidIdParameter('placement_id', bid.params)
}
}
}
}),
bidId: bid.bidId
});
Expand All @@ -39,47 +44,32 @@ export const spec = {
},

interpretResponse: function(serverResponse, bidRequest) {
try {
const bidResponse = serverResponse.body;
const bidResponses = [];
const response = 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
try {
utils._each(response.seatbid, (resp) => {
utils._each(resp.bid, (bid) => {
bidResponses.push({
requestId: bidRequest.bidId,
cpm: bid.price,
width: bid.w,
height: bid.h,
creativeId: bid.adid,
currency: response.cur,
netRevenue: false,
ttl: TIME_TO_LIVE,
meta: {
advertiserDomains: bid.adomain || []
},
ad: bid.adm
});
});
}

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;
return bidResponses;
}
};
registerBidder(spec);
4 changes: 2 additions & 2 deletions modules/nextMillenniumBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
```
Module Name: NextMillennium Bid Adapter
Module Type: Bidder Adapter
Maintainer: mikhail.ivanchenko@iageengineering.net
Maintainer: mihail.ivanchenko@nextmillennium.io
```

# Description
Expand All @@ -21,7 +21,7 @@ Currently module supports only banner mediaType.
bids: [{
bidder: 'nextMillennium',
params: {
placement_id: -1
placement_id: '-1'
}
}]
}];
Expand Down
44 changes: 23 additions & 21 deletions test/spec/modules/nextMillenniumBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { expect } from 'chai';
import * as utils from '../../../src/utils.js';
import { spec } from 'modules/nextMillenniumBidAdapter.js';

describe('nextMillenniumBidAdapterTests', function() {
Expand All @@ -8,20 +9,19 @@ describe('nextMillenniumBidAdapterTests', function() {
bidId: 'transaction_1234',
bidder: 'nextMillennium',
params: {
placement_id: 12345
placement_id: '12345'
},
sizes: [[300, 250]]
}
]
};
let request = [];

it('validate_pub_params', function() {
expect(
spec.isBidRequestValid({
bidder: 'nextMillennium',
params: {
placement_id: 12345
placement_id: '12345'
}
})
).to.equal(true);
Expand All @@ -32,42 +32,44 @@ describe('nextMillenniumBidAdapterTests', function() {
{
bidId: 'bid1234',
bidder: 'nextMillennium',
params: { placement_id: -1 },
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!'
id: 'f7b3d2da-e762-410c-b069-424f92c4c4b2',
seatbid: [
{
bid: [
{
id: '7457329903666272789',
price: 0.5,
adm: 'Hello! It\'s a test ad!',
adid: '96846035',
adomain: ['test.addomain.com'],
w: 300,
h: 250
}
]
}
],
cur: 'USD'
}
};

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.creativeId).to.equal('96846035');
expect(bid.ad).to.equal('Hello! It\'s a test ad!');
expect(bid.cpm).to.equal(1.7);
expect(bid.cpm).to.equal(0.5);
expect(bid.width).to.equal(300);
expect(bid.height).to.equal(250);
expect(bid.currency).to.equal('USD');
Expand Down

0 comments on commit 8cac6d7

Please sign in to comment.