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

AdOcean adapter - support for sizes defined in Prebid configuration. #5337

Merged
merged 6 commits into from
Jun 10, 2020
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
30 changes: 20 additions & 10 deletions modules/adoceanBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,21 @@ import { registerBidder } from '../src/adapters/bidderFactory.js';

const BIDDER_CODE = 'adocean';

function buildEndpointUrl(emiter, payload) {
let payloadString = '';
utils._each(payload, function(v, k) {
if (payloadString.length) {
payloadString += '&';
}
payloadString += k + '=' + encodeURIComponent(v);
function buildEndpointUrl(emiter, payloadMap) {
const payload = [];
utils._each(payloadMap, function(v, k) {
payload.push(k + '=' + encodeURIComponent(v));
});

const randomizedPart = Math.random().toString().slice(2);
return 'https://' + emiter + '/_' + randomizedPart + '/ad.json?' + payloadString;
return 'https://' + emiter + '/_' + randomizedPart + '/ad.json?' + payload.join('&');
}

function buildRequest(masterBidRequests, masterId, gdprConsent) {
let emiter;
const payload = {
id: masterId,
aosspsizes: []
};
if (gdprConsent) {
payload.gdpr_consent = gdprConsent.consentString || undefined;
Expand All @@ -32,13 +30,20 @@ function buildRequest(masterBidRequests, masterId, gdprConsent) {
if (!emiter) {
emiter = bid.params.emiter;
}

const slaveSizes = utils.parseSizesInput(bid.mediaTypes.banner.sizes).join('_');
const rawSlaveId = bid.params.slaveId.replace('adocean', '');
payload.aosspsizes.push(rawSlaveId + '~' + slaveSizes);

bidIdMap[slaveId] = bid.bidId;
});

payload.aosspsizes = payload.aosspsizes.join('-');

return {
method: 'GET',
url: buildEndpointUrl(emiter, payload),
data: {},
data: '',
bidIdMap: bidIdMap
};
}
Expand Down Expand Up @@ -86,7 +91,12 @@ export const spec = {
code: BIDDER_CODE,

isBidRequestValid: function(bid) {
return !!(bid.params.slaveId && bid.params.masterId && bid.params.emiter);
const requiredParams = ['slaveId', 'masterId', 'emiter'];
if (requiredParams.some(name => !utils.isStr(bid.params[name]) || !bid.params[name].length)) {
return false;
}

return !!bid.mediaTypes.banner;
},

buildRequests: function(validBidRequests, bidderRequest) {
Expand Down
36 changes: 31 additions & 5 deletions test/spec/modules/adoceanBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { expect } from 'chai';
import { spec } from 'modules/adoceanBidAdapter.js';
import { newBidder } from 'src/adapters/bidderFactory.js';
import { deepClone } from 'src/utils.js';

describe('AdoceanAdapter', function () {
const adapter = newBidder(spec);
Expand All @@ -20,7 +21,11 @@ describe('AdoceanAdapter', function () {
'emiter': 'myao.adocean.pl'
},
'adUnitCode': 'adunit-code',
'sizes': [[300, 250]],
'mediaTypes': {
'banner': {
'sizes': [[300, 250]]
}
},
'bidId': '30b31c1838de1e',
'bidderRequestId': '22edbae2733bf6',
'auctionId': '1d1a030790a475',
Expand Down Expand Up @@ -51,7 +56,11 @@ describe('AdoceanAdapter', function () {
'emiter': 'myao.adocean.pl'
},
'adUnitCode': 'adunit-code',
'sizes': [[300, 250]],
'mediaTypes': {
'banner': {
'sizes': [[300, 250], [300, 600]]
}
},
'bidId': '30b31c1838de1e',
'bidderRequestId': '22edbae2733bf6',
'auctionId': '1d1a030790a475',
Expand All @@ -64,7 +73,11 @@ describe('AdoceanAdapter', function () {
'emiter': 'myao.adocean.pl'
},
'adUnitCode': 'adunit-code',
'sizes': [[300, 250]],
'mediaTypes': {
'banner': {
'sizes': [[300, 200], [600, 250]]
}
},
'bidId': '30b31c1838de1f',
'bidderRequestId': '22edbae2733bf6',
'auctionId': '1d1a030790a475',
Expand All @@ -78,12 +91,12 @@ describe('AdoceanAdapter', function () {
}
};

it('should send two requests if slave is duplicated', () => {
it('should send two requests if slave is duplicated', function () {
const nrOfRequests = spec.buildRequests(bidRequests, bidderRequest).length;
expect(nrOfRequests).to.equal(2);
});

it('should add bidIdMap with correct slaveId => bidId mapping', () => {
it('should add bidIdMap with correct slaveId => bidId mapping', function () {
const requests = spec.buildRequests(bidRequests, bidderRequest);
for (let i = 0; i < bidRequests.length; i++) {
expect(requests[i]).to.exist;
Expand All @@ -108,6 +121,19 @@ describe('AdoceanAdapter', function () {
expect(request.url).to.include('gdpr=1');
expect(request.url).to.include('gdpr_consent=' + bidderRequest.gdprConsent.consentString);
});

it('should attach sizes information to url', function () {
let requests = spec.buildRequests(bidRequests, bidderRequest);
expect(requests[0].url).to.include('aosspsizes=myaozpniqismex~300x250_300x600');
expect(requests[1].url).to.include('aosspsizes=myaozpniqismex~300x200_600x250');

const differentSlavesBids = deepClone(bidRequests);
differentSlavesBids[1].params.slaveId = 'adoceanmyaowafpdwlrks';
requests = spec.buildRequests(differentSlavesBids, bidderRequest);
expect(requests.length).to.equal(1);
expect(requests[0].url).to.include('aosspsizes=myaozpniqismex~300x250_300x600-myaowafpdwlrks~300x200_600x250');
expect((requests[0].url.match(/aosspsizes=/g) || []).length).to.equal(1);
});
})

describe('interpretResponse', function () {
Expand Down