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

Adding Edge Query X Adapter (with right md file) #5266

Merged
merged 18 commits into from
May 22, 2020
98 changes: 98 additions & 0 deletions modules/edgequeryxBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import * as utils from '../src/utils.js';
import { config } from '../src/config.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';

const BIDDER_CODE = 'edgequeryx';

export const spec = {
code: BIDDER_CODE,
aliases: ['eqx'], // short code
supportedMediaTypes: [BANNER, VIDEO],
/**
* 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 && bid.params.accountId && bid.params.widgetId);
},

/**
* Make a server request from the list of BidRequests.
*
* @param {BidRequest[]} validBidRequests an array of bids
* @param {BidderRequest} bidderRequest bidder request object
* @return {ServerRequest[]} Info describing the request to the server.
*/
buildRequests: function (validBidRequests, bidderRequest) {
// use bidderRequest.bids[] to get bidder-dependent request info
// if your bidder supports multiple currencies, use config.getConfig(currency)
// to find which one the ad server needs

// pull requested transaction ID from bidderRequest.bids[].transactionId
return validBidRequests.map(bid => {
// Common bid request attributes for banner, outstream and instream.
let payload = {
accountId: bid.params.accountId,
widgetId: bid.params.widgetId,
currencyCode: 'EUR',
tagId: bid.adUnitCode,
transactionId: bid.transactionId,
timeout: config.getConfig('bidderTimeout'),
bidId: bid.bidId,
prebidVersion: '$prebid.version$'
};

const bannerMediaType = utils.deepAccess(bid, 'mediaTypes.banner');
payload.sizes = bannerMediaType.sizes.map(size => ({
w: size[0],
h: size[1]
}));

var payloadString = JSON.stringify(payload);

return {
method: 'POST',
url: (bid.params.domain !== undefined ? bid.params.domain : 'https://deep.edgequery.io') + '/prebid/x',
data: payloadString,
};
});
},

/**
* Unpack the response from the server into a list of bids.
*
* @param {*} serverResponse A successful response from the server.
* @param {*} bidRequestString
* @return {Bid[]} An array of bids which were nested inside the server.
*/
interpretResponse: function (serverResponse, bidRequestString) {
const bidResponses = [];
let response = serverResponse.body;
try {
if (response) {
let bidResponse = {
requestId: response.requestId,
cpm: response.cpm,
currency: response.currency,
width: response.width,
height: response.height,
ad: response.ad,
ttl: response.ttl,
creativeId: response.creativeId,
netRevenue: response.netRevenue
};

bidResponses.push(bidResponse);
}
} catch (error) {
utils.logError('Error while parsing Edge Query X response', error);
}
return bidResponses;
}

};

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

```
Module Name: Edge Query X Bidder Adapter
Module Type: Bidder Adapter
Maintainer: contact@edgequery.com
```

# Description

Connect to Edge Query X for bids.

The Edge Query X adapter requires setup and approval from the Edge Query team.
Please reach out to your Technical account manager for more information.

# Test Parameters

## Web
```
var adUnits = [
{
code: 'test-div',
mediaTypes: {
banner: {
sizes: [[1, 1]]
}
},
bids: [
{
bidder: "edgequeryx",
params: {
accountId: "test",
widgetId: "test"
}
}
]
}
];
```
116 changes: 116 additions & 0 deletions test/spec/modules/edgequeryxBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import {
Copy link
Contributor

Choose a reason for hiding this comment

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

any specific reason why you use this multi-line format for imports here, while on lines 13 and 14 you're inlining them?

expect
} from 'chai';
import {
spec
} from 'modules/edgequeryxBidAdapter.js';
import {
newBidder
} from 'src/adapters/bidderFactory.js';
import {
config
} from 'src/config.js';
import * as utils from 'src/utils.js';
import { requestBidsHook } from 'modules/consentManagement.js';

// Default params with optional ones
describe('Edge Query X bid adapter tests', function () {
var DEFAULT_PARAMS = [{
bidId: 'abcd1234',
mediaTypes: {
banner: {
sizes: [
[1, 1]
]
}
},
bidder: 'edgequeryx',
params: {
accountId: 'test',
widgetId: 'test'
},
requestId: 'efgh5678',
transactionId: 'zsfgzzg'
}];
var BID_RESPONSE = {
body: {
requestId: 'abcd1234',
cpm: 22,
width: 1,
height: 1,
creativeId: 'EQXTest',
currency: 'EUR',
netRevenue: true,
ttl: 360,
ad: '< --- awesome script --- >'
}
};

it('Verify build request', function () {
config.setConfig({
'currency': {
'adServerCurrency': 'EUR'
}
});
const request = spec.buildRequests(DEFAULT_PARAMS);
expect(request[0]).to.have.property('url').and.to.equal('https://deep.edgequery.io/prebid/x');
expect(request[0]).to.have.property('method').and.to.equal('POST');
const requestContent = JSON.parse(request[0].data);

expect(requestContent).to.have.property('accountId').and.to.equal('test');
expect(requestContent).to.have.property('widgetId').and.to.equal('test');
expect(requestContent).to.have.property('sizes');
expect(requestContent.sizes[0]).to.have.property('w').and.to.equal(1);
expect(requestContent.sizes[0]).to.have.property('h').and.to.equal(1);
});

it('Verify parse response', function () {
const request = spec.buildRequests(DEFAULT_PARAMS);
const bids = spec.interpretResponse(BID_RESPONSE, request[0]);
expect(bids).to.have.lengthOf(1);
const bid = bids[0];
expect(bid.cpm).to.equal(22);
expect(bid.ad).to.equal('< --- awesome script --- >');
expect(bid.width).to.equal(1);
expect(bid.height).to.equal(1);
expect(bid.creativeId).to.equal('EQXTest');
expect(bid.currency).to.equal('EUR');
expect(bid.netRevenue).to.equal(true);
expect(bid.ttl).to.equal(360);
expect(bid.requestId).to.equal(DEFAULT_PARAMS[0].bidId);

expect(function () {
spec.interpretResponse(BID_RESPONSE, {
data: 'invalid Json'
})
}).to.not.throw();
});

it('Verifies bidder code', function () {
expect(spec.code).to.equal('edgequeryx');
});

it('Verifies bidder aliases', function () {
expect(spec.aliases).to.have.lengthOf(1);
expect(spec.aliases[0]).to.equal('eqx');
});

it('Verifies if bid request valid', function () {
expect(spec.isBidRequestValid(DEFAULT_PARAMS[0])).to.equal(true);
expect(spec.isBidRequestValid({})).to.equal(false);
expect(spec.isBidRequestValid({
params: {}
})).to.equal(false);
expect(spec.isBidRequestValid({
params: {
widgetyId: 'abcdef'
}
})).to.equal(false);
expect(spec.isBidRequestValid({
params: {
widgetId: 'test',
accountId: 'test'
}
})).to.equal(true);
});
});