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

CPMStar Bid Adapter : change request method to post & added data to endpoint #8810

Merged
merged 4 commits into from
Aug 15, 2022
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
32 changes: 21 additions & 11 deletions modules/cpmstarBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { deepAccess, getBidIdParameter, logWarn, logError } from '../src/utils.js';

import * as utils from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { VIDEO, BANNER } from '../src/mediaTypes.js';
import { config } from '../src/config.js';
Expand All @@ -25,11 +26,11 @@ export const spec = {

getMediaType: function (bidRequest) {
if (bidRequest == null) return BANNER;
return !deepAccess(bidRequest, 'mediaTypes.video') ? BANNER : VIDEO;
return !utils.deepAccess(bidRequest, 'mediaTypes.video') ? BANNER : VIDEO;
},

getPlayerSize: function (bidRequest) {
var playerSize = deepAccess(bidRequest, 'mediaTypes.video.playerSize');
var playerSize = utils.deepAccess(bidRequest, 'mediaTypes.video.playerSize');
if (playerSize == null) return [640, 440];
if (playerSize[0] != null) playerSize = playerSize[0];
if (playerSize == null || playerSize[0] == null || playerSize[1] == null) return [640, 440];
Expand All @@ -46,15 +47,14 @@ export const spec = {

for (var i = 0; i < validBidRequests.length; i++) {
var bidRequest = validBidRequests[i];
// TODO: is 'page' the right value here?
var referer = encodeURIComponent(bidderRequest.refererInfo.page);
var e = getBidIdParameter('endpoint', bidRequest.params);
var referer = encodeURIComponent(bidderRequest.refererInfo.referer);
var e = utils.getBidIdParameter('endpoint', bidRequest.params);
var ENDPOINT = e == 'dev' ? ENDPOINT_DEV : e == 'staging' ? ENDPOINT_STAGING : ENDPOINT_PRODUCTION;
var mediaType = spec.getMediaType(bidRequest);
var playerSize = spec.getPlayerSize(bidRequest);
var videoArgs = '&fv=0' + (playerSize ? ('&w=' + playerSize[0] + '&h=' + playerSize[1]) : '');
var url = ENDPOINT + '?media=' + mediaType + (mediaType == VIDEO ? videoArgs : '') +
'&json=c_b&mv=1&poolid=' + getBidIdParameter('placementId', bidRequest.params) +
'&json=c_b&mv=1&poolid=' + utils.getBidIdParameter('placementId', bidRequest.params) +
'&reachedTop=' + encodeURIComponent(bidderRequest.refererInfo.reachedTop) +
'&requestid=' + bidRequest.bidId +
'&referer=' + encodeURIComponent(referer);
Expand Down Expand Up @@ -93,10 +93,20 @@ export const spec = {
url += '&tfcd=' + (config.getConfig('coppa') ? 1 : 0);
}

let body = {};
let adUnitCode = bidRequest.adUnitCode;
if (adUnitCode) {
body.adUnitCode = adUnitCode;
}
if (mediaType == VIDEO) {
body.video = utils.deepAccess(bidRequest, 'mediaTypes.video');
}

requests.push({
method: 'GET',
method: 'POST',
url: url,
bidRequest: bidRequest,
data: body
});
}

Expand All @@ -117,13 +127,13 @@ export const spec = {
var raw = serverResponse.body[i];
var rawBid = raw.creatives[0];
if (!rawBid) {
logWarn('cpmstarBidAdapter: server response failed check');
utils.logWarn('cpmstarBidAdapter: server response failed check');
return;
}
var cpm = (parseFloat(rawBid.cpm) || 0);

if (!cpm) {
logWarn('cpmstarBidAdapter: server response failed check. Missing cpm')
utils.logWarn('cpmstarBidAdapter: server response failed check. Missing cpm')
return;
}

Expand Down Expand Up @@ -156,7 +166,7 @@ export const spec = {
bidResponse.mediaType = VIDEO;
bidResponse.vastXml = rawBid.creativemacros.HTML5VID_VASTSTRING;
} else {
return logError('bad response', rawBid);
return utils.logError('bad response', rawBid);
}

bidResponses.push(bidResponse);
Expand Down
2 changes: 1 addition & 1 deletion test/spec/modules/cpmstarBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const valid_bid_requests = [{

const bidderRequest = {
refererInfo: {
page: 'referer',
referer: 'referer',
reachedTop: false,
}
};
Expand Down