-
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
Add bid adapter for ablida #4256
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
dc629b2
Add ablida adapter
bokos 716abcf
Merge branch 'master' of github.com:bokos/Prebid.js
bokos 1129ddd
Merge branch 'master' of https://github.com/prebid/Prebid.js
bokos f8d1c2d
Merge branch 'master' of https://github.com/prebid/Prebid.js
bokos 3044d89
Merge branch 'master' of https://github.com/prebid/Prebid.js
bokos 3b40973
rename category parameter, add documentation
bokos 00afa9d
Merge branch 'master' of https://github.com/prebid/Prebid.js
bokos 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 |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import * as utils from '../src/utils'; | ||
import {config} from '../src/config'; | ||
import {registerBidder} from '../src/adapters/bidderFactory'; | ||
|
||
const BIDDER_CODE = 'ablida'; | ||
const ENDPOINT_URL = 'https://bidder.ablida.net/prebid'; | ||
|
||
export const spec = { | ||
code: BIDDER_CODE, | ||
|
||
/** | ||
* 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.placementId); | ||
}, | ||
|
||
/** | ||
* Make a server request from the list of BidRequests. | ||
* | ||
* @return Array Info describing the request to the server. | ||
* @param validBidRequests | ||
* @param bidderRequest | ||
*/ | ||
buildRequests: function (validBidRequests, bidderRequest) { | ||
if (validBidRequests.length === 0) { | ||
return []; | ||
} | ||
return validBidRequests.map(bidRequest => { | ||
const sizes = utils.parseSizesInput(bidRequest.sizes)[0]; | ||
const size = sizes.split('x'); | ||
const jaySupported = 'atob' in window && 'currentScript' in document; | ||
const device = getDevice(); | ||
const payload = { | ||
placementId: bidRequest.params.placementId, | ||
width: size[0], | ||
height: size[1], | ||
bidId: bidRequest.bidId, | ||
category: bidRequest.params.category, | ||
referer: bidderRequest.refererInfo.referer, | ||
jaySupported: jaySupported, | ||
device: device | ||
}; | ||
return { | ||
method: 'POST', | ||
url: ENDPOINT_URL, | ||
data: payload | ||
}; | ||
}); | ||
}, | ||
|
||
/** | ||
* Unpack the response from the server into a list of bids. | ||
* | ||
* @param {ServerResponse} serverResponse A successful response from the server. | ||
* @param bidRequest | ||
* @return {Bid[]} An array of bids which were nested inside the server. | ||
*/ | ||
interpretResponse: function (serverResponse, bidRequest) { | ||
const bidResponses = []; | ||
const response = serverResponse.body; | ||
|
||
response.forEach(function(bid) { | ||
bid.ttl = config.getConfig('_bidderTimeout'); | ||
bidResponses.push(bid); | ||
}); | ||
return bidResponses; | ||
}, | ||
}; | ||
|
||
function getDevice() { | ||
const ua = navigator.userAgent; | ||
const topWindow = window.top; | ||
if ((/(ipad|xoom|sch-i800|playbook|silk|tablet|kindle)|(android(?!.*mobi))/i).test(ua)) { | ||
return 'tablet'; | ||
} | ||
if ((/(smart[-]?tv|hbbtv|appletv|googletv|hdmi|netcast\.tv|viera|nettv|roku|\bdtv\b|sonydtv|inettvbrowser|\btv\b)/i).test(ua)) { | ||
return 'connectedtv'; | ||
} | ||
if ((/Mobile|iP(hone|od|ad)|Android|BlackBerry|IEMobile|Kindle|NetFront|Windows\sCE|Silk-Accelerated|(hpw|web)OS|Fennec|Minimo|Opera M(obi|ini)|Blazer|Dolfin|Dolphin|Skyfire|Zune/i).test(ua)) { | ||
return 'smartphone'; | ||
} | ||
const width = topWindow.innerWidth || topWindow.document.documentElement.clientWidth || topWindow.document.body.clientWidth; | ||
if (width > 320) { | ||
return 'desktop'; | ||
} | ||
return 'other'; | ||
} | ||
|
||
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**: Ablida Bidder Adapter | ||
**Module Type**: Bidder Adapter | ||
**Maintainer**: d.kuster@ablida.de | ||
|
||
# Description | ||
|
||
Module that connects to Ablida's bidder for bids. | ||
|
||
# Test Parameters | ||
``` | ||
var adUnits = [ | ||
{ | ||
code: 'ad-div', | ||
mediaTypes: { | ||
banner: { | ||
sizes: [[300, 250]], | ||
} | ||
}, | ||
bids: [ | ||
{ | ||
bidder: 'ablida', | ||
params: { | ||
placementId: 'mediumrectangle-demo' | ||
} | ||
} | ||
] | ||
} | ||
]; | ||
``` |
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,102 @@ | ||
import {assert, expect} from 'chai'; | ||
import {spec} from 'modules/ablidaBidAdapter'; | ||
import {newBidder} from 'src/adapters/bidderFactory'; | ||
|
||
const ENDPOINT_URL = 'https://bidder.ablida.net/prebid'; | ||
|
||
describe('ablidaBidAdapter', function () { | ||
const adapter = newBidder(spec); | ||
describe('isBidRequestValid', function () { | ||
let bid = { | ||
bidder: 'ablida', | ||
params: { | ||
placementId: 123 | ||
}, | ||
adUnitCode: 'adunit-code', | ||
sizes: [ | ||
[300, 250] | ||
], | ||
bidId: '1234asdf1234', | ||
bidderRequestId: '1234asdf1234asdf', | ||
auctionId: '69e8fef8-5105-4a99-b011-d5669f3bc7f0' | ||
}; | ||
it('should return true where required params found', function () { | ||
expect(spec.isBidRequestValid(bid)).to.equal(true); | ||
}); | ||
}); | ||
describe('buildRequests', function () { | ||
let bidRequests = [ | ||
{ | ||
bidder: 'ablida', | ||
params: { | ||
placementId: 123 | ||
}, | ||
sizes: [ | ||
[300, 250] | ||
], | ||
adUnitCode: 'adunit-code', | ||
bidId: '23beaa6af6cdde', | ||
bidderRequestId: '14d2939272a26a', | ||
auctionId: '69e8fef8-5105-4a99-b011-d5669f3bc7f0', | ||
} | ||
]; | ||
|
||
let bidderRequests = { | ||
refererInfo: { | ||
numIframes: 0, | ||
reachedTop: true, | ||
referer: 'http://example.com', | ||
stack: ['http://example.com'] | ||
} | ||
}; | ||
|
||
const request = spec.buildRequests(bidRequests, bidderRequests); | ||
it('sends bid request via POST', function () { | ||
expect(request[0].method).to.equal('POST'); | ||
}); | ||
}); | ||
|
||
describe('interpretResponse', function () { | ||
let bidRequest = { | ||
method: 'POST', | ||
url: ENDPOINT_URL, | ||
data: { | ||
placementId: 'testPlacementId', | ||
width: 300, | ||
height: 200, | ||
bidId: '2b8c4de0116e54', | ||
jaySupported: true, | ||
device: 'desktop', | ||
referer: 'www.example.com' | ||
} | ||
}; | ||
let serverResponse = { | ||
body: [{ | ||
requestId: '2b8c4de0116e54', | ||
cpm: 1.00, | ||
width: 300, | ||
height: 250, | ||
creativeId: '2b8c4de0116e54', | ||
currency: 'EUR', | ||
netRevenue: true, | ||
ttl: 3000, | ||
ad: '<script>console.log("ad");</script>' | ||
}] | ||
}; | ||
it('should get the correct bid response', function () { | ||
let expectedResponse = [{ | ||
requestId: '2b8c4de0116e54', | ||
cpm: 1.00, | ||
width: 300, | ||
height: 250, | ||
creativeId: '2b8c4de0116e54', | ||
currency: 'EUR', | ||
netRevenue: true, | ||
ttl: 3000, | ||
ad: '<script>console.log("ad");</script>' | ||
}]; | ||
let result = spec.interpretResponse(serverResponse, bidRequest[0]); | ||
expect(Object.keys(result)).to.deep.equal(Object.keys(expectedResponse)); | ||
}); | ||
}); | ||
}); |
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.
Is this one of the potential params that could be specified in the bidder params? If so, can you please document this in your md file (and docs PR if needed)?
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.
Thanks, I changed that parameter a little and added documentation in the md and docs PR.