From 1153404df229d5553f10e698d72428a192073b9f Mon Sep 17 00:00:00 2001 From: Carlos Date: Tue, 30 Apr 2019 12:40:09 +0200 Subject: [PATCH 1/2] Files name updated --- modules/richAudienceBidAdapter.js | 140 ------------------ modules/richaudienceBidAdapter.js | 0 ...idAdapter.md => richaudienceBidAdapter.md} | 0 ...spec.js => richaudienceBidAdapter_spec.js} | 5 +- 4 files changed, 2 insertions(+), 143 deletions(-) delete mode 100644 modules/richAudienceBidAdapter.js create mode 100644 modules/richaudienceBidAdapter.js rename modules/{richAudienceBidAdapter.md => richaudienceBidAdapter.md} (100%) rename test/spec/modules/{richAudienceBidAdapter_spec.js => richaudienceBidAdapter_spec.js} (98%) diff --git a/modules/richAudienceBidAdapter.js b/modules/richAudienceBidAdapter.js deleted file mode 100644 index bd47e481a76..00000000000 --- a/modules/richAudienceBidAdapter.js +++ /dev/null @@ -1,140 +0,0 @@ -import {registerBidder} from '../src/adapters/bidderFactory'; -import {config} from '../src/config'; -import {BANNER, VIDEO} from '../src/mediaTypes'; -import * as utils from '../src/utils'; - -const BIDDER_CODE = 'richaudience'; - -export const spec = { - code: BIDDER_CODE, - aliases: ['ra'], - supportedMediaTypes: [BANNER, VIDEO], - - /*** - * Determines whether or not the given bid request is valid - * - * @param {bidRequest} bid The bid params to validate. - * @returns {boolean} True if this is a valid bid, and false otherwise - */ - isBidRequestValid: function (bid) { - return !!(bid.params && bid.params.pid && bid.params.supplyType); - }, - /*** - * Build a server request from the list of valid BidRequests - * @param {validBidRequests} is an array of the valid bids - * @param {bidderRequest} bidder request object - * @returns {ServerRequest} Info describing the request to the server - */ - buildRequests: function (validBidRequests, bidderRequest) { - return validBidRequests.map(bid => { - var payload = { - bidfloor: bid.params.bidfloor, - ifa: bid.params.ifa, - pid: bid.params.pid, - supplyType: bid.params.supplyType, - currencyCode: config.getConfig('currency.adServerCurrency'), - auctionId: bid.auctionId, - bidId: bid.bidId, - BidRequestsCount: bid.bidRequestsCount, - bidder: bid.bidder, - bidderRequestId: bid.bidderRequestId, - tagId: bid.adUnitCode, - sizes: bid.sizes.map(size => ({ - w: size[0], - h: size[1], - })), - referer: (typeof bidderRequest.refererInfo.referer != 'undefined' ? encodeURIComponent(bidderRequest.refererInfo.referer) : null), - numIframes: (typeof bidderRequest.refererInfo.numIframes != 'undefined' ? bidderRequest.refererInfo.numIframes : null), - transactionId: bid.transactionId, - timeout: config.getConfig('bidderTimeout'), - }; - - if (bidderRequest && bidderRequest.gdprConsent) { - payload.gdpr_consent = bidderRequest.gdprConsent.consentString; - payload.gdpr = bidderRequest.gdprConsent.gdprApplies; // we're handling the undefined case server side - } else { - payload.gdpr_consent = ''; - payload.gdpr = null; - } - - var payloadString = JSON.stringify(payload); - - var endpoint = 'https://shb.richaudience.com/hb/'; - - return { - method: 'POST', - url: endpoint, - data: payloadString, - }; - }); - }, - /*** - * Read the response from the server and build a list of bids - * @param {serverResponse} Response from the server. - * @param {bidRequest} Bid request object - * @returns {bidResponses} Array of bids which were nested inside the server - */ - interpretResponse: function (serverResponse, bidRequest) { - const bidResponses = []; - - var response = serverResponse.body; - - try { - if (response) { - var bidResponse = { - requestId: JSON.parse(bidRequest.data).bidId, - cpm: response.cpm, - width: response.width, - height: response.height, - creativeId: response.creative_id, - mediaType: response.media_type, - netRevenue: response.netRevenue, - currency: response.currency, - ttl: response.ttl, - dealId: response.dealId, - }; - - if (response.media_type === 'video') { - bidResponse.vastXml = response.vastXML; - } else { - bidResponse.ad = response.adm - } - - bidResponses.push(bidResponse); - } - } catch (error) { - utils.logError('Error while parsing Rich Audience response', error); - } - return bidResponses - }, - /*** - * User Syncs - * - * @param {syncOptions} Publisher prebid configuration - * @param {serverResponses} Response from the server - * @param {gdprConsent} GPDR consent object - * @returns {Array} - */ - getUserSyncs: function (syncOptions, serverResponses, gdprConsent) { - const syncs = []; - - var rand = Math.floor(Math.random() * 9999999999); - var syncUrl = ''; - - if (gdprConsent && typeof gdprConsent.consentString === 'string') { - syncUrl = 'https://sync.richaudience.com/dcf3528a0b8aa83634892d50e91c306e/?ord=' + rand + '&pubconsent=' + gdprConsent.consentString + '&euconsent=' + gdprConsent.consentString; - } else { - syncUrl = 'https://sync.richaudience.com/dcf3528a0b8aa83634892d50e91c306e/?ord=' + rand; - } - - if (syncOptions.iframeEnabled) { - syncs.push({ - type: 'iframe', - url: syncUrl - }); - } - return syncs - }, -}; - -registerBidder(spec); diff --git a/modules/richaudienceBidAdapter.js b/modules/richaudienceBidAdapter.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/modules/richAudienceBidAdapter.md b/modules/richaudienceBidAdapter.md similarity index 100% rename from modules/richAudienceBidAdapter.md rename to modules/richaudienceBidAdapter.md diff --git a/test/spec/modules/richAudienceBidAdapter_spec.js b/test/spec/modules/richaudienceBidAdapter_spec.js similarity index 98% rename from test/spec/modules/richAudienceBidAdapter_spec.js rename to test/spec/modules/richaudienceBidAdapter_spec.js index c974ff70ce3..16d67ce7ceb 100644 --- a/test/spec/modules/richAudienceBidAdapter_spec.js +++ b/test/spec/modules/richaudienceBidAdapter_spec.js @@ -1,13 +1,12 @@ // import or require modules necessary for the test, e.g.: import {expect} from 'chai'; // may prefer 'assert' in place of 'expect' -// import spec from 'modules/richAudienceBidAdapter'; import { spec -} from 'modules/richAudienceBidAdapter'; +} from 'modules/richaudienceBidAdapter'; import {config} from 'src/config'; import * as utils from 'src/utils'; -describe('Rich Audience adapter tests', function () { +describe('Richaudience adapter tests', function () { var DEFAULT_PARAMS = [{ adUnitCode: 'test-div', bidId: '2c7c8e9c900244', From a38410848667fe36b79d37ed1b4fb68e0605268e Mon Sep 17 00:00:00 2001 From: Carlos Date: Tue, 30 Apr 2019 13:03:34 +0200 Subject: [PATCH 2/2] uploading bidder --- modules/richaudienceBidAdapter.js | 140 ++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) diff --git a/modules/richaudienceBidAdapter.js b/modules/richaudienceBidAdapter.js index e69de29bb2d..bd47e481a76 100644 --- a/modules/richaudienceBidAdapter.js +++ b/modules/richaudienceBidAdapter.js @@ -0,0 +1,140 @@ +import {registerBidder} from '../src/adapters/bidderFactory'; +import {config} from '../src/config'; +import {BANNER, VIDEO} from '../src/mediaTypes'; +import * as utils from '../src/utils'; + +const BIDDER_CODE = 'richaudience'; + +export const spec = { + code: BIDDER_CODE, + aliases: ['ra'], + supportedMediaTypes: [BANNER, VIDEO], + + /*** + * Determines whether or not the given bid request is valid + * + * @param {bidRequest} bid The bid params to validate. + * @returns {boolean} True if this is a valid bid, and false otherwise + */ + isBidRequestValid: function (bid) { + return !!(bid.params && bid.params.pid && bid.params.supplyType); + }, + /*** + * Build a server request from the list of valid BidRequests + * @param {validBidRequests} is an array of the valid bids + * @param {bidderRequest} bidder request object + * @returns {ServerRequest} Info describing the request to the server + */ + buildRequests: function (validBidRequests, bidderRequest) { + return validBidRequests.map(bid => { + var payload = { + bidfloor: bid.params.bidfloor, + ifa: bid.params.ifa, + pid: bid.params.pid, + supplyType: bid.params.supplyType, + currencyCode: config.getConfig('currency.adServerCurrency'), + auctionId: bid.auctionId, + bidId: bid.bidId, + BidRequestsCount: bid.bidRequestsCount, + bidder: bid.bidder, + bidderRequestId: bid.bidderRequestId, + tagId: bid.adUnitCode, + sizes: bid.sizes.map(size => ({ + w: size[0], + h: size[1], + })), + referer: (typeof bidderRequest.refererInfo.referer != 'undefined' ? encodeURIComponent(bidderRequest.refererInfo.referer) : null), + numIframes: (typeof bidderRequest.refererInfo.numIframes != 'undefined' ? bidderRequest.refererInfo.numIframes : null), + transactionId: bid.transactionId, + timeout: config.getConfig('bidderTimeout'), + }; + + if (bidderRequest && bidderRequest.gdprConsent) { + payload.gdpr_consent = bidderRequest.gdprConsent.consentString; + payload.gdpr = bidderRequest.gdprConsent.gdprApplies; // we're handling the undefined case server side + } else { + payload.gdpr_consent = ''; + payload.gdpr = null; + } + + var payloadString = JSON.stringify(payload); + + var endpoint = 'https://shb.richaudience.com/hb/'; + + return { + method: 'POST', + url: endpoint, + data: payloadString, + }; + }); + }, + /*** + * Read the response from the server and build a list of bids + * @param {serverResponse} Response from the server. + * @param {bidRequest} Bid request object + * @returns {bidResponses} Array of bids which were nested inside the server + */ + interpretResponse: function (serverResponse, bidRequest) { + const bidResponses = []; + + var response = serverResponse.body; + + try { + if (response) { + var bidResponse = { + requestId: JSON.parse(bidRequest.data).bidId, + cpm: response.cpm, + width: response.width, + height: response.height, + creativeId: response.creative_id, + mediaType: response.media_type, + netRevenue: response.netRevenue, + currency: response.currency, + ttl: response.ttl, + dealId: response.dealId, + }; + + if (response.media_type === 'video') { + bidResponse.vastXml = response.vastXML; + } else { + bidResponse.ad = response.adm + } + + bidResponses.push(bidResponse); + } + } catch (error) { + utils.logError('Error while parsing Rich Audience response', error); + } + return bidResponses + }, + /*** + * User Syncs + * + * @param {syncOptions} Publisher prebid configuration + * @param {serverResponses} Response from the server + * @param {gdprConsent} GPDR consent object + * @returns {Array} + */ + getUserSyncs: function (syncOptions, serverResponses, gdprConsent) { + const syncs = []; + + var rand = Math.floor(Math.random() * 9999999999); + var syncUrl = ''; + + if (gdprConsent && typeof gdprConsent.consentString === 'string') { + syncUrl = 'https://sync.richaudience.com/dcf3528a0b8aa83634892d50e91c306e/?ord=' + rand + '&pubconsent=' + gdprConsent.consentString + '&euconsent=' + gdprConsent.consentString; + } else { + syncUrl = 'https://sync.richaudience.com/dcf3528a0b8aa83634892d50e91c306e/?ord=' + rand; + } + + if (syncOptions.iframeEnabled) { + syncs.push({ + type: 'iframe', + url: syncUrl + }); + } + return syncs + }, +}; + +registerBidder(spec);