-
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.
[NEW Adapter] RTBHouseBidAdapter (#2184)
* [NEW Adapter] RTBHouseBidAdapter * remove trailing space in a comment
- Loading branch information
1 parent
37ead27
commit 324d530
Showing
3 changed files
with
277 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,117 @@ | ||
import * as utils from 'src/utils'; | ||
import { BANNER } from 'src/mediaTypes'; | ||
import { registerBidder } from 'src/adapters/bidderFactory'; | ||
|
||
const BIDDER_CODE = 'rtbhouse'; | ||
const REGIONS = ['prebid-eu', 'prebid-us', 'prebid-asia']; | ||
const ENDPOINT_URL = 'creativecdn.com/bidder/prebid/bids'; | ||
const DEFAULT_CURRENCY_ARR = ['USD']; // NOTE - USD is the only supported currency right now; Hardcoded for bids | ||
|
||
/** | ||
* Helpers | ||
*/ | ||
|
||
function buildEndpointUrl(region) { | ||
return 'https://' + region + '.' + ENDPOINT_URL; | ||
} | ||
|
||
/** | ||
* Produces an OpenRTBImpression from a slot config. | ||
*/ | ||
function mapImpression(slot) { | ||
return { | ||
id: slot.bidId, | ||
banner: mapBanner(slot), | ||
tagid: slot.adUnitCode.toString(), | ||
}; | ||
} | ||
|
||
/** | ||
* Produces an OpenRTB Banner object for the slot given. | ||
*/ | ||
function mapBanner(slot) { | ||
return { | ||
w: slot.sizes[0][0], | ||
h: slot.sizes[0][1], | ||
format: mapSizes(slot.sizes) | ||
}; | ||
} | ||
|
||
/** | ||
* Produce openRTB banner.format object | ||
*/ | ||
function mapSizes(slot_sizes) { | ||
const format = []; | ||
slot_sizes.forEach(elem => { | ||
format.push({ | ||
w: elem[0], | ||
h: elem[1] | ||
}); | ||
}); | ||
return format; | ||
} | ||
|
||
/** | ||
* Produces an OpenRTB site object. | ||
*/ | ||
function mapSite(validRequest) { | ||
const pubId = validRequest && validRequest.length > 0 ? validRequest[0].params.publisherId : 'unknown'; | ||
return { | ||
publisher: { | ||
id: pubId.toString(), | ||
}, | ||
page: utils.getTopWindowUrl(), | ||
name: utils.getOrigin() | ||
} | ||
} | ||
|
||
export const spec = { | ||
code: BIDDER_CODE, | ||
supportedMediaTypes: [BANNER], | ||
|
||
isBidRequestValid: function (bid) { | ||
return !!(REGIONS.includes(bid.params.region) && bid.params.publisherId); | ||
}, | ||
|
||
buildRequests: function (validBidRequests) { | ||
const request = { | ||
id: validBidRequests[0].auctionId, | ||
imp: validBidRequests.map(slot => mapImpression(slot)), | ||
site: mapSite(validBidRequests), | ||
cur: DEFAULT_CURRENCY_ARR, | ||
test: validBidRequests[0].params.test || 0 | ||
}; | ||
return { | ||
method: 'POST', | ||
url: buildEndpointUrl(validBidRequests[0].params.region), | ||
data: JSON.stringify(request) | ||
}; | ||
}, | ||
interpretResponse: function (serverResponse, originalRequest) { | ||
serverResponse = serverResponse.body; | ||
const bids = []; | ||
|
||
if (utils.isArray(serverResponse)) { | ||
serverResponse.forEach(serverBid => { | ||
if (serverBid.price !== 0) { | ||
const bid = { | ||
requestId: serverBid.impid, | ||
mediaType: BANNER, | ||
cpm: serverBid.price, | ||
creativeId: serverBid.adid, | ||
ad: serverBid.adm, | ||
width: serverBid.w, | ||
height: serverBid.h, | ||
ttl: 55, | ||
netRevenue: true, | ||
currency: 'USD' | ||
}; | ||
bids.push(bid); | ||
} | ||
}); | ||
} | ||
return bids; | ||
} | ||
}; | ||
|
||
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,31 @@ | ||
# Overview | ||
|
||
Module Name: RTB House Bidder Adapter | ||
Module Type: Bidder Adapter | ||
Maintainer: prebid@rtbhouse.com | ||
|
||
# Description | ||
|
||
Connects to RTB House unique demand. | ||
Banner formats are supported. | ||
Unique publisherId is required. | ||
Please reach out to pmp@rtbhouse.com to receive your own | ||
|
||
# Test Parameters | ||
``` | ||
var adUnits = [ | ||
{ | ||
code: 'test-div', | ||
sizes: [[300, 250]], | ||
bids: [ | ||
{ | ||
bidder: "rtbhouse", | ||
params: { | ||
region: 'prebid-eu', | ||
publisherId: 'PREBID_TEST_ID' | ||
} | ||
} | ||
] | ||
} | ||
]; | ||
``` |
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,129 @@ | ||
import { expect } from 'chai'; | ||
import { spec } from 'modules/rtbhouseBidAdapter'; | ||
import { newBidder } from 'src/adapters/bidderFactory'; | ||
|
||
const REGIONS = ['prebid-eu', 'prebid-us', 'prebid-asia']; | ||
const ENDPOINT_URL = 'creativecdn.com/bidder/prebid/bids'; | ||
|
||
/** | ||
* Helpers | ||
*/ | ||
|
||
function buildEndpointUrl(region) { | ||
return 'https://' + region + '.' + ENDPOINT_URL; | ||
} | ||
|
||
/** | ||
* endof Helpers | ||
*/ | ||
|
||
describe('RTBHouseAdapter', () => { | ||
const adapter = newBidder(spec); | ||
|
||
describe('inherited functions', () => { | ||
it('exists and is a function', () => { | ||
expect(adapter.callBids).to.exist.and.to.be.a('function'); | ||
}); | ||
}); | ||
|
||
describe('isBidRequestValid', () => { | ||
let bid = { | ||
'bidder': 'rtbhouse', | ||
'params': { | ||
'publisherId': 'PREBID_TEST', | ||
'region': 'prebid-eu' | ||
}, | ||
'adUnitCode': 'adunit-code', | ||
'sizes': [[300, 250], [300, 600]], | ||
'bidId': '30b31c1838de1e', | ||
'bidderRequestId': '22edbae2733bf6', | ||
'auctionId': '1d1a030790a475' | ||
}; | ||
|
||
it('should return true when required params found', () => { | ||
expect(spec.isBidRequestValid(bid)).to.equal(true); | ||
}); | ||
|
||
it('should return false when required params are not passed', () => { | ||
let bid = Object.assign({}, bid); | ||
delete bid.params; | ||
bid.params = { | ||
'someIncorrectParam': 0 | ||
}; | ||
expect(spec.isBidRequestValid(bid)).to.equal(false); | ||
}); | ||
}); | ||
|
||
describe('buildRequests', () => { | ||
let bidRequests = [ | ||
{ | ||
'bidder': 'rtbhouse', | ||
'params': { | ||
'publisherId': 'PREBID_TEST', | ||
'region': 'prebid-eu', | ||
'test': 1 | ||
}, | ||
'adUnitCode': 'adunit-code', | ||
'sizes': [[300, 250], [300, 600]], | ||
'bidId': '30b31c1838de1e', | ||
'bidderRequestId': '22edbae2733bf6', | ||
'auctionId': '1d1a030790a475' | ||
} | ||
]; | ||
|
||
it('should build test param into the request', () => { | ||
let builtTestRequest = spec.buildRequests(bidRequests).data; | ||
expect(JSON.parse(builtTestRequest).test).to.equal(1); | ||
}); | ||
|
||
it('sends bid request to ENDPOINT via POST', () => { | ||
let bidRequest = Object.assign([], bidRequests); | ||
delete bidRequest[0].params.test; | ||
|
||
const request = spec.buildRequests(bidRequest); | ||
expect(request.url).to.equal(buildEndpointUrl(bidRequest[0].params.region)); | ||
expect(request.method).to.equal('POST'); | ||
}); | ||
}) | ||
|
||
describe('interpretResponse', () => { | ||
let response = [{ | ||
'id': 'bidder_imp_identifier', | ||
'impid': '552b8922e28f27', | ||
'price': 0.5, | ||
'adid': 'Ad_Identifier', | ||
'adm': '<!-- test creative -->', | ||
'adomain': ['rtbhouse.com'], | ||
'cid': 'Ad_Identifier', | ||
'w': 300, | ||
'h': 250 | ||
}]; | ||
|
||
it('should get correct bid response', () => { | ||
let expectedResponse = [ | ||
{ | ||
'requestId': '552b8922e28f27', | ||
'cpm': 0.5, | ||
'creativeId': 29681110, | ||
'width': 300, | ||
'height': 250, | ||
'ad': '<!-- test creative -->', | ||
'mediaType': 'banner', | ||
'currency': 'USD', | ||
'ttl': 300, | ||
'netRevenue': true | ||
} | ||
]; | ||
let bidderRequest; | ||
let result = spec.interpretResponse({ body: response }, {bidderRequest}); | ||
expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0])); | ||
}); | ||
|
||
it('handles nobid responses', () => { | ||
let response = ''; | ||
let bidderRequest; | ||
let result = spec.interpretResponse({ body: response }, {bidderRequest}); | ||
expect(result.length).to.equal(0); | ||
}); | ||
}); | ||
}); |