-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
adbund adapter #932
Merged
Merged
adbund adapter #932
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
d45bf80
add adBund Adaptor
linrubo 990cbf8
更改正式接口地址
linrubo 7eb9e0c
change code style;add param(referrer,domain,ua)
linrubo 9a8f86d
add test in pbjs_example_gpt.html
linrubo 06ac318
Merge branch 'master' into master
adbundzheng 8035395
change code style
linrubo 6e2b6e5
Convert this comment to english;
linrubo 4de408c
Merge branch 'master' into master
adbundzheng 434163f
add unit tests
linrubo a5d241f
移除gpt示例中的sizes可选参数
linrubo b7cd4bd
tabs to spaces
linrubo 16e23e2
change unit tests
linrubo 4e9fdab
change unit tests
linrubo 95e40b3
change unit tests
linrubo 574aa2c
change unit tests
linrubo 73e3217
change unit tests
linrubo 22f2aad
change unit tests
linrubo a269e70
change unit tests
linrubo 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 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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
[ | ||
"aardvark", | ||
"adblade", | ||
"adbund", | ||
"adbutler", | ||
"adequant", | ||
"adform", | ||
|
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
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,66 @@ | ||
var CONSTANTS = require('../constants.json'); | ||
var utils = require('../utils.js'); | ||
var bidfactory = require('../bidfactory.js'); | ||
var bidmanager = require('../bidmanager.js'); | ||
var adloader = require('../adloader'); | ||
|
||
var adBundAdapter = function adBundAdapter() { | ||
var timezone = (new Date()).getTimezoneOffset(); | ||
var bidAPIs = [ | ||
'http://us-east-engine.adbund.xyz/prebid/ad/get', | ||
'http://us-west-engine.adbund.xyz/prebid/ad/get' | ||
]; | ||
//Based on the time zone to select the interface to the server | ||
var bidAPI = bidAPIs[timezone < 0 ? 0 : 1]; | ||
|
||
function _stringify(param) { | ||
var result = []; | ||
var key; | ||
for (key in param) { | ||
if (param.hasOwnProperty(key)) { | ||
result.push(key + '=' + encodeURIComponent(param[key])); | ||
} | ||
} | ||
return result.join('&'); | ||
} | ||
|
||
function _createCallback(bid) { | ||
return function (data) { | ||
var response; | ||
if (data && data.cpm) { | ||
response = bidfactory.createBid(CONSTANTS.STATUS.GOOD); | ||
response.bidderCode = 'adbund'; | ||
Object.assign(response, data); | ||
} else { | ||
response = bidfactory.createBid(CONSTANTS.STATUS.NO_BID); | ||
response.bidderCode = 'adbund'; | ||
} | ||
bidmanager.addBidResponse(bid.placementCode, response); | ||
}; | ||
} | ||
|
||
function _requestBids(bid) { | ||
var info = { | ||
referrer: utils.getTopWindowUrl(), | ||
domain: utils.getTopWindowLocation().hostname, | ||
ua: window.navigator.userAgent | ||
}; | ||
var param = Object.assign({}, bid.params, info); | ||
param.sizes = JSON.stringify(param.sizes || bid.sizes); | ||
param.callback = '$$PREBID_GLOBAL$$.adbundResponse'; | ||
$$PREBID_GLOBAL$$.adbundResponse = _createCallback(bid); | ||
adloader.loadScript(bidAPI + '?' + _stringify(param)); | ||
} | ||
|
||
function _callBids(params) { | ||
(params.bids || []).forEach(function (bid) { | ||
_requestBids(bid); | ||
}); | ||
} | ||
|
||
return { | ||
callBids: _callBids | ||
}; | ||
}; | ||
|
||
module.exports = adBundAdapter; |
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,96 @@ | ||
import { expect } from 'chai'; | ||
import Adapter from '../../../src/adapters/adbund'; | ||
import bidManager from 'src/bidmanager'; | ||
import CONSTANTS from 'src/constants.json'; | ||
|
||
describe('adbund adapter tests', function () { | ||
|
||
let sandbox; | ||
let adapter; | ||
let server; | ||
|
||
const request = { | ||
bidderCode: 'adbund', | ||
bids: [{ | ||
bidder: 'adbund', | ||
params: { | ||
sid: '110238', | ||
bidfloor: 0.036 | ||
}, | ||
placementCode: 'adbund', | ||
sizes: [[300, 250]], | ||
bidId: 'adbund_bidId', | ||
bidderRequestId: 'adbund_bidderRequestId', | ||
requestId: 'adbund_requestId' | ||
}] | ||
}; | ||
|
||
const response = { | ||
bidderCode: 'adbund', | ||
cpm: 1.06, | ||
height: 250, | ||
width: 300 | ||
}; | ||
|
||
beforeEach(() => { | ||
sandbox = sinon.sandbox.create(); | ||
}); | ||
|
||
afterEach(() => { | ||
sandbox.restore(); | ||
}); | ||
|
||
describe('adbund callBids validation', () => { | ||
|
||
beforeEach(() => { | ||
adapter = new Adapter(); | ||
}); | ||
|
||
afterEach(() => { | ||
}); | ||
|
||
it('Valid bid-request', () => { | ||
let bidderRequest; | ||
|
||
sandbox.stub(adapter, 'callBids'); | ||
adapter.callBids(request); | ||
|
||
bidderRequest = adapter.callBids.getCall(0).args[0]; | ||
|
||
expect(bidderRequest).to.have.property('bids') | ||
.that.is.an('array') | ||
.with.lengthOf(1); | ||
|
||
expect(bidderRequest).to.have.deep.property('bids[0]') | ||
.to.have.property('bidder', 'adbund'); | ||
|
||
expect(bidderRequest).to.have.deep.property('bids[0]') | ||
.with.property('sizes') | ||
.that.is.an('array') | ||
.with.lengthOf(1) | ||
.that.deep.equals(request.bids[0].sizes); | ||
|
||
expect(bidderRequest).to.have.deep.property('bids[0]') | ||
.with.property('params') | ||
.to.have.property('bidfloor', 0.036); | ||
}); | ||
|
||
it('Valid bid-response', () => { | ||
var bidderResponse; | ||
|
||
sandbox.stub(bidManager, 'addBidResponse'); | ||
adapter.callBids(request); | ||
bidderResponse = bidManager.addBidResponse.getCall(0) || | ||
bidManager.addBidResponse.getCall(1); | ||
|
||
if (bidderResponse && bidderResponse.args && bidderResponse.args[1]) { | ||
bidderResponse = bidderResponse.args[1]; | ||
expect(bidderResponse.getStatusCode()).to.equal(CONSTANTS.STATUS.GOOD); | ||
expect(bidderResponse.bidderCode).to.equal(response.bidderCode); | ||
expect(bidderResponse.width).to.equal(response.width); | ||
expect(bidderResponse.height).to.equal(response.height); | ||
expect(bidderResponse.cpm).to.equal(response.cpm); | ||
} | ||
}); | ||
}); | ||
}); |
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.
I am getting bid back for size [[300,250]] but not for [300,250]. Please add support for the same.
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.
Has been modified, please review again