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

Refactor craft bidder and adrelevantis bid adapter #12473

Closed
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
22 changes: 22 additions & 0 deletions libraries/interpretResponseUtils/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {logError} from '../../src/utils.js';

export function interpretResponseUtil(serverResponse, {bidderRequest}, eachBidCallback) {
serverResponse = serverResponse.body;
const bids = [];
if (!serverResponse.body || serverResponse.body.error) {
let errorMessage = `in response for ${bidderRequest.bidderCode} adapter`;
if (serverResponse.body && serverResponse.body.error) { errorMessage += `: ${serverResponse.body.error}`; }
logError(errorMessage);
return bids;
}
(serverResponse.body.tags || []).forEach(serverBid => {
try {
const bid = eachBidCallback();
if (bid) {
bids.push(bid);
}
} catch (e) {
// Do nothing
}
});
}
29 changes: 10 additions & 19 deletions modules/adrelevantisBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {INSTREAM, OUTSTREAM} from '../src/video.js';
import { convertOrtbRequestToProprietaryNative } from '../src/native.js';
import {getANKeywordParam} from '../libraries/appnexusUtils/anKeywords.js';
import {chunk} from '../libraries/chunk/chunk.js';
import {interpretResponseUtil} from '../libraries/interpretResponseUtils/index.js';

/**
* @typedef {import('../src/adapters/bidderFactory.js').BidRequest} BidRequest
Expand Down Expand Up @@ -162,29 +163,19 @@ export const spec = {
* @return {Bid[]} An array of bids which were nested inside the server.
*/
interpretResponse: function(serverResponse, {bidderRequest}) {
serverResponse = serverResponse.body;
const bids = [];
if (!serverResponse || serverResponse.error) {
let errorMessage = `in response for ${bidderRequest.bidderCode} adapter`;
if (serverResponse && serverResponse.error) { errorMessage += `: ${serverResponse.error}`; }
logError(errorMessage);
return bids;
}

if (serverResponse.tags) {
serverResponse.tags.forEach(serverBid => {
try {
const bids = interpretResponseUtil(serverResponse, {bidderRequest}, serverBid => {
const rtbBid = getRtbBid(serverBid);
if (rtbBid) {
if (rtbBid.cpm !== 0 && includes(this.supportedMediaTypes, rtbBid.ad_type)) {
const bid = newBid(serverBid, rtbBid, bidderRequest);
bid.mediaType = parseMediaType(rtbBid);
bids.push(bid);
}
if (rtbBid && rtbBid.cpm !== 0 && includes(this.supportedMediaTypes, rtbBid.ad_type)) {
const bid = newBid(serverBid, rtbBid, bidderRequest);
bid.mediaType = parseMediaType(rtbBid);
return bid;
}
});
return bids;
} catch (e) {
return [];
}

return bids;
}
};

Expand Down
34 changes: 9 additions & 25 deletions modules/craftBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {getBidRequest, logError} from '../src/utils.js';
import {getBidRequest} from '../src/utils.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {BANNER, NATIVE, VIDEO} from '../src/mediaTypes.js';
import {find, includes} from '../src/polyfill.js';
Expand All @@ -7,6 +7,7 @@ import {ajax} from '../src/ajax.js';
import {hasPurpose1Consent} from '../src/utils/gdpr.js';
import {convertOrtbRequestToProprietaryNative} from '../src/native.js';
import {getANKeywordParam} from '../libraries/appnexusUtils/anKeywords.js';
import {interpretResponseUtil} from '../libraries/interpretResponseUtils/index.js';

const BIDDER_CODE = 'craft';
const URL_BASE = 'https://gacraft.jp/prebid-v3';
Expand Down Expand Up @@ -68,31 +69,14 @@ export const spec = {

interpretResponse: function(serverResponse, {bidderRequest}) {
try {
serverResponse = serverResponse.body;
const bids = [];
if (!serverResponse) {
return [];
}
if (serverResponse.error) {
let errorMessage = `in response for ${bidderRequest.bidderCode} adapter`;
if (serverResponse.error) {
errorMessage += `: ${serverResponse.error}`;
const bids = interpretResponseUtil(serverResponse, {bidderRequest}, serverBid => {
const rtbBid = getRtbBid(serverBid);
if (rtbBid && rtbBid.cpm !== 0 && includes(this.supportedMediaTypes, rtbBid.ad_type)) {
const bid = newBid(serverBid, rtbBid, bidderRequest);
bid.mediaType = parseMediaType(rtbBid);
return bid;
}
logError(errorMessage);
return bids;
}
if (serverResponse.tags) {
serverResponse.tags.forEach(serverBid => {
const rtbBid = getRtbBid(serverBid);
if (rtbBid) {
if (rtbBid.cpm !== 0 && includes(this.supportedMediaTypes, rtbBid.ad_type)) {
const bid = newBid(serverBid, rtbBid, bidderRequest);
bid.mediaType = parseMediaType(rtbBid);
bids.push(bid);
}
}
});
}
});
return bids;
} catch (e) {
return [];
Expand Down
Loading