Skip to content

Commit

Permalink
Update Widespace request param (#1098)
Browse files Browse the repository at this point in the history
* widespace adapter: separating params with # and addding hb, and hb.ver into it

* widespace adapter: update tests with new mandatory params

* widespace adapter: add adapter version number before # so we can force specific cached request script based on our adapter version

* widespace adapter: sid as query param

* widespace adapter: revert back sid after hash
  • Loading branch information
mizmaar3 authored and matthewlane committed Apr 17, 2017
1 parent 4257158 commit b33a229
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
42 changes: 27 additions & 15 deletions src/adapters/widespace.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

import { getBidRequest } from '../utils.js';

var utils = require('../utils.js');
var adloader = require('../adloader.js');
var bidmanager = require('../bidmanager.js');
var bidfactory = require('../bidfactory.js');

const utils = require('../utils.js');
const adloader = require('../adloader.js');
const bidmanager = require('../bidmanager.js');
const bidfactory = require('../bidfactory.js');
const WS_ADAPTER_VERSION = '1.0.1';

function WidespaceAdapter() {
let useSSL = 'https:' === document.location.protocol,
Expand All @@ -17,9 +17,9 @@ function WidespaceAdapter() {

for (var i = 0; i < bids.length; i++) {
const bid = bids[i],
callbackUid = bid.bidId,
sid = bid.params.sid,
currency = bid.params.currency;
callbackUid = bid.bidId,
sid = bid.params.sid,
currency = bid.params.cur || bid.params.currency;

//Handle Sizes string
let sizeQueryString = '';
Expand All @@ -29,14 +29,25 @@ function WidespaceAdapter() {
return prev ? `${prev},${curr}` : curr;
}, sizeQueryString);

var requestURL = baseURL;
requestURL = utils.tryAppendQueryString(requestURL, 'hb.name', 'prebidjs');
requestURL = utils.tryAppendQueryString(requestURL, 'hb.callback', callbackName);
requestURL = utils.tryAppendQueryString(requestURL, 'hb.callbackUid', callbackUid);
requestURL = utils.tryAppendQueryString(requestURL, 'hb.sizes', sizeQueryString);
requestURL = utils.tryAppendQueryString(requestURL, 'sid', sid);
requestURL = utils.tryAppendQueryString(requestURL, 'hb.currency', currency);
let requestURL = baseURL;
requestURL = utils.tryAppendQueryString(requestURL, 'hb.ver', WS_ADAPTER_VERSION);

const params = {
'hb': '1',
'hb.name': 'prebidjs',
'hb.callback': callbackName,
'hb.callbackUid': callbackUid,
'hb.sizes': sizeQueryString,
'hb.currency': currency,
'sid': sid
};

requestURL += '#';

// Append all params to requestURL
for (let key of Object.keys(params)) {
requestURL += key + '=' + params[key] + '&';
}

// Expose the callback
$$PREBID_GLOBAL$$.widespaceHandleCB = window[callbackName] = handleCallback;
Expand Down Expand Up @@ -66,6 +77,7 @@ function WidespaceAdapter() {
placementCode = inBid.placementCode;
validSizes = inBid.sizes;
}

if (bid && bid.callbackUid && bid.status !=='noad' && verifySize(bid.sizes, validSizes)) {
bidObject = bidfactory.createBid(1);
bidObject.bidderCode = bidCode;
Expand Down
2 changes: 2 additions & 0 deletions test/spec/adapters/widespace_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ describe('WidespaceAdapter', () => {
it('should include required request parameters', () => {
const endpointRequest = expect(adLoader.loadScript.firstCall.args[0]);
endpointRequest.to.include('sid');
endpointRequest.to.include('hb');
endpointRequest.to.include('hb.ver');
endpointRequest.to.include('hb.callbackUid');
endpointRequest.to.include('hb.callback');
endpointRequest.to.include('hb.sizes');
Expand Down

0 comments on commit b33a229

Please sign in to comment.