Skip to content

Commit

Permalink
Merge pull request #4 from prebid/master
Browse files Browse the repository at this point in the history
Latest
  • Loading branch information
pm-shashank-jain authored Dec 21, 2018
2 parents d1146d7 + e476021 commit 53ac4fe
Show file tree
Hide file tree
Showing 66 changed files with 9,852 additions and 3,519 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ A test module might have the following general structure:
import { expect } from 'chai'; // may prefer 'assert' in place of 'expect'
import adapter from 'src/adapters/<adapter>';

describe('<Adapter>', () => {
it('<description of unit or feature being tested>', () => {
describe('<Adapter>', function () {
it('<description of unit or feature being tested>', function () {
// Arrange - set up preconditions and inputs
// Act - call or act on the code under test
// Assert - use chai to check that expected results have occurred
Expand Down
76 changes: 26 additions & 50 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var _ = require('lodash');
var argv = require('yargs').argv;
var gulp = require('gulp');
var gutil = require('gulp-util');
var connect = require('gulp-connect');
var webserver = require('gulp-webserver');
var webpack = require('webpack');
var webpackStream = require('webpack-stream');
var uglify = require('gulp-uglify');
Expand Down Expand Up @@ -56,11 +56,12 @@ function e2etestReport() {
var reportPort = 9010;
var targetDestinationDir = './e2etest-report';
helpers.createEnd2EndTestReport(targetDestinationDir);
connect.server({
port: reportPort,
root: './',
livereload: true
});
gulp.src('./')
.pipe(webserver({
port: reportPort,
directoryListing: true,
livereload: true
}));

setTimeout(function() {
opens('http://localhost:' + reportPort + '/' + targetDestinationDir.slice(2) + '/results.html');
Expand Down Expand Up @@ -90,13 +91,14 @@ function lint(done) {
function viewCoverage(done) {
var coveragePort = 1999;

connect.server({
port: coveragePort,
root: 'build/coverage/karma_html',
livereload: false
});
opens('http://localhost:' + coveragePort);
done();
var stream = gulp.src('./')
.pipe(webserver({
port: coveragePort,
directoryListing: true,
livereload: false,
open: 'build/coverage/karma_html/index.html'
}));
stream.on('finish', done);
};
viewCoverage.displayName = 'view-coverage';

Expand All @@ -113,16 +115,17 @@ function watch(done) {
'test/spec/loaders/**/*.js'
]);

connect.server({
https: argv.https,
port: port,
root: './',
livereload: true
});
var stream = gulp.src('./')
.pipe(webserver({
https: argv.https,
port: port,
directoryListing: true,
livereload: true
}));

mainWatcher.on('all', gulp.series(clean, gulp.parallel(lint, 'build-bundle-dev', test)));
loaderWatcher.on('all', gulp.series(lint));
done();
stream.on('finish', done);
};

function makeDevpackPkg() {
Expand All @@ -137,8 +140,7 @@ function makeDevpackPkg() {
.pipe(helpers.nameModules(externalModules))
.pipe(webpackStream(cloned, webpack))
.pipe(replace('$prebid.version$', prebid.version))
.pipe(gulp.dest('build/dev'))
.pipe(connect.reload());
.pipe(gulp.dest('build/dev'));
}

function makeWebpackPkg() {
Expand All @@ -158,8 +160,7 @@ function makeWebpackPkg() {
.pipe(uglify())
.pipe(gulpif(file => file.basename === 'prebid-core.js', header(banner, { prebid: prebid })))
.pipe(optimizejs())
.pipe(gulp.dest('build/dist'))
.pipe(connect.reload());
.pipe(gulp.dest('build/dist'));
}

function gulpBundle(dev) {
Expand Down Expand Up @@ -227,12 +228,7 @@ function newKarmaCallback(done) {
if (exitCode) {
done(new Error('Karma tests failed with exit code ' + exitCode));
} else {
if (argv.browserstack) {
// process.exit(0);
done(); // test this with travis (or circleci)
} else {
done();
}
done();
}
}
}
Expand Down Expand Up @@ -273,26 +269,6 @@ function coveralls() { // 2nd arg is a dependency: 'test' must be finished
.pipe(shell('cat build/coverage/lcov.info | node_modules/coveralls/bin/coveralls.js'));
}

// Watch Task with Live Reload
gulp.task('watch', function () {
gulp.watch([
'src/**/*.js',
'modules/**/*.js',
'test/spec/**/*.js',
'!test/spec/loaders/**/*.js'
], ['build-bundle-dev', 'test']);
gulp.watch([
'loaders/**/*.js',
'test/spec/loaders/**/*.js'
], ['lint']);
connect.server({
https: argv.https,
port: port,
root: './',
livereload: true
});
});

function e2eTest() {
var cmdQueue = [];
if (argv.browserstack) {
Expand Down
12 changes: 6 additions & 6 deletions modules/adgenerationBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,6 @@ export const spec = {
return [];
}
const bidRequest = bidRequests.bidRequest;
if (!bidRequest.mediaTypes || bidRequest.mediaTypes.banner) {
if (!body.w || !body.h) {
return [];
}
}
const bidResponse = {
requestId: bidRequest.bidId,
cpm: body.cpm || 0,
Expand All @@ -91,7 +86,7 @@ export const spec = {
netRevenue: true,
ttl: body.ttl || 10,
};
if (bidRequest.mediaTypes && bidRequest.mediaTypes.native) {
if (isNative(body)) {
bidResponse.native = createNativeAd(body);
bidResponse.mediaType = NATIVE;
} else {
Expand Down Expand Up @@ -124,6 +119,11 @@ function createAd(body, bidRequest) {
return ad;
}

function isNative(body) {
if (!body) return false;
return body.native_ad && body.native_ad.assets.length > 0;
}

function createNativeAd(body) {
let native = {};
if (body.native_ad && body.native_ad.assets.length > 0) {
Expand Down
37 changes: 35 additions & 2 deletions modules/adtelligentBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,43 @@ export const spec = {
isBidRequestValid: function (bid) {
return bid && bid.params && bid.params.aid;
},
getUserSyncs: function (syncOptions, serverResponses) {
var syncs = [];

function addSyncs(_s) {
if (_s && _s.length) {
_s.forEach(s => {
syncs.push({
type: 'image',
url: s
})
})
}
}

if (syncOptions.pixelEnabled) {
serverResponses && serverResponses.length && serverResponses.forEach((response) => {
if (response.body) {
if (utils.isArray(response.body)) {
response.body.forEach(b => {
addSyncs(b.cookieURLs);
})
} else {
addSyncs(response.body.cookieURLs)
}
}
})
}
return syncs;
},
/**
* Make a server request from the list of BidRequests
* @param bidRequests
* @param bidderRequest
*/
buildRequests: function (bidRequests, bidderRequest) {
return {
data: bidToTag(bidRequests),
data: bidToTag(bidRequests, bidderRequest),
bidderRequest,
method: 'GET',
url: URL
Expand Down Expand Up @@ -83,11 +111,16 @@ function parseRTBResponse(serverResponse, bidderRequest) {
return bids;
}

function bidToTag(bidRequests) {
function bidToTag(bidRequests, bidderRequest) {
let tag = {
domain: utils.getTopWindowLocation().hostname
};

if (bidderRequest && bidderRequest.gdprConsent) {
tag.gdpr = 1;
tag.gdpr_consent = bidderRequest.gdprConsent.consentString;
}

for (let i = 0, length = bidRequests.length; i < length; i++) {
Object.assign(tag, prepareRTBRequestParams(i, bidRequests[i]));
}
Expand Down
22 changes: 9 additions & 13 deletions modules/adyoulikeBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export const spec = {
* @return ServerRequest Info describing the request to the server.
*/
buildRequests: function (bidRequests, bidderRequest) {
let dcHostname = getHostname(bidRequests);
const payload = {
Version: VERSION,
Bids: bidRequests.reduce((accumulator, bid) => {
Expand Down Expand Up @@ -60,7 +59,7 @@ export const spec = {

return {
method: 'POST',
url: createEndpoint(dcHostname),
url: createEndpoint(bidRequests, bidderRequest),
data,
options
};
Expand Down Expand Up @@ -94,14 +93,10 @@ function getHostname(bidderRequest) {
}

/* Get current page referrer url */
function getReferrerUrl() {
function getReferrerUrl(bidderRequest) {
let referer = '';
if (window.self !== window.top) {
try {
referer = window.top.document.referrer;
} catch (e) { }
} else {
referer = document.referrer;
if (bidderRequest && bidderRequest.refererInfo) {
referer = encodeURIComponent(bidderRequest.refererInfo.referer);
}
return referer;
}
Expand Down Expand Up @@ -134,20 +129,21 @@ function getPageRefreshed() {
}

/* Create endpoint url */
function createEndpoint(host) {
function createEndpoint(bidRequests, bidderRequest) {
let host = getHostname(bidRequests);
return format({
protocol: (document.location.protocol === 'https:') ? 'https' : 'http',
host: `${DEFAULT_DC}${host}.omnitagjs.com`,
pathname: '/hb-api/prebid/v1',
search: createEndpointQS()
search: createEndpointQS(bidderRequest)
});
}

/* Create endpoint query string */
function createEndpointQS() {
function createEndpointQS(bidderRequest) {
const qs = {};

const ref = getReferrerUrl();
const ref = getReferrerUrl(bidderRequest);
if (ref) {
qs.RefererUrl = encodeURIComponent(ref);
}
Expand Down
30 changes: 21 additions & 9 deletions modules/ajaBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,28 @@ export const spec = {

getUserSyncs: function(syncOptions, serverResponses) {
const syncs = [];
if (syncOptions.pixelEnabled && serverResponses.length) {
const bidderResponseBody = serverResponses[0].body;
if (bidderResponseBody.syncs) {
bidderResponseBody.syncs.forEach(sync => {
syncs.push({
type: 'image',
url: sync
});
if (!serverResponses.length) {
return syncs;
}

const bidderResponseBody = serverResponses[0].body;

if (syncOptions.pixelEnabled && bidderResponseBody.syncs) {
bidderResponseBody.syncs.forEach(sync => {
syncs.push({
type: 'image',
url: sync
});
}
});
}

if (syncOptions.iframeEnabled && bidderResponseBody.sync_htmls) {
bidderResponseBody.sync_htmls.forEach(sync => {
syncs.push({
type: 'iframe',
url: sync
});
});
}

return syncs;
Expand Down
Loading

0 comments on commit 53ac4fe

Please sign in to comment.