Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

33Across Adapter: Removed the usage of utils library #1917

Merged
merged 5 commits into from
Dec 6, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 26 additions & 33 deletions modules/33acrossBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { registerBidder } = require('../src/adapters/bidderFactory');
const utils = require('../src/utils');
const { userSync } = require('../src/userSync');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do import over here. import { userSync } from 'src/userSync';
This will make sure it imports same object https://github.com/prebid/Prebid.js/blob/master/src/userSync.js#L189

const { config } = require('../src/config');

const BIDDER_CODE = '33across';
const END_POINT = 'https://ssc.33across.com/api/v1/hb';
Expand Down Expand Up @@ -38,9 +39,7 @@ function _createServerRequest(bidRequest) {
}
}

// Allowing site to be a test configuration object or just the id (former required for testing,
// latter when used by publishers)
ttxRequest.site = params.site || { id: params.siteId };
ttxRequest.site = { id: params.siteId };

// Go ahead send the bidId in request to 33exchange so it's kept track of in the bid response and
// therefore in ad targetting process
Expand All @@ -51,28 +50,18 @@ function _createServerRequest(bidRequest) {
withCredentials: false
};

if (bidRequest.params.customHeaders) {
options.customHeaders = bidRequest.params.customHeaders;
}
// Allow the ability to configure the HB endpoint for testing purposes.
const ttxSettings = config.getConfig('ttxSettings');
const url = (ttxSettings && ttxSettings.url) || END_POINT;

return {
'method': 'POST',
'url': bidRequest.params.url || END_POINT,
'url': url,
'data': JSON.stringify(ttxRequest),
'options': options
}
}

// Sync object will always be of type iframe for ttx
function _createSync(bid) {
const syncUrl = bid.params.syncUrl || SYNC_ENDPOINT;

return {
type: 'iframe',
url: `${syncUrl}&id=${bid.params.siteId || bid.params.site.id}`
}
}

function _getFormatSize(sizeArr) {
return {
w: sizeArr[0],
Expand All @@ -81,6 +70,18 @@ function _getFormatSize(sizeArr) {
}
}

// Register one sync per bid since each ad unit may potenitally be linked to a uniqe guid
// Sync type will always be 'iframe' for 33Across
function _registerUserSyncs(requestData) {
const ttxRequest = JSON.parse(requestData);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrap JSON.parse in try..catch.

const ttxSettings = config.getConfig('ttxSettings');

let syncUrl = (ttxSettings && ttxSettings.syncUrl) || SYNC_ENDPOINT;

syncUrl = `${syncUrl}&id=${ttxRequest.site.id}`;
userSync.registerSync('iframe', BIDDER_CODE, syncUrl);
}

function isBidRequestValid(bid) {
if (bid.bidder !== BIDDER_CODE || typeof bid.params === 'undefined') {
return false;
Expand All @@ -104,7 +105,12 @@ function buildRequests(bidRequests) {
}

// NOTE: At this point, the response from 33exchange will only ever contain one bid i.e. the highest bid
function interpretResponse(serverResponse) {
function interpretResponse(serverResponse, bidRequest) {
// Register user sync first
if (bidRequest && bidRequest.data) {
_registerUserSyncs(bidRequest.data);
}

const bidResponses = [];

// If there are bids, look at the first bid of the first seatbid (see NOTE above for assumption about ttx)
Expand All @@ -115,24 +121,11 @@ function interpretResponse(serverResponse) {
return bidResponses;
}

// Register one sync per bid since each ad unit may potenitally be linked to a uniqe guid
function getUserSyncs(syncOptions) {
let syncs = [];
const ttxBidRequests = utils.getBidderRequestAllAdUnits(BIDDER_CODE).bids;

if (syncOptions.iframeEnabled) {
syncs = ttxBidRequests.map(_createSync);
}

return syncs;
}

const spec = {
code: BIDDER_CODE,
isBidRequestValid,
buildRequests,
interpretResponse,
getUserSyncs
interpretResponse
}

registerBidder(spec);
Expand Down
Loading