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.
- Loading branch information
Showing
3 changed files
with
172 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,42 @@ | ||
import * as utils from '../src/utils.js'; | ||
import { registerBidder } from '../src/adapters/bidderFactory.js'; | ||
import { config } from '../src/config.js'; | ||
import { BANNER } from '../src/mediaTypes.js'; | ||
import { ortbConverter } from '../libraries/ortbConverter/converter.js' | ||
const converter = ortbConverter({ | ||
context: { netRevenue: true, ttl: 300 }, | ||
imp(buildImp, bidRequest, context) { | ||
const imp = buildImp(bidRequest, context); | ||
utils.mergeDeep(imp, { | ||
tagid: bidRequest.params.site, | ||
}); | ||
return imp; | ||
} | ||
}); | ||
const BIDDER_CODE = 'optable'; | ||
const DEFAULT_REGION = 'ca' | ||
const DEFAULT_ORIGIN = 'https://ads.optable.co' | ||
|
||
export const spec = { | ||
code: BIDDER_CODE, | ||
isBidRequestValid: function(bid) { return !!bid.params?.site }, | ||
buildRequests: function(bidRequests, bidderRequest) { | ||
const region = config.getConfig('optable.region') ?? DEFAULT_REGION | ||
const origin = config.getConfig('optable.origin') ?? DEFAULT_ORIGIN | ||
const requestURL = `${origin}/${region}/ortb2/v1/ssp/bid` | ||
const data = converter.toORTB({ bidRequests, bidderRequest, context: { mediaType: BANNER } }); | ||
|
||
return { method: 'POST', url: requestURL, data } | ||
}, | ||
interpretResponse: function(response, request) { | ||
const bids = converter.fromORTB({ response: response.body, request: request.data }).bids | ||
const auctionConfigs = (response.body.ext?.optable?.fledge?.auctionconfigs ?? []).map((cfg) => { | ||
const { impid, ...config } = cfg; | ||
return { bidId: impid, config } | ||
}) | ||
|
||
return { bids, fledgeAuctionConfigs: auctionConfigs } | ||
}, | ||
supportedMediaTypes: [BANNER] | ||
} | ||
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,41 @@ | ||
# Overview | ||
|
||
``` | ||
Module Name: Optable Bidder Adapter | ||
Module Type: Bidder Adapter | ||
Maintainer: prebid@optable.co | ||
``` | ||
|
||
# Description | ||
|
||
Module that connects to Optable's demand sources. | ||
|
||
# Bid Parameters | ||
## Banner | ||
|
||
| Name | Scope | Type | Description | Example | ||
| ---- | ----- | ---- | ----------- | ------- | ||
| `site` | required | String | Optable site ID provided by your Optable representative. | "aaaaaaaa" | ||
|
||
## Video | ||
|
||
Not supported at the moment. | ||
|
||
# Example | ||
```javascript | ||
var adUnits = [ | ||
{ | ||
code: 'test-div', | ||
sizes: [[728, 90]], // a display size | ||
mediaTypes: {'banner': {}}, | ||
bids: [ | ||
{ | ||
bidder: 'optable', | ||
params: { | ||
site: 'aaaaaaaa', | ||
}, | ||
}, | ||
], | ||
}, | ||
]; | ||
``` |
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,89 @@ | ||
import { expect } from 'chai'; | ||
import { spec } from 'modules/optableBidAdapter'; | ||
import { newBidder } from 'src/adapters/bidderFactory.js'; | ||
|
||
describe('optableBidAdapter', function() { | ||
const adapter = newBidder(spec); | ||
|
||
describe('isBidRequestValid', function() { | ||
const validBid = { | ||
bidder: 'optable', | ||
params: { site: '123' }, | ||
}; | ||
|
||
it('should return true when required params are present', function() { | ||
expect(spec.isBidRequestValid(validBid)).to.be.true; | ||
}); | ||
|
||
it('should return false when site is missing', function() { | ||
const invalidBid = { ...validBid }; | ||
delete invalidBid.params.site; | ||
expect(spec.isBidRequestValid(invalidBid)).to.be.false; | ||
}); | ||
}); | ||
|
||
describe('buildRequests', function() { | ||
const validBid = { | ||
bidder: 'optable', | ||
params: { | ||
site: '123', | ||
}, | ||
}; | ||
|
||
const bidderRequest = { | ||
bidderRequestId: 'bid123', | ||
refererInfo: { | ||
domain: 'example.com', | ||
page: 'https://example.com/page', | ||
ref: 'https://referrer.com' | ||
}, | ||
}; | ||
|
||
it('should include site as tagid in imp', function() { | ||
const request = spec.buildRequests([validBid], bidderRequest); | ||
expect(request.url).to.equal('https://ads.optable.co/ca/ortb2/v1/ssp/bid'); | ||
expect(request.method).to.equal('POST'); | ||
expect(request.data.imp[0].tagid).to.equal('123') | ||
}); | ||
}); | ||
|
||
describe('interpretResponse', function() { | ||
const validBid = { | ||
bidder: 'optable', | ||
params: { | ||
site: '123', | ||
}, | ||
}; | ||
|
||
const bidderRequest = { | ||
bidderRequestId: 'bid123', | ||
refererInfo: { | ||
domain: 'example.com', | ||
page: 'https://example.com/page', | ||
ref: 'https://referrer.com' | ||
}, | ||
}; | ||
|
||
const response = { | ||
body: { | ||
ext: { | ||
optable: { | ||
fledge: { | ||
auctionconfigs: [ | ||
{ impid: 'bid123', seller: 'https://ads.optable.co' }, | ||
] | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
|
||
it('maps fledgeAuctionConfigs from ext.optable.fledge.auctionconfigs', function() { | ||
const request = spec.buildRequests([validBid], bidderRequest); | ||
const result = spec.interpretResponse(response, request); | ||
expect(result.fledgeAuctionConfigs).to.deep.equal([ | ||
{ bidId: 'bid123', config: { seller: 'https://ads.optable.co' } } | ||
]); | ||
}); | ||
}); | ||
}); |