@@ -3,6 +3,7 @@ const ajax = require('../ajax.js').ajax;
3
3
const bidfactory = require ( '../bidfactory.js' ) ;
4
4
const bidmanager = require ( '../bidmanager.js' ) ;
5
5
const constants = require ( '../constants.json' ) ;
6
+ const BaseAdapter = require ( './adapter.js' ) ;
6
7
7
8
$$PREBID_GLOBAL$$ . aolGlobals = {
8
9
pixelsDropped : false
@@ -14,7 +15,6 @@ const AolAdapter = function AolAdapter() {
14
15
const pubapiTemplate = template `${ 'protocol' } ://${ 'host' } /pubapi/3.0/${ 'network' } /${ 'placement' } /${ 'pageid' } /${ 'sizeid' } /ADTECH;v=2;cmd=bid;cors=yes;alias=${ 'alias' } ${ 'bidfloor' } ;misc=${ 'misc' } ` ;
15
16
const nexageBaseApiTemplate = template `${ 'protocol' } ://${ 'host' } /bidRequest?` ;
16
17
const nexageGetApiTemplate = template `dcn=${ 'dcn' } &pos=${ 'pos' } &cmd=bid${ 'ext' } ` ;
17
- const BIDDER_CODE = 'aol' ;
18
18
const MP_SERVER_MAP = {
19
19
us : 'adserver-us.adtech.advertising.com' ,
20
20
eu : 'adserver-eu.adtech.advertising.com' ,
@@ -25,6 +25,11 @@ const AolAdapter = function AolAdapter() {
25
25
iframe : 'IFRAME' ,
26
26
img : 'IMG'
27
27
} ;
28
+ const AOL_BIDDERS_CODES = {
29
+ aol : 'aol' ,
30
+ onemobile : 'onemobile' ,
31
+ onedisplay : 'onedisplay'
32
+ } ;
28
33
29
34
let domReady = ( ( ) => {
30
35
let readyEventFired = false ;
@@ -175,7 +180,7 @@ const AolAdapter = function AolAdapter() {
175
180
176
181
function _addErrorBidResponse ( bid , response = { } ) {
177
182
const bidResponse = bidfactory . createBid ( 2 , bid ) ;
178
- bidResponse . bidderCode = BIDDER_CODE ;
183
+ bidResponse . bidderCode = bid . bidder ;
179
184
bidResponse . reason = response . nbr ;
180
185
bidResponse . raw = response ;
181
186
bidmanager . addBidResponse ( bid . placementCode , bidResponse ) ;
@@ -199,7 +204,7 @@ const AolAdapter = function AolAdapter() {
199
204
cpm = bidData . price ;
200
205
201
206
if ( cpm === null || isNaN ( cpm ) ) {
202
- utils . logError ( 'Invalid price in bid response' , BIDDER_CODE , bid ) ;
207
+ utils . logError ( 'Invalid price in bid response' , AOL_BIDDERS_CODES . aol , bid ) ;
203
208
_addErrorBidResponse ( bid , response ) ;
204
209
return ;
205
210
}
@@ -219,7 +224,7 @@ const AolAdapter = function AolAdapter() {
219
224
}
220
225
221
226
const bidResponse = bidfactory . createBid ( 1 , bid ) ;
222
- bidResponse . bidderCode = BIDDER_CODE ;
227
+ bidResponse . bidderCode = bid . bidder ;
223
228
bidResponse . ad = ad ;
224
229
bidResponse . cpm = cpm ;
225
230
bidResponse . width = bidData . w ;
@@ -234,15 +239,31 @@ const AolAdapter = function AolAdapter() {
234
239
bidmanager . addBidResponse ( bid . placementCode , bidResponse ) ;
235
240
}
236
241
242
+ function _isMarketplaceBidder ( bidder ) {
243
+ return bidder === AOL_BIDDERS_CODES . aol || bidder === AOL_BIDDERS_CODES . onedisplay ;
244
+ }
245
+
246
+ function _isNexageBidder ( bidder ) {
247
+ return bidder === AOL_BIDDERS_CODES . aol || bidder === AOL_BIDDERS_CODES . onemobile ;
248
+ }
249
+
237
250
function _isNexageRequestPost ( bid ) {
238
- if ( bid . params . id && bid . params . imp && bid . params . imp [ 0 ] ) {
251
+ if ( _isNexageBidder ( bid . bidder ) && bid . params . id && bid . params . imp && bid . params . imp [ 0 ] ) {
239
252
let imp = bid . params . imp [ 0 ] ;
240
253
return imp . id && imp . tagid &&
241
254
( ( imp . banner && imp . banner . w && imp . banner . h ) ||
242
255
( imp . video && imp . video . mimes && imp . video . minduration && imp . video . maxduration ) ) ;
243
256
}
244
257
}
245
258
259
+ function _isNexageRequestGet ( bid ) {
260
+ return _isNexageBidder ( bid . bidder ) && bid . params . dcn && bid . params . pos ;
261
+ }
262
+
263
+ function _isMarketplaceRequest ( bid ) {
264
+ return _isMarketplaceBidder ( bid . bidder ) && bid . params . placement && bid . params . network ;
265
+ }
266
+
246
267
function _callBids ( params ) {
247
268
utils . _each ( params . bids , bid => {
248
269
let apiUrl ;
@@ -251,9 +272,10 @@ const AolAdapter = function AolAdapter() {
251
272
withCredentials : true
252
273
} ;
253
274
let isNexageRequestPost = _isNexageRequestPost ( bid ) ;
254
- if ( bid . params . placement && bid . params . network ) {
255
- apiUrl = _buildMarketplaceUrl ( bid ) ;
256
- } else if ( bid . params . dcn && bid . params . pos || isNexageRequestPost ) {
275
+ let isNexageRequestGet = _isNexageRequestGet ( bid ) ;
276
+ let isMarketplaceRequest = _isMarketplaceRequest ( bid ) ;
277
+
278
+ if ( isNexageRequestGet || isNexageRequestPost ) {
257
279
apiUrl = _buildNexageApiUrl ( bid ) ;
258
280
if ( isNexageRequestPost ) {
259
281
data = bid . params ;
@@ -263,7 +285,10 @@ const AolAdapter = function AolAdapter() {
263
285
options . method = 'POST' ;
264
286
options . contentType = 'application/json' ;
265
287
}
288
+ } else if ( isMarketplaceRequest ) {
289
+ apiUrl = _buildMarketplaceUrl ( bid ) ;
266
290
}
291
+
267
292
if ( apiUrl ) {
268
293
ajax ( apiUrl , response => {
269
294
// Needs to be here in case bidderSettings are defined after requestBids() is called
@@ -279,15 +304,15 @@ const AolAdapter = function AolAdapter() {
279
304
showCpmAdjustmentWarning = false ; // warning is shown at most once
280
305
281
306
if ( ! response && response . length <= 0 ) {
282
- utils . logError ( 'Empty bid response' , BIDDER_CODE , bid ) ;
307
+ utils . logError ( 'Empty bid response' , AOL_BIDDERS_CODES . aol , bid ) ;
283
308
_addErrorBidResponse ( bid , response ) ;
284
309
return ;
285
310
}
286
311
287
312
try {
288
313
response = JSON . parse ( response ) ;
289
314
} catch ( e ) {
290
- utils . logError ( 'Invalid JSON in bid response' , BIDDER_CODE , bid ) ;
315
+ utils . logError ( 'Invalid JSON in bid response' , AOL_BIDDERS_CODES . aol , bid ) ;
291
316
_addErrorBidResponse ( bid , response ) ;
292
317
return ;
293
318
}
@@ -299,9 +324,12 @@ const AolAdapter = function AolAdapter() {
299
324
} ) ;
300
325
}
301
326
302
- return {
303
- callBids : _callBids
304
- } ;
327
+ return Object . assign ( BaseAdapter . createNew ( AOL_BIDDERS_CODES . aol ) , {
328
+ callBids : _callBids ,
329
+ createNew : function ( ) {
330
+ return new AolAdapter ( ) ;
331
+ }
332
+ } ) ;
305
333
} ;
306
334
307
335
module . exports = AolAdapter ;
0 commit comments