Skip to content

Commit

Permalink
Orbitsoft Bid Adapter : add adapter back to current version (prebid#9288
Browse files Browse the repository at this point in the history
)

* Adding Orbitsoft module

* Adding Orbitsoft module (corrected)

* Adding Orbitsoft module (correction of remarks)

* Adding Orbitsoft module (correction of remarks)

* Adding Orbitsoft module (correction to alias-able)

* Adding Orbitsoft module (correction to alias-able)

* Adding Orbitsoft module (correction to alias-able)

* Adding Orbitsoft module (correction to alias-able)

* Adding Orbitsoft module (correction to new constructor)

* Adding Orbitsoft module (delete unnecessary aliases)

* Adding Orbitsoft module (delete unnecessary aliases)

* fixed orbitsoftAdapter

* fixed orbitsoftAdapter processing undefined request referrer

* fixed orbitsoftAdapter processing undefined request referrer

* fix-orbitsoftAdaper: codereview fixes

* added changes for new spec

* added changes for new spec

* added changes for new spec

Co-authored-by: Dmitriy Shimko <dmitriy.shimko@orbitsoft.com>
Co-authored-by: Хатламаджиян Виталий <vitaly.khatlamadzhiyan@orbitsoft.com>
  • Loading branch information
3 people authored and jorgeluisrocha committed May 18, 2023
1 parent e149bba commit f644b09
Show file tree
Hide file tree
Showing 2 changed files with 405 additions and 0 deletions.
150 changes: 150 additions & 0 deletions modules/orbitsoftBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
import * as utils from '../src/utils.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {config} from '../src/config.js';

const BIDDER_CODE = 'orbitsoft';
let styleParamsMap = {
'title.family': 'f1', // headerFont
'title.size': 'fs1', // headerFontSize
'title.weight': 'w1', // headerWeight
'title.style': 's1', // headerStyle
'title.color': 'c3', // headerColor
'description.family': 'f2', // descriptionFont
'description.size': 'fs2', // descriptionFontSize
'description.weight': 'w2', // descriptionWeight
'description.style': 's2', // descriptionStyle
'description.color': 'c4', // descriptionColor
'url.family': 'f3', // urlFont
'url.size': 'fs3', // urlFontSize
'url.weight': 'w3', // urlWeight
'url.style': 's3', // urlStyle
'url.color': 'c5', // urlColor
'colors.background': 'c2', // borderColor
'colors.border': 'c1', // borderColor
'colors.link': 'c6', // lnkColor
};
export const spec = {
code: BIDDER_CODE,
aliases: ['oas', '152media'], // short code and customer aliases
isBidRequestValid: function (bid) {
switch (true) {
case !('params' in bid):
utils.logError(bid.bidder + ': No required params');
return false;
case !(bid.params.placementId):
utils.logError(bid.bidder + ': No required param placementId');
return false;
case !(bid.params.requestUrl):
utils.logError(bid.bidder + ': No required param requestUrl');
return false;
}
return true;
},
buildRequests: function (validBidRequests) {
let bidRequest;
let serverRequests = [];
for (let i = 0; i < validBidRequests.length; i++) {
bidRequest = validBidRequests[i];
let bidRequestParams = bidRequest.params;
let placementId = utils.getBidIdParameter('placementId', bidRequestParams);
let requestUrl = utils.getBidIdParameter('requestUrl', bidRequestParams);
let referrer = utils.getBidIdParameter('ref', bidRequestParams);
let location = utils.getBidIdParameter('loc', bidRequestParams);
// Append location & referrer
if (location === '') {
location = utils.getWindowLocation();
}
if (referrer === '' && bidRequest && bidRequest.refererInfo) {
referrer = bidRequest.refererInfo.referer;
}

// Styles params
let stylesParams = utils.getBidIdParameter('style', bidRequestParams);
let stylesParamsArray = {};
for (let currentValue in stylesParams) {
if (stylesParams.hasOwnProperty(currentValue)) {
let currentStyle = stylesParams[currentValue];
for (let field in currentStyle) {
if (currentStyle.hasOwnProperty(field)) {
let styleField = styleParamsMap[currentValue + '.' + field];
if (typeof styleField !== 'undefined') {
stylesParamsArray[styleField] = currentStyle[field];
}
}
}
}
}
// Custom params
let customParams = utils.getBidIdParameter('customParams', bidRequestParams);
let customParamsArray = {};
for (let customField in customParams) {
if (customParams.hasOwnProperty(customField)) {
customParamsArray['c.' + customField] = customParams[customField];
}
}

// Sizes params (not supports by server, for future features)
let sizesParams = bidRequest.sizes;
let parsedSizes = utils.parseSizesInput(sizesParams);
let requestData = Object.assign({
'scid': placementId,
'callback_uid': utils.generateUUID(),
'loc': location,
'ref': referrer,
'size': parsedSizes
}, stylesParamsArray, customParamsArray);

serverRequests.push({
method: 'POST',
url: requestUrl,
data: requestData,
options: {withCredentials: false},
bidRequest: bidRequest
});
}
return serverRequests;
},
interpretResponse: function (serverResponse, request) {
let bidResponses = [];
if (!serverResponse || serverResponse.error) {
utils.logError(BIDDER_CODE + ': Server response error');
return bidResponses;
}

const serverBody = serverResponse.body;
if (!serverBody) {
utils.logError(BIDDER_CODE + ': Empty bid response');
return bidResponses;
}

const CPM = serverBody.cpm;
const WIDTH = serverBody.width;
const HEIGHT = serverBody.height;
const CREATIVE = serverBody.content_url;
const CALLBACK_UID = serverBody.callback_uid;
const TIME_TO_LIVE = config.getConfig('_bidderTimeout');
const REFERER = utils.getWindowTop();
let bidRequest = request.bidRequest;
if (CPM > 0 && WIDTH > 0 && HEIGHT > 0) {
let bidResponse = {
requestId: bidRequest.bidId,
cpm: CPM,
width: WIDTH,
height: HEIGHT,
creativeId: CALLBACK_UID,
ttl: TIME_TO_LIVE,
referrer: REFERER,
currency: 'USD',
netRevenue: true,
adUrl: CREATIVE,
meta: {
advertiserDomains: serverBody.adomain ? serverBody.adomain : []
}
};
bidResponses.push(bidResponse);
}

return bidResponses;
}
};
registerBidder(spec);
Loading

0 comments on commit f644b09

Please sign in to comment.