Skip to content

Commit

Permalink
Made some cosmetic changes to names and documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
dbemiller committed Jun 27, 2017
1 parent bf92a4c commit 8468d77
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 29 deletions.
34 changes: 17 additions & 17 deletions src/adServerManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,52 +39,52 @@ const prebid = getGlobal();
/**
* @typedef {Object} VideoSupport
*
* @property {string} code The identifying code for this adserver. Note that this contributes to
* the user-facing API. For example, if the adserver code is 'dfp', and the Prebid bundle contains two
* @property {string} name A name which identifies this adserver. Note that this contributes to
* the user-facing API. For example, if the adserver name is 'dfp', and the Prebid bundle contains two
* or more ad server modules, then publishers will access its functions through 'pbjs.adservers.dfp'.
*
* @method {VideoAdUrlBuilder} buildVideoAdUrl
* @function {VideoAdUrlBuilder} buildVideoAdUrl
*/

/**
* Prepares a namespace on object so that utility functions can be added to it.
*
* If this is the only code we've seen, attach functionality to $$PREBID_GLOBAL$$.adServer.
* If we've seen any other codes, attach functionality to $$PREBID_GLOBAL$$.adServers[code].
* If this is the only name we've seen, attach functionality to $$PREBID_GLOBAL$$.adServer.
* If we've seen any other names, attach functionality to $$PREBID_GLOBAL$$.adServers[name].
*
* @param {object} object The object where this function should manage namespaces.
* @param {string} code The code for this ad server.
* @param {string} name The name for this ad server.
* @return {object} An object where functions for dealing with this ad server can be added.
*/
function prepareNamespaceIn(object, code) {
if (object.adServer && object.adServer.code !== code) {
function prepareNamespaceIn(object, name) {
if (object.adServer && object.adServer.name !== name) {
object.adServers = { };
object.adServers[object.adServer.code] = object.adServer;
delete object.adServer.code;
object.adServers[object.adServer.name] = object.adServer;
delete object.adServer.name;
delete object.adServer;
}

if (object.adServer) {
return object.adServer;
}
if (object.adServers) {
if (!object.adServers[code]) {
object.adServers[code] = { };
if (!object.adServers[name]) {
object.adServers[name] = { };
}
return object.adServers[code];
return object.adServers[name];
}
else {
object.adServer = { code };
object.adServer = { name };
return object.adServer;
}
}

/**
* Enable video support for the Ad Server.
*
* @property {string} code The identifying code for this adserver.
* @property {string} name The identifying name for this adserver.
* @property {VideoSupport} videoSupport An object with the functions needed to support video in Prebid.
*/
export function registerVideoSupport(code, videoSupport) {
prepareNamespaceIn(prebid, code).buildVideoAdUrl = videoSupport.buildVideoAdUrl;
export function registerVideoSupport(name, videoSupport) {
prepareNamespaceIn(prebid, name).buildVideoAdUrl = videoSupport.buildVideoAdUrl;
}
16 changes: 8 additions & 8 deletions src/videoCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,26 +75,26 @@ function fromStorageResponse(response) {
/**
* A function which bridges the APIs between the videoCacheStoreCallback and our ajax function's API.
*
* @param {videoCacheStoreCallback} callback A callback to the "store" function.
* @param {videoCacheStoreCallback} done A callback to the "store" function.
* @return {Function} A callback which interprets the cache server's responses, and makes up the right
* arguments for our callback.
*/
function shimStorageCallback(callback) {
function shimStorageCallback(done) {
return {
success: function(responseBody) {
let ids;
try {
ids = JSON.parse(responseBody).responses.map(fromStorageResponse)
}
catch (e) {
callback(e, []);
done(e, []);
return;
}

callback(null, ids);
done(null, ids);
},
error: function(statusText, responseBody) {
callback(new Error('Error storing video ad in the cache: ' + statusText + ': ' + JSON.stringify(responseBody)), []);
done(new Error('Error storing video ad in the cache: ' + statusText + ': ' + JSON.stringify(responseBody)), []);
}
}
}
Expand All @@ -103,15 +103,15 @@ function shimStorageCallback(callback) {
* If the given bid is for a Video ad, generate a unique ID and cache it somewhere server-side.
*
* @param {CacheableBid[]} bids A list of bid objects which should be cached.
* @param {videoCacheStoreCallback} [callback] An optional callback which should be executed after
* @param {videoCacheStoreCallback} [done] An optional callback which should be executed after
* the data has been stored in the cache.
*/
export function store(bids, callback) {
export function store(bids, done) {
const requestData = {
puts: bids.map(toStorageRequest)
};

ajax(PUT_URL, shimStorageCallback(callback), JSON.stringify(requestData), {
ajax(PUT_URL, shimStorageCallback(done), JSON.stringify(requestData), {
contentType: 'text/plain',
withCredentials: true
});
Expand Down
7 changes: 3 additions & 4 deletions test/spec/unit/adServerManager_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ describe('The ad server manager', () => {
registerVideoSupport('dfp', { buildVideoAdUrl: videoSupport });

expect(prebid).to.have.property('adServer');
expect(prebid.adServer).to.have.property('code');
expect(prebid.adServer.code).to.equal('dfp');
expect(prebid.adServer).to.have.property('name', 'dfp');

expect(prebid.adServer).to.have.property('buildVideoAdUrl');
expect(prebid.adServer.buildVideoAdUrl).to.equal(videoSupport);
Expand All @@ -35,8 +34,8 @@ describe('The ad server manager', () => {
expect(prebid.adServers.ast).to.have.property('buildVideoAdUrl');
expect(prebid.adServers).to.have.property('dfp');
expect(prebid.adServers.dfp).to.have.property('buildVideoAdUrl');
expect(prebid.adServers.ast).not.to.have.property('code');
expect(prebid.adServers.dfp).not.to.have.property('code');
expect(prebid.adServers.ast).not.to.have.property('name');
expect(prebid.adServers.dfp).not.to.have.property('name');

expect(prebid.adServers.dfp.buildVideoAdUrl).to.equal(dfpVideoSupport);
expect(prebid.adServers.ast.buildVideoAdUrl).to.equal(astVideoSupport);
Expand Down

0 comments on commit 8468d77

Please sign in to comment.