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

Multiple sizes handling in adYouLike adaptor #4013

Merged
merged 11 commits into from
Aug 11, 2019
20 changes: 16 additions & 4 deletions modules/adyoulikeBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const spec = {
* @return boolean True if this is a valid bid, and false otherwise.
*/
isBidRequestValid: function (bid) {
const sizes = getSize(bid.sizes);
const sizes = getSize(getSizeArray(bid));
if (!bid.params || !bid.params.placement || !sizes.width || !sizes.height) {
return false;
}
Expand All @@ -34,12 +34,14 @@ export const spec = {
const payload = {
Version: VERSION,
Bids: bidRequests.reduce((accumulator, bid) => {
let size = getSize(bid.sizes);
let sizesArray = getSizeArray(bid);
let size = getSize(sizesArray);
accumulator[bid.bidId] = {};
accumulator[bid.bidId].PlacementID = bid.params.placement;
accumulator[bid.bidId].TransactionID = bid.transactionId;
accumulator[bid.bidId].Width = size.width;
accumulator[bid.bidId].Height = size.height;
accumulator[bid.bidId].AvaiableSizes = sizesArray.join(',');
return accumulator;
}, {}),
PageRefreshed: getPageRefreshed()
Expand Down Expand Up @@ -156,10 +158,20 @@ function createEndpointQS(bidderRequest) {
return qs;
}

function getSizeArray(bid) {
let inputSize = bid.sizes;
if (bid.mediaTypes && bid.mediaTypes.banner) {
inputSize = bid.mediaTypes.banner.sizes;
}

return utils.parseSizesInput(inputSize);
}

/* Get parsed size from request size */
function getSize(requestSizes) {
function getSize(sizesArray) {
const parsed = {};
const size = utils.parseSizesInput(requestSizes)[0];
// the main requested size is the first one
const size = sizesArray[0];

if (typeof size !== 'string') {
return parsed;
Expand Down