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

adbund adapter #932

Merged
merged 18 commits into from
Feb 28, 2017
Merged
1 change: 1 addition & 0 deletions adapters.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[
"aardvark",
"adblade",
"adbund",
"adbutler",
"adequant",
"adform",
Expand Down
15 changes: 11 additions & 4 deletions integrationExamples/gpt/pbjs_example_gpt.html
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,14 @@
{
bidder: 'memeglobal',
params: {
tagid: 007, // REQUIRED int. To get one, contact http://www.memeglobal.com
tagid: 007, // REQUIRED int. To get one, contact http://www.memeglobal.com
}
},
{
bidder: 'adblade',
params: {
partnerId: 42980,
bidfloor: 0.01 // OPTIONAL float bid floor in $ CPM
bidfloor: 0.01 // OPTIONAL float bid floor in $ CPM
}
},
{
Expand All @@ -231,6 +231,13 @@
cur: 'EUR'
}
},
{
bidder: 'adbund',
params: {
sid: '110238', // REQUIRED int. To get one, sign up http://www.adbund.com
bidfloor: 0.036 // OPTIONAL float bid floor in $ CPM
}
},
{
bidder: 'smartyads',
params: {
Expand Down Expand Up @@ -329,7 +336,7 @@
{
bidder: 'memeglobal',
params: {
tagid: 007, // REQUIRED int. To get one, contact http://www.memeglobal.com
tagid: 007, // REQUIRED int. To get one, contact http://www.memeglobal.com
}
},
{
Expand All @@ -346,7 +353,7 @@
$$PREBID_GLOBAL$$.addAdUnits(adUnits);

//register a callback handler
$$PREBID_GLOBAL$$.addCallback('adUnitBidsBack', function (adUnitCode) {
$$PREBID_GLOBAL$$.addCallback('adUnitBidsBack', function (adUnitCode) {
console.debug('ad unit bids back for:', adUnitCode);
});

Expand Down
66 changes: 66 additions & 0 deletions src/adapters/adbund.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
var CONSTANTS = require('../constants.json');
var utils = require('../utils.js');
var bidfactory = require('../bidfactory.js');
var bidmanager = require('../bidmanager.js');
var adloader = require('../adloader');

var adBundAdapter = function adBundAdapter() {
var timezone = (new Date()).getTimezoneOffset();
var bidAPIs = [
'http://us-east-engine.adbund.xyz/prebid/ad/get',
'http://us-west-engine.adbund.xyz/prebid/ad/get'
];
//Based on the time zone to select the interface to the server
var bidAPI = bidAPIs[timezone < 0 ? 0 : 1];

function _stringify(param) {
var result = [];
var key;
for (key in param) {
if (param.hasOwnProperty(key)) {
result.push(key + '=' + encodeURIComponent(param[key]));
}
}
return result.join('&');
}

function _createCallback(bid) {
return function (data) {
var response;
if (data && data.cpm) {
response = bidfactory.createBid(CONSTANTS.STATUS.GOOD);
response.bidderCode = 'adbund';
Object.assign(response, data);
} else {
response = bidfactory.createBid(CONSTANTS.STATUS.NO_BID);
response.bidderCode = 'adbund';
}
bidmanager.addBidResponse(bid.placementCode, response);
};
}

function _requestBids(bid) {
var info = {
referrer: utils.getTopWindowUrl(),
domain: utils.getTopWindowLocation().hostname,
ua: window.navigator.userAgent
};
var param = Object.assign({}, bid.params, info);
param.sizes = JSON.stringify(param.sizes || bid.sizes);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am getting bid back for size [[300,250]] but not for [300,250]. Please add support for the same.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has been modified, please review again

param.callback = '$$PREBID_GLOBAL$$.adbundResponse';
$$PREBID_GLOBAL$$.adbundResponse = _createCallback(bid);
adloader.loadScript(bidAPI + '?' + _stringify(param));
}

function _callBids(params) {
(params.bids || []).forEach(function (bid) {
_requestBids(bid);
});
}

return {
callBids: _callBids
};
};

module.exports = adBundAdapter;
96 changes: 96 additions & 0 deletions test/spec/adapters/adbund_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { expect } from 'chai';
import Adapter from '../../../src/adapters/adbund';
import bidManager from 'src/bidmanager';
import CONSTANTS from 'src/constants.json';

describe('adbund adapter tests', function () {

let sandbox;
let adapter;
let server;

const request = {
bidderCode: 'adbund',
bids: [{
bidder: 'adbund',
params: {
sid: '110238',
bidfloor: 0.036
},
placementCode: 'adbund',
sizes: [[300, 250]],
bidId: 'adbund_bidId',
bidderRequestId: 'adbund_bidderRequestId',
requestId: 'adbund_requestId'
}]
};

const response = {
bidderCode: 'adbund',
cpm: 1.06,
height: 250,
width: 300
};

beforeEach(() => {
sandbox = sinon.sandbox.create();
});

afterEach(() => {
sandbox.restore();
});

describe('adbund callBids validation', () => {

beforeEach(() => {
adapter = new Adapter();
});

afterEach(() => {
});

it('Valid bid-request', () => {
let bidderRequest;

sandbox.stub(adapter, 'callBids');
adapter.callBids(request);

bidderRequest = adapter.callBids.getCall(0).args[0];

expect(bidderRequest).to.have.property('bids')
.that.is.an('array')
.with.lengthOf(1);

expect(bidderRequest).to.have.deep.property('bids[0]')
.to.have.property('bidder', 'adbund');

expect(bidderRequest).to.have.deep.property('bids[0]')
.with.property('sizes')
.that.is.an('array')
.with.lengthOf(1)
.that.deep.equals(request.bids[0].sizes);

expect(bidderRequest).to.have.deep.property('bids[0]')
.with.property('params')
.to.have.property('bidfloor', 0.036);
});

it('Valid bid-response', () => {
var bidderResponse;

sandbox.stub(bidManager, 'addBidResponse');
adapter.callBids(request);
bidderResponse = bidManager.addBidResponse.getCall(0) ||
bidManager.addBidResponse.getCall(1);

if (bidderResponse && bidderResponse.args && bidderResponse.args[1]) {
bidderResponse = bidderResponse.args[1];
expect(bidderResponse.getStatusCode()).to.equal(CONSTANTS.STATUS.GOOD);
expect(bidderResponse.bidderCode).to.equal(response.bidderCode);
expect(bidderResponse.width).to.equal(response.width);
expect(bidderResponse.height).to.equal(response.height);
expect(bidderResponse.cpm).to.equal(response.cpm);
}
});
});
});