-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding Edge Query X Adapter (with right md file) (#5266)
* Add files via upload * Bug fixed * Remove some new lines * Correction Circle * Test Unit * Indent * Indent 2 space * Single quote * test unit * requestID * Rename mb to md * add md * Correcting md file * Improving gulp test to get more than 80% * Correcting double lines * Update package-lock.json * Back to original lock version * Back to original package-lock.json version Co-authored-by: Olivier <olivier@MacBook-Pro-de-Olivier.local>
- Loading branch information
Edge Query
and
Olivier
authored
May 22, 2020
1 parent
67a1b1e
commit 9ca46df
Showing
3 changed files
with
253 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
] | ||
} | ||
]; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import { | ||
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); | ||
}); | ||
}); |