Skip to content

Commit

Permalink
Rhythmone Adapter - Multiple ad size support, rewrite tests, update d…
Browse files Browse the repository at this point in the history
…ocs. (#3854)
  • Loading branch information
rhythmonebhaines authored and jaiminpanchal27 committed May 28, 2019
1 parent 445df80 commit c1f6ce4
Show file tree
Hide file tree
Showing 3 changed files with 629 additions and 230 deletions.
60 changes: 49 additions & 11 deletions modules/rhythmoneBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ function RhythmOneBidAdapter() {
let SUPPORTED_VIDEO_API = [1, 2, 5];
let slotsToBids = {};
let that = this;
let version = '1.0.2.1';
let version = '2.0.0.0';
let loadStart = Date.now();
var win = typeof window !== 'undefined' ? window : {};

this.isBidRequestValid = function (bid) {
return true;
return !!(bid.params && bid.params.placementId);
};

this.getUserSyncs = function (syncOptions, responses, gdprConsent) {
Expand Down Expand Up @@ -90,6 +90,7 @@ function RhythmOneBidAdapter() {
impObj.id = BRs[i].adUnitCode;
impObj.bidfloor = parseFloat(utils.deepAccess(BRs[i], 'params.floor')) || 0;
impObj.secure = win.location.protocol === 'https:' ? 1 : 0;

if (utils.deepAccess(BRs[i], 'mediaTypes.banner') || utils.deepAccess(BRs[i], 'mediaType') === 'banner') {
impObj.banner = frameBanner(BRs[i]);
}
Expand Down Expand Up @@ -139,21 +140,58 @@ function RhythmOneBidAdapter() {
}
}

function frameBanner(bid) {
var sizes = utils.parseSizesInput(bid.sizes).map(size => size.split('x'));
return {
w: parseInt(sizes[0][0]),
h: parseInt(sizes[0][1])
function getValidSizeSet(dimensionList) {
let w = parseInt(dimensionList[0]);
let h = parseInt(dimensionList[1]);
// clever check for NaN
if (! (w !== w || h !== h)) { // eslint-disable-line
return [w, h];
}
return false;
}

function frameBanner(adUnit) {
// adUnit.sizes is scheduled to be deprecated, continue its support but prefer adUnit.mediaTypes.banner
var sizeList = adUnit.sizes;
if (adUnit.mediaTypes && adUnit.mediaTypes.banner) {
sizeList = adUnit.mediaTypes.banner.sizes;
}
var sizeStringList = utils.parseSizesInput(sizeList);
if (!Array.isArray(sizeStringList)) {
return {};
}

var format = [];
sizeStringList.forEach(function(size) {
if (!size) {
return;
}
var dimensionList = getValidSizeSet(size.split('x'));
if (dimensionList) {
format.push({
'w': dimensionList[0],
'h': dimensionList[1],
});
}
});
if (format.length) {
return {
'format': format
};
}
return {};
}

function frameVideo(bid) {
var size = [];
if (utils.deepAccess(bid, 'mediaTypes.video.playerSize')) {
var dimensionSet = bid.mediaTypes.video.playerSize;
if (utils.isArray(bid.mediaTypes.video.playerSize[0])) {
size = bid.mediaTypes.video.playerSize[0];
} else if (utils.isNumber(bid.mediaTypes.video.playerSize[0])) {
size = bid.mediaTypes.video.playerSize;
dimensionSet = bid.mediaTypes.video.playerSize[0];
}
var validSize = getValidSizeSet(dimensionSet)
if (validSize) {
size = validSize;
}
}
return {
Expand All @@ -172,7 +210,7 @@ function RhythmOneBidAdapter() {
function frameExt(bid) {
return {
bidder: {
placementId: (bid.params && bid.params['placementId']) ? bid.params['placementId'] : '',
placementId: bid.params['placementId'],
zone: (bid.params && bid.params['zone']) ? bid.params['zone'] : '1r',
path: (bid.params && bid.params['path']) ? bid.params['path'] : 'mvo'
}
Expand Down
40 changes: 33 additions & 7 deletions modules/rhythmoneBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,41 @@ This module relays Prebid bids from Rhythm Exchange, RhythmOne's ad exchange.

```js
const adUnits = [{
code: 'uuddlrlrbass',
sizes: [
[300, 250]
],
code: 'adSlot-1',
mediaTypes: {
banner: {
sizes: [
[300, 250],
[300, 600]
]
}
},
bids: [
{
bidder: 'rhythmone',
params:
{
params:
{
placementId: '80184', // REQUIRED
zone: '1r', // OPTIONAL
path: 'mvo', // OPTIONAL
endpoint: "//tag.1rx.io/rmp/80184/0/mvo?z=1r" // OPTIONAL, only required for testing. this api guarantees no 204 responses
}
}
]
},
{
code: 'adSlot-2',
mediaTypes: {
video: {
context: "instream",
playerSize: [640, 480]
}
},
bids: [
{
bidder: 'rhythmone',
params:
{
placementId: '80184', // REQUIRED
zone: '1r', // OPTIONAL
path: 'mvo', // OPTIONAL
Expand All @@ -31,4 +57,4 @@ const adUnits = [{
}
]
}];
```
```
Loading

0 comments on commit c1f6ce4

Please sign in to comment.