Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Vertoz adapter for Prebid 1.0 #2104

Merged
merged 2 commits into from
Feb 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions modules/vertozBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import * as utils from 'src/utils';
import { registerBidder } from 'src/adapters/bidderFactory';
const BIDDER_CODE = 'vertoz';
const BASE_URI = '//hb.vrtzads.com/vzhbidder/bid?';

export const spec = {
code: BIDDER_CODE,
/**
* 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) {
return !!(bid.params.placementId);
},
/**
* Make a server request from the list of BidRequests.
*
* @param {validBidRequests[]} - an array of bids
* @return ServerRequest Info describing the request to the server.
*/
buildRequests: function(bidRequestsArr) {
var bidRequests = bidRequestsArr || [];
return bidRequests.map(bid => {
let slotBidId = utils.getValue(bid, 'bidId');
let cb = Math.round(new Date().getTime() / 1000);
let vzEndPoint = BASE_URI;
let reqParams = bid.params || {};
let placementId = utils.getValue(reqParams, 'placementId');
let cpm = utils.getValue(reqParams, 'cpmFloor');

if (utils.isEmptyStr(placementId)) {
utils.logError('missing params:', BIDDER_CODE, 'Enter valid vzPlacementId');
return;
}

let reqSrc = utils.getTopWindowLocation().href;
var vzReq = {
_vzPlacementId: placementId,
_rqsrc: reqSrc,
_cb: cb,
_slotBidId: slotBidId,
_cpm: cpm,
_cbn: '$$PREBID_GLOBAL$$'
};

let queryParamValue = encodeURIComponent(JSON.stringify(vzReq));

return {
method: 'POST',
data: {q: queryParamValue},
url: vzEndPoint
};
})
},
/**
* 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) {
var bidRespObj = serverResponse.body;
const bidResponses = [];

if (bidRespObj.cpm) {
const bidResponse = {
requestId: bidRespObj.slotBidId,
cpm: Number(bidRespObj.cpm),
width: Number(bidRespObj.adWidth),
height: Number(bidRespObj.adHeight),
netRevenue: true,
mediaType: 'banner',
currency: 'USD',
dealId: null,
creativeId: null,
ttl: 300,
ad: bidRespObj.ad + utils.createTrackPixelHtml(decodeURIComponent(bidRespObj.nurl))
};
bidResponses.push(bidResponse);
}
return bidResponses;
}
}
registerBidder(spec);
31 changes: 31 additions & 0 deletions modules/vertozBidAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Overview

```
Module Name: Vertoz Bidder Adapter
Module Type: Bidder Adapter
Maintainer: prebid-team@vertoz.com
```

# Description

Connects to Vertoz exchange for bids.
Vertoz Bidder adapter supports Banner ads.
Use bidder code ```vertoz``` for all Vertoz traffic.

# Test Parameters
```
var adUnits = [
// Banner adUnit
{
code: 'banner-div',
sizes: [[300, 250], [300,600]], // a display size(s)
bids: [{
bidder: 'vertoz',
params: {
placementId: 'VZ-HB-B784382V6C6G3C'
}
}]
},
];
```

112 changes: 112 additions & 0 deletions test/spec/modules/vertozBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import { expect } from 'chai';
import { spec } from 'modules/vertozBidAdapter';
import { newBidder } from 'src/adapters/bidderFactory';

const BASE_URI = '//hb.vrtzads.com/vzhbidder/bid?';

describe('VertozAdapter', () => {
const adapter = newBidder(spec);

describe('inherited functions', () => {
it('exists and is a function', () => {
expect(adapter.callBids).to.exist.and.to.be.a('function');
});
});

describe('isBidRequestValid', () => {
let bid = {
'bidder': 'vertoz',
'params': {
'placementId': 'VZ-HB-B784382V6C6G3C'
},
'adUnitCode': 'adunit-code',
'sizes': [[300, 250], [300, 600]],
'bidId': '30b31c1838de1e',
'bidderRequestId': '22edbae2733bf6',
'auctionId': '1d1a030790a475',
};

it('should return true when required params found', () => {
expect(spec.isBidRequestValid(bid)).to.equal(true);
});

it('should return false when required params are not passed', () => {
let bid = Object.assign({}, bid);
delete bid.params;
bid.params = {
'placementId': 0
};
expect(spec.isBidRequestValid(bid)).to.equal(false);
});
});

describe('buildRequests', () => {
let bidRequests = [
{
'bidder': 'vertoz',
'params': {
'placementId': '10433394'
},
'adUnitCode': 'adunit-code',
'sizes': [[300, 250], [300, 600]],
'bidId': '30b31c1838de1e',
'bidderRequestId': '22edbae2733bf6',
'auctionId': '1d1a030790a475',
}
];

it('sends bid request to ENDPOINT via POST', () => {
const request = spec.buildRequests(bidRequests)[0];
expect(request.url).to.equal(BASE_URI);
expect(request.method).to.equal('POST');
});
});

describe('interpretResponse', () => {
let response = {
'vzhPlacementId': 'VZ-HB-B784382V6C6G3C',
'bid': '76021e56-adaf-4114-b68d-ccacd1b3e551_1',
'adWidth': '300',
'adHeight': '250',
'cpm': '0.16312590000000002',
'ad': '<!-- Creative -->',
'slotBidId': '44b3fcfd24aa93',
'nurl': '<!-- Pixelurl -->',
'statusText': 'Vertoz:Success'
};

it('should get correct bid response', () => {
let expectedResponse = [
{
'requestId': '44b3fcfd24aa93',
'cpm': 0.16312590000000002,
'width': 300,
'height': 250,
'netRevenue': true,
'mediaType': 'banner',
'currency': 'USD',
'dealId': null,
'creativeId': null,
'ttl': 300,
'ad': '<!-- Creative -->'
}
];
let bidderRequest;
let result = spec.interpretResponse({body: response});
expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0]));
expect(result[0].cpm).to.not.equal(null);
});

it('handles nobid responses', () => {
let response = {
'vzhPlacementId': 'VZ-HB-I617046VBGE3EH',
'slotBidId': 'f00412ac86b79',
'statusText': 'NO_BIDS'
};
let bidderRequest;

let result = spec.interpretResponse({body: response});
expect(result.length).to.equal(0);
});
});
});