From ab93aaade4142b15af33c3748ba0014bc0ade88c Mon Sep 17 00:00:00 2001 From: "takaaki.kojima" Date: Fri, 5 Oct 2018 16:38:58 +0900 Subject: [PATCH] update AdGeneration adapter --- modules/adgenerationBidAdapter.js | 40 ++++++++++++++++++- modules/adgenerationBidAdapter.md | 1 + .../modules/adgenerationBidAdapter_spec.js | 15 ++++--- 3 files changed, 46 insertions(+), 10 deletions(-) diff --git a/modules/adgenerationBidAdapter.js b/modules/adgenerationBidAdapter.js index 1753446fc67..faffae63edb 100644 --- a/modules/adgenerationBidAdapter.js +++ b/modules/adgenerationBidAdapter.js @@ -1,5 +1,4 @@ import * as utils from 'src/utils'; -// import {config} from 'src/config'; import {registerBidder} from 'src/adapters/bidderFactory'; import {BANNER, NATIVE} from 'src/mediaTypes'; const ADG_BIDDER_CODE = 'adgeneration'; @@ -15,7 +14,7 @@ export const spec = { * @return boolean True if this is a valid bid, and false otherwise. */ isBidRequestValid: function (bid) { - return !!(bid.params.id); + return !!(bid.params.id) && (isValidCurrency(bid.params.currency)); }, /** * Make a server request from the list of BidRequests. @@ -24,6 +23,7 @@ export const spec = { * @return ServerRequest Info describing the request to the server. */ buildRequests: function (validBidRequests) { + const ADGENE_PREBID_VERSION = '1.0.1'; let serverRequests = []; for (let i = 0, len = validBidRequests.length; i < len; i++) { const validReq = validBidRequests[i]; @@ -38,6 +38,12 @@ export const spec = { data = utils.tryAppendQueryString(data, 'hb', 'true'); data = utils.tryAppendQueryString(data, 't', 'json3'); data = utils.tryAppendQueryString(data, 'transactionid', validReq.transactionId); + data = utils.tryAppendQueryString(data, 'sizes', getSizes(validReq)); + data = utils.tryAppendQueryString(data, 'currency', validReq.params.currency.toUpperCase()); + data = utils.tryAppendQueryString(data, 'pbver', '$prebid.version$'); + data = utils.tryAppendQueryString(data, 'sdkname', 'prebidjs'); + data = utils.tryAppendQueryString(data, 'adapterver', ADGENE_PREBID_VERSION); + data = utils.tryAppendQueryString(data, 'tp', utils.getTopWindowUrl()); // native以外にvideo等の対応が入った場合は要修正 if (!validReq.mediaTypes || !validReq.mediaTypes.native) { @@ -198,4 +204,34 @@ function removeWrapper(ad) { return ad.substr(bodyIndex, lastBodyIndex).replace('', '').replace('', ''); } +/** + * request + * @param validReq request + * @returns {?string} 300x250,320x50... + */ +function getSizes(validReq) { + const sizes = validReq.sizes; + if (!sizes || sizes.length < 1) return null; + let sizesStr = null; + for (const i in sizes) { + const size = sizes[i]; + if (sizesStr == null) { + sizesStr = size[0] + 'x' + size[1]; + } else { + sizesStr += ',' + size[0] + 'x' + size[1]; + } + } + return sizesStr; +} + +/** + * @param {?string} currency + * @return {!boolean} + */ +function isValidCurrency(currency) { + if (!currency) return false; + const upperCurrency = currency.toUpperCase(); + return (upperCurrency === 'JPY' || upperCurrency === 'USD') +} + registerBidder(spec); diff --git a/modules/adgenerationBidAdapter.md b/modules/adgenerationBidAdapter.md index 7d8281be9b2..4a475d4d1ba 100644 --- a/modules/adgenerationBidAdapter.md +++ b/modules/adgenerationBidAdapter.md @@ -24,6 +24,7 @@ var adUnits = [ bidder: 'adg', params: { id: '58278', // banner + currency: 'JPY', } }, ] diff --git a/test/spec/modules/adgenerationBidAdapter_spec.js b/test/spec/modules/adgenerationBidAdapter_spec.js index 558303ccecb..fc24eda60a7 100644 --- a/test/spec/modules/adgenerationBidAdapter_spec.js +++ b/test/spec/modules/adgenerationBidAdapter_spec.js @@ -15,10 +15,11 @@ describe('AdgenerationAdapter', function () { }); describe('isBidRequestValid', function () { - let bid = { + const bid = { 'bidder': 'adg', 'params': { id: '58278', // banner + currency: 'JPY', } }; it('should return true when required params found', function () { @@ -39,11 +40,10 @@ describe('AdgenerationAdapter', function () { bidder: 'adg', params: { id: '58278', - width: '300', - height: '250' + currency: 'JPY', }, adUnitCode: 'adunit-code', - sizes: [[300, 250]], + sizes: [[300, 250], [320, 100]], bidId: '2f6ac468a9c15e', bidderRequestId: '14a9f773e30243', auctionId: '4aae9f05-18c6-4fcd-80cf-282708cd584a', @@ -53,8 +53,7 @@ describe('AdgenerationAdapter', function () { bidder: 'adg', params: { id: '58278', - width: '300', - height: '250' + currency: 'JPY', }, mediaTypes: { native: { @@ -88,8 +87,8 @@ describe('AdgenerationAdapter', function () { } ]; const data = { - banner: 'posall=SSPLOC&id=58278&sdktype=0&hb=true&t=json3&imark=1', - native: 'posall=SSPLOC&id=58278&sdktype=0&hb=true&t=json3' + banner: `posall=SSPLOC&id=58278&sdktype=0&hb=true&t=json3&sizes=300x250%2C320x100¤cy=JPY&pbver=%24prebid.version%24&sdkname=prebidjs&adapterver=1.0.1&tp=http%3A%2F%2Flocalhost%3A9876%2F&imark=1`, + native: 'posall=SSPLOC&id=58278&sdktype=0&hb=true&t=json3&sizes=1x1¤cy=JPY&pbver=%24prebid.version%24&sdkname=prebidjs&adapterver=1.0.1&tp=http%3A%2F%2Flocalhost%3A9876%2F' }; it('sends bid request to ENDPOINT via GET', function () { const request = spec.buildRequests(bidRequests)[0];