Skip to content

Commit

Permalink
Buzzoola bid adapter (#4127)
Browse files Browse the repository at this point in the history
* initial commit for buzzoola adapter

* leave only banners for now

* fix bid validation

* change endpoint url

* add video type

* restore renderer

* fix renderer

* add fixed player sizes

* switch bids

* convert dimentions to strings

* write tests

* 100% tests

* remove new DOM element creation in tests

* handle empty response from server

* change description
  • Loading branch information
VanCyric authored and Fawke committed Sep 10, 2019
1 parent 25b6471 commit c520176
Show file tree
Hide file tree
Showing 4 changed files with 6,388 additions and 935 deletions.
108 changes: 108 additions & 0 deletions modules/buzzoolaBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import * as utils from '../src/utils';
import {registerBidder} from '../src/adapters/bidderFactory';
import {BANNER, VIDEO} from '../src/mediaTypes';
import {Renderer} from '../src/Renderer';
import {OUTSTREAM} from '../src/video';

const BIDDER_CODE = 'buzzoola';
const ENDPOINT = 'https://exchange.buzzoola.com/ssp/prebidjs';
const RENDERER_SRC = 'https://tube.buzzoola.com/new/build/buzzlibrary.js';

export const spec = {
code: BIDDER_CODE,
aliases: ['buzzoolaAdapter'],
supportedMediaTypes: [BANNER, VIDEO],

/**
* Determines whether or not the given bid request is valid.
*
* @param {BidRequest} bid The bid params to validate.
* @return {boolean} True if this is a valid bid, and false otherwise.
*/
isBidRequestValid: function (bid) {
let types = bid.mediaTypes;
return !!(bid && bid.mediaTypes && (types.banner || types.video) && bid.params && bid.params.placementId);
},

/**
* Make a server request from the list of BidRequests.
*
* @param {BidRequest[]} validBidRequests an array of bids
* @param bidderRequest
* @return ServerRequest Info describing the request to the server.
*/
buildRequests: function (validBidRequests, bidderRequest) {
return {
url: ENDPOINT,
method: 'POST',
data: bidderRequest,
}
},

/**
* Unpack the response from the server into a list of bids.
*
* @param {ServerResponse} serverResponse A successful response from the server.
* @param bidderRequest
* @return {Bid[]} An array of bids which were nested inside the server.
*/
interpretResponse: function ({body}, {data}) {
let requestBids = {};
let response;

try {
response = JSON.parse(body);
} catch (ex) {
response = body;
}

if (!Array.isArray(response)) response = [];

data.bids.forEach(bid => requestBids[bid.bidId] = bid);

return response.map(bid => {
let requestBid = requestBids[bid.requestId];
let context = utils.deepAccess(requestBid, 'mediaTypes.video.context');
let validBid = utils.deepClone(bid);

if (validBid.mediaType === VIDEO && context === OUTSTREAM) {
let renderer = Renderer.install({
id: validBid.requestId,
url: RENDERER_SRC,
loaded: false
});

renderer.setRender(setOutstreamRenderer);
validBid.renderer = renderer
}

return validBid;
});
}
};

/**
* Initialize Buzzoola Outstream player
*
* @param bid
*/
function setOutstreamRenderer(bid) {
let adData = JSON.parse(bid.ad);
let unitSettings = utils.deepAccess(adData, 'placement.unit_settings');
let extendedSettings = {
width: '' + bid.width,
height: '' + bid.height,
container_height: '' + bid.height
};

adData.placement = Object.assign({}, adData.placement);
adData.placement.unit_settings = Object.assign({}, unitSettings, extendedSettings);

bid.renderer.push(() => {
window.Buzzoola.Core.install(document.querySelector(`#${bid.adUnitCode}`), {
data: adData
});
});
}

registerBidder(spec);
72 changes: 72 additions & 0 deletions modules/buzzoolaBidAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Overview

```
Module Name: Buzzoola Bid Adapter
Module Type: Bidder Adapter
Maintainer: devteam@buzzoola.com
```

# Description

Connects to Buzzoola exchange for bids.

Buzzoola bid adapter supports Banner and Video (instream and outstream).

# Test Parameters
```
var adUnits = [
// Banner adUnit
{
code: 'banner-div',
mediaTypes: {
banner: {
sizes: [[240, 400], [300, 600]],
}
},
bids: [{
bidder: 'buzzoola',
params: {
placementId: 417846
}
}]
},
// Video instream adUnit
{
code: 'video-instream',
mediaTypes: {
video: {
context: 'instream',
playerSize: [640, 380],
mimes: ['video/mp4'],
minduration: 1,
maxduration: 2,
}
},
bids: [{
bidder: 'buzzoola',
params: {
placementId: 417845
}
}]
},
// Video outstream adUnit
{
code: 'video-outstream',
mediaTypes: {
video: {
context: 'outstream',
playerSize: [640, 380],
mimes: ['video/mp4'],
minduration: 1,
maxduration: 2,
}
},
bids: [{
bidder: 'buzzoola',
params: {
placementId: 417845
}
}]
}
];
```
Loading

0 comments on commit c520176

Please sign in to comment.