Skip to content

Commit

Permalink
Merge pull request #9 from harman-goei/upgrade-0.8-2
Browse files Browse the repository at this point in the history
Upgrade 0.8 2
  • Loading branch information
Harman Goei committed May 15, 2016
2 parents 957bfb7 + d680d60 commit b35c029
Show file tree
Hide file tree
Showing 17 changed files with 714 additions and 375 deletions.
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
language: node_js

node_js:
- 0.12
- 0.11
- "5.1"

before_install:
- npm install -g gulp

script:
- gulp build
- gulp build
21 changes: 14 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
[![Build Status](https://travis-ci.org/prebid/Prebid.js.svg?branch=master)](https://travis-ci.org/prebid/Prebid.js)
[![Percentage of issues still open](http://isitmaintained.com/badge/open/prebid/Prebid.js.svg)](http://isitmaintained.com/project/prebid/Prebid.js "Percentage of issues still open")
[![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/prebid/Prebid.js.svg)](http://isitmaintained.com/project/prebid/Prebid.js "Average time to resolve an issue")
[![Code Climate](https://codeclimate.com/github/prebid/Prebid.js/badges/gpa.svg)](https://codeclimate.com/github/prebid/Prebid.js)

Prebid.js
========

Expand Down Expand Up @@ -36,12 +41,14 @@ Download the integration example [here](https://github.com/prebid/Prebid.js/blob
**Include the prebid.js library**
Note that you need to host `prebid.js` locally or on a CDN and update the reference in the code snippet below for `cdn.host.com/prebid.min.js
```javascript
(function() {
var d = document, pbs = d.createElement('script'), pro = d.location.protocol;
pbs.type = 'text/javascript';
pbs.src = ((pro === 'https:') ? 'https' : 'http') + '://cdn.host.com/prebid.min.js';
var target = document.getElementsByTagName('head')[0];
target.insertBefore(pbs, target.firstChild);
(function () {
var d = document;
var pbs = d.createElement('script');
pbs.type = 'text/javascript';
//replace with your CDN hosted version. HTTPS is strongly recommended.
pbs.src = '//cdn.host.com/prebid.min.js';
var target = d.getElementsByTagName('script')[0];
target.parentNode.insertBefore(pbs, target);
})();
```

Expand Down Expand Up @@ -88,7 +95,7 @@ Full Developer API reference:

Contribute
----------
**Note:** You need to have at least `node.js 4.x` or greater installed to be able to run the gulp build commands.
**Note:** You need to have at least `node.js 4.x` or greater installed to be able to run the gulp build commands.

### Add a Bidder Adapter ###
Follow the [guide outlined here](http://prebid.org/dev-docs/bidder-adaptor.html) to add an adapter.
Expand Down
5 changes: 4 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ var concat = require('gulp-concat');
var jscs = require('gulp-jscs');
var header = require('gulp-header');
var zip = require('gulp-zip');
var replace = require('gulp-replace');

var CI_MODE = process.env.NODE_ENV === 'ci';
var prebid = require('./package.json');
var dateString = 'Updated : ' + (new Date()).toISOString().substring(0, 10);
var packageNameVersion = prebid.name + '_' + prebid.version;
var banner = '/* <%= prebid.name %> v<%= prebid.version %> \n' + dateString + ' */\n';
var banner = '/* <%= prebid.name %> v<%= prebid.version %>\n' + dateString + ' */\n';

// Tasks
gulp.task('default', ['clean', 'quality', 'webpack']);
Expand All @@ -43,6 +44,7 @@ gulp.task('devpack', function () {
webpackConfig.devtool = 'source-map';
return gulp.src(['src/prebid.js'])
.pipe(webpack(webpackConfig))
.pipe(replace('$prebid.version$', prebid.version))
.pipe(gulp.dest('build/dev'))
.pipe(connect.reload());
});
Expand All @@ -58,6 +60,7 @@ gulp.task('webpack', function () {

return gulp.src(['src/prebid.js'])
.pipe(webpack(webpackConfig))
.pipe(replace('$prebid.version$', prebid.version))
.pipe(uglify())
.pipe(header(banner, { prebid: prebid }))
.pipe(gulp.dest('build/dist'))
Expand Down
17 changes: 17 additions & 0 deletions integrationExamples/gpt/creative_rendering.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
<!-- #1 deprecated method - use preferred method below instead-->
<script>
try{ window.top.pbjs.renderAd(document, '%%PATTERN:hb_adid%%'); } catch(e) {/*ignore*/}
</script>

<!-- #2 preferred method for showing ad - handles cases when pbjs is not in the top window -->
<script>
var w = window;
for (i = 0; i < 10; i++) {
w = w.parent;
if (w.pbjs) {
try {
w.pbjs.renderAd(document, '%%PATTERN:hb_adid%%');
break;
} catch (e) {
continue;
}
}
}
</script>
2 changes: 1 addition & 1 deletion integrationExamples/gpt/pbjs_example_gpt.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
googletag.cmd.push(function () {
pbjs.que.push(function () {
pbjs.setTargetingForGPTAsync();
googletag.pubads().refresh();
});
googletag.pubads().refresh();
});
pbjs.initAdserverSet = true;
}
Expand Down
127 changes: 94 additions & 33 deletions loaders/adapterLoader.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,117 @@
/** adapterLoader
* Webpack loader to insert dynamic javascript into `./src/adaptermanager.js`
* This is used in `./webpack.conf.js`
* */

'use strict';

const fs = require('fs');
const blockLoader = require('block-loader');
let adapters = require('../package.json').adapters;
const adapters = require('../package.json').adapters;

const files = fs.readdirSync('src/adapters').map((file) => file.replace(/\.[^/.]+$/, ''));
const adapterNames = adapters.map(getNames).filter(getUniques);
const aliases = adapters.filter(getAliases);

var options = {
start: '/** INSERT ADAPTERS - DO NOT EDIT OR REMOVE */',
end: '/** END INSERT ADAPTERS */',
process: function insertAdapters() {
const files = fs.readdirSync('src/adapters').map((file) => file.replace(/\.[^/.]+$/, ''));
process: insertAdapters
};

if (!adapters || !adapters.length) {
console.log('Prebid Warning: adapters config not found in package.json, building with all' +
' adapters');
adapters = files;
}
/**
* Returns a block of javascript statements to load adapter modules, register the adapters and
* set adapter aliases
* @returns {*}
*/
function insertAdapters() {

let inserts = adapters.filter((adapter) => {
if (files.includes(adapter)) {
return adapter;
} else {
console.log(`Prebid Warning: no adapter found for ${adapter}, continuing.`);
}
});

if (!inserts.length) {
console.log('Prebid Warning: no matching adapters found for config, building with all' +
' adapters.');
if (!adapters) {
console.log('Prebid Warning: adapters config not found in package.json, no adapters will' +
' be loaded');
return '';
}

const inserts = adapterNames.map(name => {
if (files.includes(name)) {
return name;
} else {
console.log(`Prebid Warning: no adapter found for ${name}, continuing.`);
}
});

inserts = inserts.length ? inserts : files;
return inserts.map((adapter) => {
if (adapter === 'appnexusAst') {
return `import { AppnexusAst } from './adapters/appnexusAst';\n` +
`exports.registerBidAdapter(new AppnexusAst('appnexus'), 'appnexus');\n`;
}

return `var ${adapterName(adapter)} = require('./adapters/${adapter}.js');\n` +
`exports.registerBidAdapter(new ${adapterName(adapter)}` +
`${useCreateNew(adapter)}(), '${adapter}');\n`;
}).join('');
if (!inserts.length) {
console.log('Prebid Warning: no matching adapters found for config, no adapters will be' +
' loaded.');
return '';
}
};

return inserts.map(name => {
if (name === 'appnexusAst') {
return `import { AppnexusAst } from './adapters/appnexusAst';
exports.registerBidAdapter(new AppnexusAst('appnexus'), 'appnexus');\n`;
} else {
return `var ${adapterName(name)} = require('./adapters/${name}.js');
exports.registerBidAdapter(new ${adapterName(name)}${useCreateNew(name)}(), '${name}');\n`;
}
})
.concat(aliases.map(adapter => {
const name = Object.keys(adapter)[0];
return `exports.aliasBidAdapter('${name}','${adapter[name].alias}');\n`;
}))
.join('');
}

/**
* Derive the variable name to use for the adapter
* @param adapter
* @returns {string}
*/
function adapterName(adapter) {
let result = adapter.split('');
const result = adapter.split('');
return result[0].toUpperCase() + result.join('').substr(1) + 'Adapter';
}

// some adapters export an object with a `createNew` constructor so accommodate this pattern
/**
* Some adapters export an object with a `createNew` constructor so accommodate this pattern
* @param adapter
* @returns {string}
*/
function useCreateNew(adapter) {
return adapter === 'appnexus' ? '.createNew' : '';
}

/**
* Filter an array to return unique values
* @param value current array element value
* @param index current array element index
* @param self current array
* @returns {boolean} if true the current array element is returned
*
* http://stackoverflow.com/questions/1960473/unique-values-in-an-array
*/
function getUniques(value, index, self) {
return self.indexOf(value) === index;
}

/**
* Filter to derive the adapter name from array elements as strings or objects
* @param adapter
* @returns {*}
*/
function getNames(adapter) {
// if `length` then `adapter` is a string, otherwise an object
return adapter.length ? adapter : Object.keys(adapter)[0];
}

/**
* Return adapter objects that have an alias field
* @param adapter
* @returns {*}
*/
function getAliases(adapter) {
const name = Object.keys(adapter)[0];
return adapter && name && adapter[name].alias;
}

module.exports = blockLoader(options);
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "prebid.js",
"version": "0.7.0",
"version": "0.8.1",
"description": "Header Bidding Management Library",
"main": "src/prebid.js",
"scripts": {
Expand Down Expand Up @@ -29,7 +29,9 @@
"triplelift",
"yieldbot",
"nginad",
"brightcom"
"brightcom",
{ "appnexus": {"alias": "brealtime"} },
{ "appnexus": {"alias": "pagescience"} }
],
"author": "the prebid.js contributors",
"license": "Apache-2.0",
Expand Down
7 changes: 2 additions & 5 deletions src/adaptermanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ var CONSTANTS = require('./constants.json');
var events = require('./events');
import { BaseAdapter } from './adapters/baseAdapter';


var _bidderRegistry = {};
exports.bidderRegistry = _bidderRegistry;

Expand Down Expand Up @@ -66,7 +65,7 @@ exports.aliasBidAdapter = function (bidderCode, alias) {
} else {
try {
let newAdapter = null;
if(bidAdaptor instanceof BaseAdapter) {
if (bidAdaptor instanceof BaseAdapter) {
//newAdapter = new bidAdaptor.constructor(alias);
utils.logError(bidderCode + ' bidder does not currently support aliasing.', 'adaptermanager.aliasBidAdapter');
} else {
Expand All @@ -84,8 +83,6 @@ exports.aliasBidAdapter = function (bidderCode, alias) {
};

/** INSERT ADAPTERS - DO NOT EDIT OR REMOVE */

// here be adapters
/** END INSERT ADAPTERS */

//default bidder alias
exports.aliasBidAdapter('appnexus', 'brealtime');
3 changes: 2 additions & 1 deletion src/adapters/aol.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ var AolAdapter = function AolAdapter() {
},
params: {
cors: 'yes',
cmd: 'bid'
cmd: 'bid',
bidfloor: (typeof bid.params.bidFloor !== "undefined") ? bid.params.bidFloor.toString() : ''
},
pubApiConfig: ADTECH_PUBAPI_CONFIG,
placementCode: bid.placementCode
Expand Down
3 changes: 1 addition & 2 deletions src/adapters/indexExchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,7 @@ var IndexExchangeAdapter = function IndexExchangeAdapter() {
}

if (cygnus_index_args.slots.length > 20) {
utils.logError('Error calling index adapter, too many unique slot-sizes. Only 20 supported.', ADAPTER_NAME);
return;
utils.logError('Too many unique sizes on slots, will use the first 20.', ADAPTER_NAME);
}

bidmanager.setExpectedBidsCount(ADAPTER_CODE, expectedBids);
Expand Down
14 changes: 11 additions & 3 deletions src/adapters/openx.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,17 @@ var OpenxAdapter = function OpenxAdapter(options) {
var i;
var POX = OX();

POX.setPageURL(opts.pageURL);
POX.setRefererURL(opts.refererURL);
POX.addPage(opts.pgid);
if (opts.pageURL) {
POX.setPageURL(opts.pageURL);
}

if (opts.refererURL) {
POX.setRefererURL(opts.refererURL);
}

if (opts.pgid) {
POX.addPage(opts.pgid);
}

// Add each ad unit ID
for (i = 0; i < bids.length; i++) {
Expand Down
Loading

0 comments on commit b35c029

Please sign in to comment.