Skip to content

Commit

Permalink
Remove placement size selection and filtering (#1107)
Browse files Browse the repository at this point in the history
Size selection moved to server side.

Changed API parameters accordingly:
`selectedSize` will simply be the first size in the sizes array
`placementSizes` -> `additionalSizes` and includes sizes besides the first one

Removed adapter parameters:
- allowedSize
- sizeTolerance
  • Loading branch information
ronenst authored and Matt Kendall committed Apr 18, 2017
1 parent f4db964 commit 2a45a16
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 279 deletions.
125 changes: 17 additions & 108 deletions src/adapters/hiromedia.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*jslint white:true, browser:true*/
/*jslint white:true, browser:true, single: true*/
/*global $$PREBID_GLOBAL$$, require, module*/

/**
Expand Down Expand Up @@ -38,7 +38,7 @@ var HiroMediaAdapter = function HiroMediaAdapter() {
* @constant {number}
* @private
*/
var ADAPTER_VERSION = 2;
var ADAPTER_VERSION = 3;

/**
* Default bid param values
Expand All @@ -57,9 +57,7 @@ var HiroMediaAdapter = function HiroMediaAdapter() {
* @private
*/
var DEFAULT_BID_PARAMS = {
bidUrl: 'https://hb-rtb.ktdpublishers.com/bid/get',
allowedSize: [300,250],
sizeTolerance: 5
bidUrl: 'https://hb-rtb.ktdpublishers.com/bid/get'
};

/**
Expand Down Expand Up @@ -98,8 +96,8 @@ var HiroMediaAdapter = function HiroMediaAdapter() {
if (bidResponse) {
bidObject.cpm = bidResponse.cpm;
bidObject.ad = bidResponse.ad;
bidObject.width = bidInfo.selectedSize[0];
bidObject.height = bidInfo.selectedSize[1];
bidObject.width = bidResponse.width;
bidObject.height = bidResponse.height;
}

utils.logMessage('hiromedia.callBids, addBidResponse for ' + placementCode + ' status: ' + bidStatus);
Expand Down Expand Up @@ -237,80 +235,6 @@ var HiroMediaAdapter = function HiroMediaAdapter() {

}

/**
* Convert a `string` to an integer with radix 10.
*
* @memberof module:HiroMediaAdapter~
* @private
*
* @param {string} value string to convert
* @return {number} the converted integer
*/
function parseInt10(value) {
return parseInt(value, 10);
}

/**
* Return `true` if a given value is in a certain range, `false` otherwise
*
* Returns `true` if the distance between `allowedValue` and `value`
* is smaller than the value of `tolerance`
*
* @memberof module:HiroMediaAdapter~
* @private
*
* @param {number} value the value to test
* @param {number} allowedValue the value to test against
* @param {number} tolerance tolerance value
* @return {Boolean} `true` if `dimension` is in range, `false` otherwise.
*/
function isValueInRange(value, allowedValue, tolerance) {

value = parseInt10(value);
allowedValue = parseInt10(allowedValue);
tolerance = parseInt10(tolerance);

return (allowedValue - tolerance) <= value && value <= (allowedValue + tolerance);

}

/**
* Returns `true` if a size array has both dimensions in range an allowed size array,
* `false` otherwise
*
* Each dimension of `size` will be checked against the corresponding dimension
* of `allowedSize`
*
* @memberof module:HiroMediaAdapter~
* @private
*
* @param {module:HiroMediaAdapter~size} size size array to test
* @param {module:HiroMediaAdapter~size} allowedSize size array to test against
* @param {number} tolerance tolerance value (same for both dimensions)
* @return {Boolean} `true` if the dimensions of `size` are in range of the
* dimensions of `allowedSize`, `false` otherwise.
*/
function isSizeInRange(size, allowedSize, tolerance) {
return isValueInRange(allowedSize[0], size[0], tolerance) && isValueInRange(allowedSize[1], size[1], tolerance);
}

/**
* Normalize sizes and return an array with sizes in WIDTHxHEIGHT format
*
* Simple wrapper around `util.parseSizesInput`
*
* @memberof module:HiroMediaAdapter~
* @private
*
* @param {array} sizes array of sizes that are passed to `util.parseSizesInput`
* @return {array} normalized array of sizes.
*/
function normalizeSizes(sizes) {
return utils.parseSizesInput(sizes).map(function (size) {
return size.split('x');
});
}

/**
* Apply default parameters to an object if the parameters are not set
*
Expand Down Expand Up @@ -344,7 +268,8 @@ var HiroMediaAdapter = function HiroMediaAdapter() {
var batchParams = [
bidParams.bidUrl,
bidParams.accountId,
bidInfo.selectedSize.join('x')
bidInfo.selectedSize,
bidInfo.additionalSizes
];

return batchParams.join('-');
Expand All @@ -355,10 +280,6 @@ var HiroMediaAdapter = function HiroMediaAdapter() {
* Build a set of {@linkcode module:HiroMediaAdapter~bidInfo|bidInfo} objects based on the
* bids sent to {@linkcode module:HiroMediaAdapter#callBids|callBids}
*
* This routine determines if a bid request should be sent for the placement, it
* will set `selectedSize` based on `params.allowedSize` and calculate the batch
* key.
*
* @memberof module:HiroMediaAdapter~
* @private
*
Expand All @@ -375,19 +296,16 @@ var HiroMediaAdapter = function HiroMediaAdapter() {

bids.forEach(function (bid) {

var sizes = normalizeSizes(bid.sizes);
var sizes = utils.parseSizesInput(bid.sizes);
var bidParams = defaultParams(bid.params);
var allowedSizes = normalizeSizes([bidParams.allowedSize])[0];
var selectedSize = sizes.find(function (size) {
return isSizeInRange(size, allowedSizes, bidParams.sizeTolerance);
});
var hasValidBidRequest = utils.hasValidBidRequest(bidParams, REQUIRED_BID_PARAMS, BIDDER_CODE);
var shouldBid = hasValidBidRequest && (selectedSize !== undefined);
var shouldBid = hasValidBidRequest;
var bidInfo = {
bid: bid,
bidParams: bidParams,
selectedSize: selectedSize,
shouldBid: shouldBid
shouldBid: shouldBid,
selectedSize: sizes[0],
additionalSizes: sizes.slice(1).join(',')
};

if (shouldBid) {
Expand Down Expand Up @@ -460,7 +378,7 @@ var HiroMediaAdapter = function HiroMediaAdapter() {
} else {

// Ensure we don't run on stale data
_bidStorage = [];
_bidStorage = [];

}

Expand Down Expand Up @@ -493,8 +411,8 @@ var HiroMediaAdapter = function HiroMediaAdapter() {
browser: browser.name,
browserVersion: browser.version,
domain: domain,
selectedSize: utils.parseSizesInput([bidInfo.selectedSize]),
placementSizes: utils.parseSizesInput(bid.sizes)
selectedSize: bidInfo.selectedSize,
additionalSizes: bidInfo.additionalSizes
});

}
Expand All @@ -519,23 +437,13 @@ var HiroMediaAdapter = function HiroMediaAdapter() {

// JSDoc typedefs

/**
* A size array where the width is the first array item and the height is
* the second array item.
*
* @typedef {array.<number>} module:HiroMediaAdapter~size
* @private
*/

/**
* Parameters for bids to HIRO Media adapter
*
* @typedef {object} module:HiroMediaAdapter~bidParams
* @private
*
* @property {string} bidUrl the bid server endpoint url
* @property {module:HiroMediaAdapter~size} allowedSize allowed placement size
* @property {number} sizeTolerance custom tolerance for `allowedSize`
*/

/**
Expand All @@ -545,7 +453,8 @@ var HiroMediaAdapter = function HiroMediaAdapter() {
* @private
*
* @property {object} bid original bid passed to #callBids
* @property {module:HiroMediaAdapter~size} selectedSize the selected size of the placement
* @property {string} selectedSize the first size in the the placement sizes array
* @property {string} additionalSizes list of sizes in the placement sizes array besides the first
* @property {string} batchKey key used for batching requests which have the same basic properties
* @property {module:HiroMediaAdapter~bidParams} bidParams original params passed for bid in #callBids
* @property {boolean} shouldBid flag to determine if the bid is valid for bidding or not
Expand Down
Loading

0 comments on commit 2a45a16

Please sign in to comment.