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

Biddo Bid Adapter: add new bid adapter #8206

Merged
merged 10 commits into from
Apr 5, 2022
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
92 changes: 92 additions & 0 deletions modules/biddoBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {BANNER} from '../src/mediaTypes.js';

const BIDDER_CODE = 'biddo';
const ENDPOINT_URL = 'https://ad.adopx.net/delivery/impress';

export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER],
/**
* Determines whether or not the given bid request is valid.
*
* @param {BidRequest} bidRequest The bid request params to validate.
* @return boolean True if this is a valid bid request, and false otherwise.
*/
isBidRequestValid: function(bidRequest) {
return !!bidRequest.params.zoneId;
},
/**
* Make a server request from the list of BidRequests.
*
* @param {Array<BidRequest>} validBidRequests an array of bid requests
* @return ServerRequest Info describing the request to the server.
*/
buildRequests: function(validBidRequests) {
let serverRequests = [];

validBidRequests.forEach(bidRequest => {
const sizes = bidRequest.mediaTypes.banner.sizes;

sizes.forEach(([width, height]) => {
bidRequest.params.requestedSizes = [width, height];

const payload = {
ctype: 'div',
pzoneid: bidRequest.params.zoneId,
width,
height,
};

const payloadString = Object.keys(payload).map(k => k + '=' + encodeURIComponent(payload[k])).join('&');

serverRequests.push({
msm0504 marked this conversation as resolved.
Show resolved Hide resolved
method: 'GET',
url: ENDPOINT_URL,
data: payloadString,
bidderRequest: bidRequest,
});
});
});

return serverRequests;
},
/**
* Unpack the response from the server into a list of bids.
*
* @param {ServerResponse} serverResponse A successful response from the server.
* @param {BidRequest} bidderRequest A matched bid request for this response.
* @return Array<BidResponse> An array of bids which were nested inside the server.
*/
interpretResponse: function(serverResponse, {bidderRequest}) {
const response = serverResponse.body;
const bidResponses = [];

if (response && response.template && response.template.html) {
const {bidId} = bidderRequest;
const [width, height] = bidderRequest.params.requestedSizes;

const bidResponse = {
requestId: bidId,
cpm: response.hb.cpm,
creativeId: response.banner.hash,
currency: 'USD',
netRevenue: response.hb.netRevenue,
ttl: 600,
ad: response.template.html,
mediaType: 'banner',
meta: {
advertiserDomains: response.hb.adomains || [],
},
width,
height,
};

bidResponses.push(bidResponse);
}

return bidResponses;
},
}

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

```
Module Name: Biddo Bidder Adapter
Module Type: Bidder Adapter
Maintainer: contact@biddo.net
```

# Description

Module that connects to Invamia demand sources.

# Test Parameters

```
const adUnits = [{
code: 'test-div',
mediaTypes: {
banner: {
sizes: [[300, 250]],
},
},
bids: [{
bidder: 'biddo',
params: {
zoneId: 7254,
},
}],
}];
```
172 changes: 172 additions & 0 deletions test/spec/modules/biddoBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
import {expect} from 'chai';
import {spec} from 'modules/biddoBidAdapter.js';

describe('biddo bid adapter tests', function () {
describe('bid requests', function () {
it('should accept valid bid', function () {
const validBid = {
bidder: 'biddo',
params: {zoneId: 123},
};

expect(spec.isBidRequestValid(validBid)).to.equal(true);
});

it('should reject invalid bid', function () {
const invalidBid = {
bidder: 'biddo',
params: {},
};

expect(spec.isBidRequestValid(invalidBid)).to.equal(false);
});

it('should correctly build payload string', function () {
const bidRequests = [{
bidder: 'biddo',
params: {zoneId: 123},
mediaTypes: {
banner: {
sizes: [[300, 250]],
},
},
bidId: '23acc48ad47af5',
auctionId: '0fb4905b-9456-4152-86be-c6f6d259ba99',
bidderRequestId: '1c56ad30b9b8ca8',
transactionId: '92489f71-1bf2-49a0-adf9-000cea934729',
}];
const payload = spec.buildRequests(bidRequests)[0].data;

expect(payload).to.contain('ctype=div');
expect(payload).to.contain('pzoneid=123');
expect(payload).to.contain('width=300');
expect(payload).to.contain('height=250');
});

it('should support multiple bids', function () {
const bidRequests = [{
bidder: 'biddo',
params: {zoneId: 123},
mediaTypes: {
banner: {
sizes: [[300, 250]],
},
},
bidId: '23acc48ad47af5',
auctionId: '0fb4905b-9456-4152-86be-c6f6d259ba99',
bidderRequestId: '1c56ad30b9b8ca8',
transactionId: '92489f71-1bf2-49a0-adf9-000cea934729',
}, {
bidder: 'biddo',
params: {zoneId: 321},
mediaTypes: {
banner: {
sizes: [[728, 90]],
},
},
bidId: '23acc48ad47af52',
auctionId: '0fb4905b-9456-4152-86be-c6f6d259ba992',
bidderRequestId: '1c56ad30b9b8ca82',
transactionId: '92489f71-1bf2-49a0-adf9-000cea9347292',
}];
const payload = spec.buildRequests(bidRequests);

expect(payload).to.be.lengthOf(2);
});

it('should support multiple sizes', function () {
const bidRequests = [{
bidder: 'biddo',
params: {zoneId: 123},
mediaTypes: {
banner: {
sizes: [[300, 250], [300, 600]],
},
},
bidId: '23acc48ad47af5',
auctionId: '0fb4905b-9456-4152-86be-c6f6d259ba99',
bidderRequestId: '1c56ad30b9b8ca8',
transactionId: '92489f71-1bf2-49a0-adf9-000cea934729',
}];
const payload = spec.buildRequests(bidRequests);

expect(payload).to.be.lengthOf(2);
});
});

describe('bid responses', function () {
it('should return complete bid response', function () {
const serverResponse = {
body: {
banner: {
hash: '1c56ad30b9b8ca8',
},
hb: {
cpm: 0.5,
netRevenue: false,
adomains: ['securepubads.g.doubleclick.net'],
},
template: {
html: '<ad></ad>',
},
},
};
const bidderRequest = {
bidId: '23acc48ad47af5',
params: {
requestedSizes: [300, 250],
},
};

const bids = spec.interpretResponse(serverResponse, {bidderRequest});

expect(bids).to.be.lengthOf(1);
expect(bids[0].requestId).to.equal('23acc48ad47af5');
expect(bids[0].creativeId).to.equal('1c56ad30b9b8ca8');
expect(bids[0].width).to.equal(300);
expect(bids[0].height).to.equal(250);
expect(bids[0].ttl).to.equal(600);
expect(bids[0].cpm).to.equal(0.5);
expect(bids[0].netRevenue).to.equal(false);
expect(bids[0].currency).to.equal('USD');
expect(bids[0].meta.advertiserDomains).to.be.lengthOf(1);
expect(bids[0].meta.advertiserDomains[0]).to.equal('securepubads.g.doubleclick.net');
});

it('should return empty bid response', function () {
const serverResponse = {
body: {},
};
const bidderRequest = {
bidId: '23acc48ad47af5',
params: {
requestedSizes: [300, 250],
},
};

const bids = spec.interpretResponse(serverResponse, {bidderRequest});

expect(bids).to.be.lengthOf(0);
});

it('should return empty bid response 2', function () {
const serverResponse = {
body: {
template: {
html: '',
}
},
};
const bidderRequest = {
bidId: '23acc48ad47af5',
params: {
requestedSizes: [300, 250],
},
};

const bids = spec.interpretResponse(serverResponse, {bidderRequest});

expect(bids).to.be.lengthOf(0);
});
});
});