Skip to content

Commit

Permalink
added instream video ad support (#5766)
Browse files Browse the repository at this point in the history
* added adapters for gjirafa and malltv

* interpretResponse fix for empty result

* updated testing propertyId and placementId

* added instream video ad support

* Single request for multple bids
  • Loading branch information
drilon-kastrati authored Sep 24, 2020
1 parent 6ea04f9 commit 7f2d81a
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 69 deletions.
64 changes: 42 additions & 22 deletions modules/gjirafaBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';

const BIDDER_CODE = 'gjirafa';
const ENDPOINT_URL = 'https://central.gjirafa.com/bid';
Expand All @@ -7,6 +8,7 @@ const SIZE_SEPARATOR = ';';

export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER, VIDEO],
/**
* Determines whether or not the given bid request is valid.
*
Expand All @@ -23,45 +25,61 @@ export const spec = {
* @return ServerRequest Info describing the request to the server.
*/
buildRequests: function (validBidRequests, bidderRequest) {
let response = validBidRequests.map(bidRequest => {
let sizes = generateSizeParam(bidRequest.sizes);
let propertyId = bidRequest.params.propertyId;
let placementId = bidRequest.params.placementId;
let propertyId = '';
let pageViewGuid = '';
let storageId = '';
let bidderRequestId = '';
let url = '';
let contents = [];

let placements = validBidRequests.map(bidRequest => {
if (!propertyId) { propertyId = bidRequest.params.propertyId; }
if (!pageViewGuid && bidRequest.params) { pageViewGuid = bidRequest.params.pageViewGuid || ''; }
if (!storageId && bidRequest.params) { storageId = bidRequest.params.storageId || ''; }
if (!bidderRequestId) { bidderRequestId = bidRequest.bidderRequestId; }
if (!url && bidderRequest) { url = bidderRequest.refererInfo.referer; }
if (!contents.length && bidRequest.params.contents && bidRequest.params.contents.length) { contents = bidRequest.params.contents }

let adUnitId = bidRequest.adUnitCode;
let pageViewGuid = bidRequest.params.pageViewGuid || '';
let contents = bidRequest.params.contents || [];
const body = {
let placementId = bidRequest.params.placementId;
let sizes = generateSizeParam(bidRequest.sizes);

return {
sizes: sizes,
adUnitId: adUnitId,
placementId: placementId,
propertyId: propertyId,
pageViewGuid: pageViewGuid,
url: bidderRequest ? bidderRequest.refererInfo.referer : '',
requestid: bidRequest.bidderRequestId,
bidid: bidRequest.bidId,
contents: contents
};
return {
method: 'POST',
url: ENDPOINT_URL,
data: body
};
});
return response

let body = {
propertyId: propertyId,
pageViewGuid: pageViewGuid,
storageId: storageId,
url: url,
requestid: bidderRequestId,
placements: placements,
contents: contents
}

return [{
method: 'POST',
url: ENDPOINT_URL,
data: body
}];
},
/**
* Unpack the response from the server into a list of bids.
*
* @param {ServerResponse} serverResponse A successful response from the server.
* @return {Bid[]} An array of bids which were nested inside the server.
*/
interpretResponse: function (serverResponse, bidRequest) {
window.adnResponse = serverResponse;
interpretResponse: function (serverResponse) {
const responses = serverResponse.body;
const bidResponses = [];
for (var i = 0; i < responses.length; i++) {
const bidResponse = {
requestId: bidRequest.data.bidid,
requestId: responses[i].BidId,
cpm: responses[i].CPM,
width: responses[i].Width,
height: responses[i].Height,
Expand All @@ -70,7 +88,9 @@ export const spec = {
netRevenue: responses[i].NetRevenue,
ttl: responses[i].TTL,
referrer: responses[i].Referrer,
ad: responses[i].Ad
ad: responses[i].Ad,
vastUrl: responses[i].VastUrl,
mediaType: responses[i].MediaType
};
bidResponses.push(bidResponse);
}
Expand Down
14 changes: 4 additions & 10 deletions modules/gjirafaBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,16 @@ var adUnits = [
{
code: 'test-div',
mediaTypes: {
banner: {
sizes: [[300, 250]]
}
video: {
context: 'instream'
}
},
bids: [
{
bidder: 'gjirafa',
params: {
propertyId: '105227',
placementId: '846848',
contents: [ //optional
{
type: 'article',
id: '123'
}
]
placementId: '846836'
}
}
]
Expand Down
64 changes: 42 additions & 22 deletions modules/malltvBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';

const BIDDER_CODE = 'malltv';
const ENDPOINT_URL = 'https://central.mall.tv/bid';
Expand All @@ -7,6 +8,7 @@ const SIZE_SEPARATOR = ';';

export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER, VIDEO],
/**
* Determines whether or not the given bid request is valid.
*
Expand All @@ -23,45 +25,61 @@ export const spec = {
* @return ServerRequest Info describing the request to the server.
*/
buildRequests: function (validBidRequests, bidderRequest) {
let response = validBidRequests.map(bidRequest => {
let sizes = generateSizeParam(bidRequest.sizes);
let propertyId = bidRequest.params.propertyId;
let placementId = bidRequest.params.placementId;
let propertyId = '';
let pageViewGuid = '';
let storageId = '';
let bidderRequestId = '';
let url = '';
let contents = [];

let placements = validBidRequests.map(bidRequest => {
if (!propertyId) { propertyId = bidRequest.params.propertyId; }
if (!pageViewGuid && bidRequest.params) { pageViewGuid = bidRequest.params.pageViewGuid || ''; }
if (!storageId && bidRequest.params) { storageId = bidRequest.params.storageId || ''; }
if (!bidderRequestId) { bidderRequestId = bidRequest.bidderRequestId; }
if (!url && bidderRequest) { url = bidderRequest.refererInfo.referer; }
if (!contents.length && bidRequest.params.contents && bidRequest.params.contents.length) { contents = bidRequest.params.contents }

let adUnitId = bidRequest.adUnitCode;
let pageViewGuid = bidRequest.params.pageViewGuid || '';
let contents = bidRequest.params.contents || [];
const body = {
let placementId = bidRequest.params.placementId;
let sizes = generateSizeParam(bidRequest.sizes);

return {
sizes: sizes,
adUnitId: adUnitId,
placementId: placementId,
propertyId: propertyId,
pageViewGuid: pageViewGuid,
url: bidderRequest ? bidderRequest.refererInfo.referer : '',
requestid: bidRequest.bidderRequestId,
bidid: bidRequest.bidId,
contents: contents
};
return {
method: 'POST',
url: ENDPOINT_URL,
data: body
};
});
return response

let body = {
propertyId: propertyId,
pageViewGuid: pageViewGuid,
storageId: storageId,
url: url,
requestid: bidderRequestId,
placements: placements,
contents: contents
}

return [{
method: 'POST',
url: ENDPOINT_URL,
data: body
}];
},
/**
* Unpack the response from the server into a list of bids.
*
* @param {ServerResponse} serverResponse A successful response from the server.
* @return {Bid[]} An array of bids which were nested inside the server.
*/
interpretResponse: function (serverResponse, bidRequest) {
window.adnResponse = serverResponse;
interpretResponse: function (serverResponse) {
const responses = serverResponse.body;
const bidResponses = [];
for (var i = 0; i < responses.length; i++) {
const bidResponse = {
requestId: bidRequest.data.bidid,
requestId: responses[i].BidId,
cpm: responses[i].CPM,
width: responses[i].Width,
height: responses[i].Height,
Expand All @@ -70,7 +88,9 @@ export const spec = {
netRevenue: responses[i].NetRevenue,
ttl: responses[i].TTL,
referrer: responses[i].Referrer,
ad: responses[i].Ad
ad: responses[i].Ad,
vastUrl: responses[i].VastUrl,
mediaType: responses[i].MediaType
};
bidResponses.push(bidResponse);
}
Expand Down
14 changes: 4 additions & 10 deletions modules/malltvBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,16 @@ var adUnits = [
{
code: 'test-div',
mediaTypes: {
banner: {
sizes: [[300, 250], [300, 300]]
}
video: {
context: 'instream'
}
},
bids: [
{
bidder: 'malltv',
params: {
propertyId: '105134',
placementId: '846832',
contents: [ //optional
{
type: 'video',
id: '123'
}
]
placementId: '846841'
}
}
]
Expand Down
12 changes: 9 additions & 3 deletions test/spec/modules/gjirafaBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('gjirafaAdapterTest', () => {
})).to.equal(false);
});

it('bidRequest without propertyId orplacementId', () => {
it('bidRequest without propertyId or placementId', () => {
expect(spec.isBidRequestValid({
bidder: 'gjirafa',
params: {
Expand Down Expand Up @@ -80,7 +80,11 @@ describe('gjirafaAdapterTest', () => {

it('bidRequest sizes', () => {
const requests = spec.buildRequests(bidRequests);
expect(requests[0].data.sizes).to.equal('728x90');
requests.forEach(function (requestItem) {
expect(requestItem.data.placements).to.exist;
expect(requestItem.data.placements.length).to.equal(1);
expect(requestItem.data.placements[0].sizes).to.equal('728x90');
});
});
});

Expand Down Expand Up @@ -128,7 +132,9 @@ describe('gjirafaAdapterTest', () => {
'netRevenue',
'ttl',
'referrer',
'ad'
'ad',
'vastUrl',
'mediaType'
];

let resultKeys = Object.keys(result[0]);
Expand Down
10 changes: 8 additions & 2 deletions test/spec/modules/malltvBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ describe('malltvAdapterTest', () => {

it('bidRequest sizes', () => {
const requests = spec.buildRequests(bidRequests);
expect(requests[0].data.sizes).to.equal('300x250');
requests.forEach(function (requestItem) {
expect(requestItem.data.placements).to.exist;
expect(requestItem.data.placements.length).to.equal(1);
expect(requestItem.data.placements[0].sizes).to.equal('300x250');
});
});
});

Expand Down Expand Up @@ -128,7 +132,9 @@ describe('malltvAdapterTest', () => {
'netRevenue',
'ttl',
'referrer',
'ad'
'ad',
'vastUrl',
'mediaType'
];

let resultKeys = Object.keys(result[0]);
Expand Down

0 comments on commit 7f2d81a

Please sign in to comment.