Skip to content

Commit

Permalink
CPMStar Bid Adapter : change request method to post & added data to e…
Browse files Browse the repository at this point in the history
…ndpoint (prebid#8810)

* added cpmstarBidAdapter with meta.advertiserDomains support

* fix linting

* Updated modules/cpmstarBidAdapter: Changed request method to post and included the mediaType.video and adUnitCode data to the request body.

Co-authored-by: Chris Huie <phoenixtechnerd@gmail.com>
Co-authored-by: = <=>
  • Loading branch information
JoshuaMGoldstein and ChrisHuie authored Aug 15, 2022
1 parent 902cfc0 commit 335a907
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
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

0 comments on commit 335a907

Please sign in to comment.