forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add nextMilleniumBidAdapter (prebid#3249)
* Add nextMilleniumBidAdapter * fix bugs
- Loading branch information
Mikhail Ivanchenko
authored and
Pedro López Jiménez
committed
Mar 18, 2019
1 parent
1cfae1a
commit 60d2f0f
Showing
3 changed files
with
204 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
}] | ||
}]; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |