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

Implement glomex bid adapter #6209

Merged
merged 4 commits into from
Jan 26, 2021
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
86 changes: 86 additions & 0 deletions modules/glomexBidAdapter.js
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)
32 changes: 32 additions & 0 deletions modules/glomexBidAdapter.md
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'
}
}]
}
];
```
133 changes: 133 additions & 0 deletions test/spec/modules/glomexBidAdapter_spec.js
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 />')
})
})
})