Skip to content
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 feature to bridgewellBidAdapter #2444

Merged
merged 2 commits into from
Apr 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 42 additions & 18 deletions modules/bridgewellBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {registerBidder} from 'src/adapters/bidderFactory';
import find from 'core-js/library/fn/array/find';

const BIDDER_CODE = 'bridgewell';
const REQUEST_ENDPOINT = '//rec.scupio.com/recweb/prebid.aspx';
const REQUEST_ENDPOINT = '//rec.scupio.com/recweb/prebid.aspx?cb=' + Math.random();

export const spec = {
code: BIDDER_CODE,
Expand Down Expand Up @@ -43,17 +43,23 @@ export const spec = {
* @return ServerRequest Info describing the request to the server.
*/
buildRequests: function(validBidRequests) {
const channelIDs = [];

const adUnits = [];
utils._each(validBidRequests, function(bid) {
channelIDs.push(bid.params.ChannelID);
adUnits.push({
ChannelID: bid.params.ChannelID,
mediaTypes: bid.mediaTypes || {
banner: {
sizes: bid.sizes
}
}
});
});

return {
method: 'GET',
method: 'POST',
url: REQUEST_ENDPOINT,
data: {
'ChannelID': channelIDs.join(',')
adUnits: adUnits
},
validBidRequests: validBidRequests
};
Expand All @@ -77,15 +83,35 @@ export const spec = {
return;
}

const anotherFormatSize = []; // for store width and height
let matchedResponse = find(serverResponse.body, function(res) {
return !!res && !res.consumed && find(req.sizes, function(size) {
let width = res.width;
let height = res.height;
if (typeof size === 'number') anotherFormatSize.push(size); // if sizes format is Array[Number], push width and height into anotherFormatSize
return (width === size[0] && height === size[1]) || // for format Array[Array[Number]] check
(width === anotherFormatSize[0] && height === anotherFormatSize[1]); // for foramt Array[Number] check
});
let valid = false;

if (!!res && !res.consumed) { // response exists and not consumed
if (res.width && res.height) {
let mediaTypes = req.mediaTypes;
// for prebid 1.0 and later usage, mediaTypes.banner.sizes
let sizes = mediaTypes && mediaTypes.banner && mediaTypes.banner.sizes ? mediaTypes.banner.sizes : req.sizes;
if (sizes) {
let sizeValid;
let width = res.width;
let height = res.height;
// check response size validation
if (typeof sizes[0] === 'number') { // for foramt Array[Number] check
sizeValid = width === sizes[0] && height === sizes[1];
} else { // for format Array[Array[Number]] check
sizeValid = find(sizes, function(size) {
return (width === size[0] && height === size[1]);
});
}

if (sizeValid) { // dont care native sizes
valid = true;
}
}
}
}

return valid;
});

if (matchedResponse) {
Expand All @@ -94,11 +120,9 @@ export const spec = {
// check required parameters
if (typeof matchedResponse.cpm !== 'number') {
return;
} else if (typeof matchedResponse.width !== 'number' || typeof matchedResponse.height !== 'number') {
return;
} else if (typeof matchedResponse.ad !== 'string') {
return;
} else if (typeof matchedResponse.net_revenue === 'undefined') {
} else if (typeof matchedResponse.netRevenue !== 'boolean') {
return;
} else if (typeof matchedResponse.currency !== 'string') {
return;
Expand All @@ -111,7 +135,7 @@ export const spec = {
bidResponse.ad = matchedResponse.ad;
bidResponse.ttl = matchedResponse.ttl;
bidResponse.creativeId = matchedResponse.id;
bidResponse.netRevenue = matchedResponse.net_revenue === 'true';
bidResponse.netRevenue = matchedResponse.netRevenue;
bidResponse.currency = matchedResponse.currency;

bidResponses.push(bidResponse);
Expand Down
83 changes: 46 additions & 37 deletions modules/bridgewellBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,50 @@ Module that connects to Bridgewell demand source to fetch bids.

# Test Parameters
```
var adUnits = [
{
code: 'test-div',
sizes: [[300, 250]],
bids: [
{
bidder: 'bridgewell',
params: {
ChannelID: 'CgUxMjMzOBIBNiIFcGVubnkqCQisAhD6ARoBOQ'
}
}
]
},{
code: 'test-div',
sizes: [[728, 90]],
bids: [
{
bidder: 'bridgewell',
params: {
ChannelID: 'CgUxMjMzOBIBNiIGcGVubnkzKggI2AUQWhoBOQ',
cpmWeight: 1.5
}
}
]
},{
code: 'test-div',
sizes: [728, 90],
bids: [
{
bidder: 'bridgewell',
params: {
ChannelID: 'CgUxMjMzOBIBNiIGcGVubnkzKggI2AUQWhoBOQ'
}
}
]
}
];
var adUnits = [{
code: 'test-div',
sizes: [
[300, 250]
],
bids: [{
bidder: 'bridgewell',
params: {
ChannelID: 'CgUxMjMzOBIBNiIFcGVubnkqCQisAhD6ARoBOQ'
}
}]
}, {
code: 'test-div',
sizes: [
[728, 90]
],
bids: [{
bidder: 'bridgewell',
params: {
ChannelID: 'CgUxMjMzOBIBNiIGcGVubnkzKggI2AUQWhoBOQ',
cpmWeight: 1.5
}
}]
}, {
code: 'test-div',
sizes: [728, 90],
bids: [{
bidder: 'bridgewell',
params: {
ChannelID: 'CgUxMjMzOBIBNiIGcGVubnkzKggI2AUQWhoBOQ'
}
}]
}, {
code: 'test-div',
mediaTypes: {
banner: {
sizes: [728, 90]
}
},
bids: [{
bidder: 'bridgewell',
params: {
ChannelID: 'CgUxMjMzOBIBNiIGcGVubnkzKggI2AUQWhoBOQ'
}
}]
}];
```
Loading