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

Craft Bid Adapter : refactor adapter #12474

Closed
wants to merge 5 commits into from
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) {
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(serverBid);
if (bid) {
bids.push(bid);
}
} catch (e) {
// Do nothing
}
});
return bids;
}
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