forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement glomex bid adapter (prebid#6209)
* Implement glomexBidAdapter * Implement glomexBidAdapter with tests and docs Co-authored-by: Herb Dombrowski <32455795+hrb-d@users.noreply.github.com>
- Loading branch information
1 parent
af8af15
commit 0284cc2
Showing
3 changed files
with
251 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,86 @@ | ||
import { registerBidder } from '../src/adapters/bidderFactory.js' | ||
import find from 'core-js-pure/features/array/find.js' | ||
import { BANNER } from '../src/mediaTypes.js' | ||
|
||
const ENDPOINT = 'https://prebid.mes.glomex.cloud/request-bid' | ||
const BIDDER_CODE = 'glomex' | ||
|
||
export const spec = { | ||
code: BIDDER_CODE, | ||
supportedMediaTypes: [BANNER], | ||
|
||
isBidRequestValid: function (bid) { | ||
if (bid && bid.params && bid.params.integrationId) { | ||
return true | ||
} | ||
return false | ||
}, | ||
|
||
buildRequests: function (validBidRequests, bidderRequest = {}) { | ||
const refererInfo = bidderRequest.refererInfo || {}; | ||
const gdprConsent = bidderRequest.gdprConsent || {}; | ||
|
||
return { | ||
method: 'POST', | ||
url: `${ENDPOINT}`, | ||
data: { | ||
auctionId: bidderRequest.auctionId, | ||
refererInfo: { | ||
isAmp: refererInfo.isAmp, | ||
numIframes: refererInfo.numIframes, | ||
reachedTop: refererInfo.reachedTop, | ||
referer: refererInfo.referer | ||
}, | ||
gdprConsent: { | ||
consentString: gdprConsent.consentString, | ||
gdprApplies: gdprConsent.gdprApplies | ||
}, | ||
bidRequests: validBidRequests.map(({ params, sizes, bidId, adUnitCode }) => ({ | ||
bidId, | ||
adUnitCode, | ||
params, | ||
sizes | ||
})) | ||
}, | ||
options: { | ||
withCredentials: false, | ||
contentType: 'application/json' | ||
}, | ||
validBidRequests: validBidRequests, | ||
} | ||
}, | ||
|
||
interpretResponse: function (serverResponse, originalBidRequest) { | ||
const bidResponses = [] | ||
|
||
originalBidRequest.validBidRequests.forEach(function (bidRequest) { | ||
if (!serverResponse.body) { | ||
return | ||
} | ||
|
||
const matchedBid = find(serverResponse.body.bids, function (bid) { | ||
return String(bidRequest.bidId) === String(bid.id) | ||
}) | ||
|
||
if (matchedBid) { | ||
const bidResponse = { | ||
requestId: bidRequest.bidId, | ||
cpm: matchedBid.cpm, | ||
width: matchedBid.width, | ||
height: matchedBid.height, | ||
creativeId: matchedBid.creativeId, | ||
dealId: matchedBid.dealId, | ||
currency: matchedBid.currency, | ||
netRevenue: matchedBid.netRevenue, | ||
ttl: matchedBid.ttl, | ||
ad: matchedBid.ad | ||
} | ||
|
||
bidResponses.push(bidResponse) | ||
} | ||
}) | ||
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,32 @@ | ||
# Overview | ||
|
||
``` | ||
Module Name: Glomex Bidder Adapter | ||
Module Type: Bidder Adapter | ||
Maintainer: integration-squad@services.glomex.com | ||
``` | ||
|
||
# Description | ||
|
||
Module to use the Glomex Player with prebid.js | ||
|
||
# Test Parameters | ||
``` | ||
var adUnits = [ | ||
{ | ||
code: "banner", | ||
mediaTypes: { | ||
banner: { | ||
sizes: [[640, 360]] | ||
} | ||
}, | ||
bids: [{ | ||
bidder: "glomex", | ||
params: { | ||
integrationId: '4059a11hkdzuf65i', | ||
playlistId: 'v-bdui4dz7vjq9' | ||
} | ||
}] | ||
} | ||
]; | ||
``` |
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,133 @@ | ||
import { expect } from 'chai' | ||
import { spec } from 'modules/glomexBidAdapter.js' | ||
import { newBidder } from 'src/adapters/bidderFactory.js' | ||
|
||
const REQUEST = { | ||
bidder: 'glomex', | ||
params: { | ||
integrationId: 'abcdefg', | ||
playlistId: 'defghjk' | ||
}, | ||
bidderRequestId: '143346cf0f1732', | ||
auctionId: '2e41f65424c87c', | ||
adUnitCode: 'adunit-code', | ||
bidId: '2d925f27f5079f', | ||
sizes: [640, 360] | ||
} | ||
|
||
const BIDDER_REQUEST = { | ||
auctionId: '2d921234f5079f', | ||
refererInfo: { | ||
isAmp: true, | ||
numIframes: 0, | ||
reachedTop: true, | ||
referer: 'https://glomex.com' | ||
}, | ||
gdprConsent: { | ||
gdprApplies: true, | ||
consentString: 'CO5asbJO5asbJE-AAAENAACAAAAAAAAAAAYgAAAAAAAA.IAAA' | ||
} | ||
} | ||
|
||
const RESPONSE = { | ||
bids: [ | ||
{ | ||
id: '2d925f27f5079f', | ||
cpm: 3.5, | ||
width: 640, | ||
height: 360, | ||
creativeId: 'creative-1j75x4ln1kk6m1ius', | ||
dealId: 'deal-1j75x4ln1kk6m1iut', | ||
currency: 'EUR', | ||
netRevenue: true, | ||
ttl: 300, | ||
ad: '<ad />' | ||
} | ||
] | ||
} | ||
describe('glomexBidAdapter', function () { | ||
const adapter = newBidder(spec) | ||
|
||
describe('inherited functions', function () { | ||
it('exists and is a function', function () { | ||
expect(adapter.callBids).to.exist.and.to.be.a('function') | ||
}) | ||
}) | ||
|
||
describe('isBidRequestValid', function () { | ||
it('should return true when required params found', function () { | ||
const request = { | ||
'params': { | ||
'integrationId': 'abcdefg' | ||
} | ||
} | ||
expect(spec.isBidRequestValid(request)).to.equal(true) | ||
}) | ||
|
||
it('should return false when required params are not passed', function () { | ||
expect(spec.isBidRequestValid({})).to.equal(false) | ||
}) | ||
}) | ||
|
||
describe('buildRequests', function () { | ||
const bidRequests = [REQUEST] | ||
const request = spec.buildRequests(bidRequests, BIDDER_REQUEST) | ||
|
||
it('sends bid request to ENDPOINT via POST', function () { | ||
expect(request.method).to.equal('POST') | ||
}) | ||
|
||
it('returns a list of valid requests', function () { | ||
expect(request.validBidRequests).to.eql([REQUEST]) | ||
}) | ||
|
||
it('sends params.integrationId', function () { | ||
expect(request.validBidRequests[0].params.integrationId).to.eql(REQUEST.params.integrationId) | ||
}) | ||
|
||
it('sends params.playlistId', function () { | ||
expect(request.validBidRequests[0].params.playlistId).to.eql(REQUEST.params.playlistId) | ||
}) | ||
|
||
it('sends refererInfo', function () { | ||
expect(request.data.refererInfo).to.eql(BIDDER_REQUEST.refererInfo) | ||
}) | ||
|
||
it('sends gdprConsent', function () { | ||
expect(request.data.gdprConsent).to.eql(BIDDER_REQUEST.gdprConsent) | ||
}) | ||
|
||
it('sends the auctionId', function () { | ||
expect(request.data.auctionId).to.eql(BIDDER_REQUEST.auctionId) | ||
}) | ||
}) | ||
|
||
describe('interpretResponse', function () { | ||
it('handles nobid responses', function () { | ||
expect(spec.interpretResponse({body: {}}, {validBidRequests: []}).length).to.equal(0) | ||
expect(spec.interpretResponse({body: []}, {validBidRequests: []}).length).to.equal(0) | ||
}) | ||
|
||
it('handles the server response', function () { | ||
const result = spec.interpretResponse( | ||
{ | ||
body: RESPONSE | ||
}, | ||
{ | ||
validBidRequests: [REQUEST] | ||
} | ||
) | ||
|
||
expect(result[0].requestId).to.equal('2d925f27f5079f') | ||
expect(result[0].cpm).to.equal(3.5) | ||
expect(result[0].width).to.equal(640) | ||
expect(result[0].height).to.equal(360) | ||
expect(result[0].creativeId).to.equal('creative-1j75x4ln1kk6m1ius') | ||
expect(result[0].dealId).to.equal('deal-1j75x4ln1kk6m1iut') | ||
expect(result[0].currency).to.equal('EUR') | ||
expect(result[0].netRevenue).to.equal(true) | ||
expect(result[0].ttl).to.equal(300) | ||
expect(result[0].ad).to.equal('<ad />') | ||
}) | ||
}) | ||
}) |