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 all 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
65 changes: 32 additions & 33 deletions modules/33acrossBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { userSync } from 'src/userSync'
const { registerBidder } = require('../src/adapters/bidderFactory');
const utils = require('../src/utils');
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,24 @@ 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) {
let ttxRequest;
try {
ttxRequest = JSON.parse(requestData);
} catch (err) {
// No point in trying to register sync since the requisite data cannot be parsed.
return;
}
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 +111,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 +127,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