Skip to content

Commit

Permalink
Add Logicad for Publishers bid adapter (prebid#4010)
Browse files Browse the repository at this point in the history
* Add Logicad for Publishers bid adapter

* Add test code
  • Loading branch information
logicad authored and jsnellbaker committed Jul 23, 2019
1 parent 2ceeb38 commit 2aa8846
Show file tree
Hide file tree
Showing 3 changed files with 212 additions and 0 deletions.
68 changes: 68 additions & 0 deletions modules/logicadBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import {registerBidder} from '../src/adapters/bidderFactory';
import {BANNER} from '../src/mediaTypes';

const BIDDER_CODE = 'logicad';
const ENDPOINT_URL = 'https://pb.ladsp.com/adrequest/prebid';

export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER],
isBidRequestValid: function (bid) {
return !!(bid.params && bid.params.tid);
},
buildRequests: function (bidRequests, bidderRequest) {
const requests = [];
for (let i = 0, len = bidRequests.length; i < len; i++) {
const request = {
method: 'POST',
url: ENDPOINT_URL,
data: JSON.stringify(newBidRequest(bidRequests[i], bidderRequest)),
options: {},
bidderRequest
};
requests.push(request);
}
return requests;
},
interpretResponse: function (serverResponse, bidderRequest) {
serverResponse = serverResponse.body;
const bids = [];
if (!serverResponse || serverResponse.error) {
return bids;
}
serverResponse.seatbid.forEach(function (seatbid) {
bids.push(seatbid.bid);
})
return bids;
},
getUserSyncs: function (syncOptions, serverResponses) {
if (serverResponses.length > 0 && serverResponses[0].body.userSync &&
syncOptions.pixelEnabled && serverResponses[0].body.userSync.type == 'image') {
return [{
type: 'image',
url: serverResponses[0].body.userSync.url
}];
}
return [];
},
};

function newBidRequest(bid, bidderRequest) {
return {
auctionId: bid.auctionId,
bidderRequestId: bid.bidderRequestId,
bids: [{
adUnitCode: bid.adUnitCode,
bidId: bid.bidId,
transactionId: bid.transactionId,
sizes: bid.sizes,
params: bid.params,
mediaTypes: bid.mediaTypes
}],
prebidJsVersion: '$prebid.version$',
referrer: bidderRequest.refererInfo.referer,
auctionStartTime: bidderRequest.auctionStart,
};
}

registerBidder(spec);
25 changes: 25 additions & 0 deletions modules/logicadBidAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Overview
```
Module Name: Logicad for Publishers
Module Type: Bidder Adapter
Maintainer: [email protected]
```

# Description
Module that connects to Logicad's demand sources.
Currently module supports only banner mediaType.

# Test Parameters
```
var adUnits = [{
code: 'test-code',
sizes: [[300, 250],[300, 600]],
bids: [{
bidder: 'logicad',
params: {
tid: 'test',
page: 'url',
}
}]
}];
```
119 changes: 119 additions & 0 deletions test/spec/modules/logicadBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import {expect} from 'chai';
import {spec} from '../../../modules/logicadBidAdapter';
import * as utils from 'src/utils';

describe('LogicadAdapter', function () {
const bidRequests = [{
bidder: 'logicad',
bidId: '51ef8751f9aead',
params: {
tid: 'PJ2P',
page: 'http://www.logicad.com/'
},
adUnitCode: 'div-gpt-ad-1460505748561-0',
transactionId: 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec',
sizes: [[300, 250], [300, 600]],
bidderRequestId: '418b37f85e772c',
auctionId: '18fd8b8b0bd757',
mediaTypes: {
banner: {
sizes: [[300, 250], [300, 600]]
}
}
}];
const bidderRequest = {
refererInfo: {
referer: 'fakeReferer',
reachedTop: true,
numIframes: 1,
stack: []
},
auctionStart: 1563337198010
};
const serverResponse = {
body: {
seatbid:
[{
bid: {
requestId: '51ef8751f9aead',
cpm: 101.0234,
width: 300,
height: 250,
creativeId: '2019',
currency: 'JPY',
netRevenue: true,
ttl: 60,
ad: '<div>TEST</div>'
}
}],
userSync: {
type: 'image',
url: 'https://cr-p31.ladsp.jp/cookiesender/31'
}
}
};

describe('isBidRequestValid', function () {
it('should return true if the tid parameter is present', function () {
expect(spec.isBidRequestValid(bidRequests[0])).to.be.true;
});

it('should return false if the tid parameter is not present', function () {
let bidRequest = utils.deepClone(bidRequests[0]);
delete bidRequest.params.tid;
expect(spec.isBidRequestValid(bidRequest)).to.be.false;
});

it('should return false if the params object is not present', function () {
let bidRequest = utils.deepClone(bidRequests);
delete bidRequest[0].params;
expect(spec.isBidRequestValid(bidRequest)).to.be.false;
});
});

describe('buildRequests', function () {
it('should generate a valid single POST request for multiple bid requests', function () {
const request = spec.buildRequests(bidRequests, bidderRequest)[0];
expect(request.method).to.equal('POST');
expect(request.url).to.equal('https://pb.ladsp.com/adrequest/prebid');
expect(request.data).to.exist;
});
});

describe('interpretResponse', function () {
it('should return an empty array if an invalid response is passed', function () {
const interpretedResponse = spec.interpretResponse({}, {});
expect(interpretedResponse).to.be.an('array').that.is.empty;
});

it('should return valid response when passed valid server response', function () {
const request = spec.buildRequests(bidRequests, bidderRequest)[0];
const interpretedResponse = spec.interpretResponse(serverResponse, request);

expect(interpretedResponse).to.have.lengthOf(1);

expect(interpretedResponse[0].requestId).to.equal(serverResponse.body.seatbid[0].bid.requestId);
expect(interpretedResponse[0].cpm).to.equal(serverResponse.body.seatbid[0].bid.cpm);
expect(interpretedResponse[0].width).to.equal(serverResponse.body.seatbid[0].bid.width);
expect(interpretedResponse[0].height).to.equal(serverResponse.body.seatbid[0].bid.height);
expect(interpretedResponse[0].creativeId).to.equal(serverResponse.body.seatbid[0].bid.creativeId);
expect(interpretedResponse[0].currency).to.equal(serverResponse.body.seatbid[0].bid.currency);
expect(interpretedResponse[0].netRevenue).to.equal(serverResponse.body.seatbid[0].bid.netRevenue);
expect(interpretedResponse[0].ad).to.equal(serverResponse.body.seatbid[0].bid.ad);
expect(interpretedResponse[0].ttl).to.equal(serverResponse.body.seatbid[0].bid.ttl);
});
});

describe('getUserSyncs', function () {
it('should perform usersync', function () {
let syncs = spec.getUserSyncs({pixelEnabled: false}, [serverResponse]);
expect(syncs).to.have.length(0);
console.log(serverResponse);
syncs = spec.getUserSyncs({pixelEnabled: true}, [serverResponse]);
expect(syncs).to.have.length(1);

expect(syncs[0]).to.have.property('type', 'image');
expect(syncs[0]).to.have.property('url', 'https://cr-p31.ladsp.jp/cookiesender/31');
});
});
});

0 comments on commit 2aa8846

Please sign in to comment.