-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Upgrade Admixer adapter for Prebid 1.0 #1755
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,74 @@ | ||
import * as utils from 'src/utils'; | ||
import {registerBidder} from 'src/adapters/bidderFactory'; | ||
|
||
const BIDDER_CODE = 'admixer'; | ||
const ENDPOINT_URL = '//inv-nets.admixer.net/prebid.1.0.aspx'; | ||
export const spec = { | ||
code: BIDDER_CODE, | ||
aliases: [], | ||
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.zone; | ||
}, | ||
/** | ||
* Make a server request from the list of BidRequests. | ||
* | ||
* @param {bidderRequest} - bidderRequest.bids[] is an array of AdUnits and bids | ||
* @return ServerRequest Info describing the request to the server. | ||
*/ | ||
buildRequests: function (bidderRequest) { | ||
const payload = { | ||
imps: [], | ||
referrer: utils.getTopWindowUrl(), | ||
}; | ||
bidderRequest.forEach((bid) => { | ||
if (bid.bidder === BIDDER_CODE) { | ||
payload.imps.push(bid); | ||
} | ||
}); | ||
const payloadString = JSON.stringify(payload); | ||
return { | ||
method: 'GET', | ||
url: ENDPOINT_URL, | ||
data: `data=${payloadString}`, | ||
}; | ||
}, | ||
/** | ||
* Unpack the response from the server into a list of bids. | ||
* | ||
* @param {*} serverResponse A successful response from the server. | ||
* @return {Bid[]} An array of bids which were nested inside the server. | ||
*/ | ||
interpretResponse: function (serverResponse, bidRequest) { | ||
const bidResponses = []; | ||
// loop through serverResponses { | ||
try { | ||
serverResponse = serverResponse.body; | ||
serverResponse.forEach((bidResponse) => { | ||
const bidResp = { | ||
requestId: bidResponse.bidId, | ||
cpm: bidResponse.cpm, | ||
width: bidResponse.width, | ||
height: bidResponse.height, | ||
ad: bidResponse.ad, | ||
ttl: bidResponse.ttl, | ||
creativeId: bidResponse.creativeId, | ||
netRevenue: bidResponse.netRevenue, | ||
currency: bidResponse.currency, | ||
vastUrl: bidResponse.vastUrl, | ||
}; | ||
bidResponses.push(bidResp); | ||
}); | ||
} catch (e) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any errors that are caught during this part should be logged. They can be passed to the utils.logError() method. |
||
utils.logError(e); | ||
} | ||
return bidResponses; | ||
} | ||
}; | ||
registerBidder(spec); |
This file contains hidden or 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,52 @@ | ||
# Overview | ||
|
||
Module Name: Admixer Bidder Adapter | ||
Module Type: Bidder Adapter | ||
Maintainer: [email protected] | ||
|
||
# Description | ||
|
||
Connects to Admixer demand source to fetch bids. | ||
Banner and Video formats are supported. | ||
Please use ```admixer``` as the bidder code. | ||
|
||
# Test Parameters | ||
``` | ||
var adUnits = [ | ||
{ | ||
code: 'desktop-banner-ad-div', | ||
sizes: [[300, 250]], // a display size | ||
bids: [ | ||
{ | ||
bidder: "admixer", | ||
params: { | ||
zone: '2eb6bd58-865c-47ce-af7f-a918108c3fd2' | ||
} | ||
} | ||
] | ||
},{ | ||
code: 'mobile-banner-ad-div', | ||
sizes: [[300, 50]], // a mobile size | ||
bids: [ | ||
{ | ||
bidder: "admixer", | ||
params: { | ||
zone: '62211486-c50b-4356-9f0f-411778d31fcc' | ||
} | ||
} | ||
] | ||
},{ | ||
code: 'video-ad', | ||
sizes: [[300, 50]], | ||
mediaType: 'video', | ||
bids: [ | ||
{ | ||
bidder: "admixer", | ||
params: { | ||
zone: 'ebeb1e79-8cb4-4473-b2d0-2e24b7ff47fd' | ||
} | ||
} | ||
] | ||
}, | ||
]; | ||
``` |
This file contains hidden or 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 {expect} from 'chai'; | ||
import {spec} from 'modules/admixerBidAdapter'; | ||
import {newBidder} from 'src/adapters/bidderFactory'; | ||
|
||
const BIDDER_CODE = 'admixer'; | ||
const ENDPOINT_URL = '//inv-nets.admixer.net/prebid.1.0.aspx'; | ||
const ZONE_ID = '2eb6bd58-865c-47ce-af7f-a918108c3fd2'; | ||
|
||
describe('AdmixerAdapter', () => { | ||
const adapter = newBidder(spec); | ||
|
||
describe('inherited functions', () => { | ||
it('exists and is a function', () => { | ||
expect(adapter.callBids).to.be.exist.and.to.be.a('function'); | ||
}); | ||
}); | ||
|
||
describe('isBidRequestValid', () => { | ||
let bid = { | ||
'bidder': BIDDER_CODE, | ||
'params': { | ||
'zone': ZONE_ID | ||
}, | ||
'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 = { | ||
'placementId': 0 | ||
}; | ||
expect(spec.isBidRequestValid(bid)).to.equal(false); | ||
}); | ||
}); | ||
|
||
describe('buildRequests', () => { | ||
let bidRequests = [ | ||
{ | ||
'bidder': BIDDER_CODE, | ||
'params': { | ||
'zone': ZONE_ID | ||
}, | ||
'adUnitCode': 'adunit-code', | ||
'sizes': [[300, 250], [300, 600]], | ||
'bidId': '30b31c1838de1e', | ||
'bidderRequestId': '22edbae2733bf6', | ||
'auctionId': '1d1a030790a475', | ||
} | ||
]; | ||
|
||
it('should add referrer and imp to be equal bidRequest', () => { | ||
const request = spec.buildRequests(bidRequests); | ||
const payload = JSON.parse(request.data.substr(5)); | ||
expect(payload.referrer).to.not.be.undefined; | ||
expect(payload.imps[0]).to.deep.equal(bidRequests[0]); | ||
}); | ||
|
||
it('sends bid request to ENDPOINT via GET', () => { | ||
const request = spec.buildRequests(bidRequests); | ||
expect(request.url).to.equal(ENDPOINT_URL); | ||
expect(request.method).to.equal('GET'); | ||
}); | ||
}); | ||
|
||
describe('interpretResponse', () => { | ||
let response = { | ||
body: [{ | ||
'currency': 'USD', | ||
'cpm': 6.210000, | ||
'ad': '<div>ad</div>', | ||
'width': 300, | ||
'height': 600, | ||
'creativeId': 'ccca3e5e-0c54-4761-9667-771322fbdffc', | ||
'ttl': 360, | ||
'netRevenue': false, | ||
'bidId': '5e4e763b6bc60b' | ||
}] | ||
}; | ||
|
||
it('should get correct bid response', () => { | ||
const body = response.body; | ||
let expectedResponse = [ | ||
{ | ||
'requestId': body[0].bidId, | ||
'cpm': body[0].cpm, | ||
'creativeId': body[0].creativeId, | ||
'width': body[0].width, | ||
'height': body[0].height, | ||
'ad': body[0].ad, | ||
'vastUrl': undefined, | ||
'currency': body[0].currency, | ||
'netRevenue': body[0].netRevenue, | ||
'ttl': body[0].ttl, | ||
} | ||
]; | ||
|
||
let result = spec.interpretResponse(response); | ||
expect(result[0]).to.deep.equal(expectedResponse[0]); | ||
}); | ||
|
||
it('handles nobid responses', () => { | ||
let response = []; | ||
|
||
let result = spec.interpretResponse(response); | ||
expect(result.length).to.equal(0); | ||
}); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#1748 changed the first argument of
interpretResponse
to:so adding something like
serverResponse = serverResponse.body;
just below this line, or however you'd prefer to grab the body, and updating corresponding tests if needed should get this back to working properly