Skip to content

Commit

Permalink
Updates to RDN Adapter (prebid#4080)
Browse files Browse the repository at this point in the history
* handle no bid in rdn adapter
  • Loading branch information
snapwich authored and sa1omon committed Nov 28, 2019
1 parent e45d733 commit bac0173
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 24 deletions.
49 changes: 26 additions & 23 deletions modules/rdnBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import * as utils from '../src/utils'
import { BANNER } from '../src/mediaTypes'
import { config } from '../src/config'

const BIDDER_CODE = 'rdn'
const ENDPOINT = 'https://s-bid.rmp.rakuten.co.jp/h'
const BIDDER_CODE = 'rdn';
const ENDPOINT = 'https://s-bid.rmp.rakuten.co.jp/h';

export const spec = {
code: BIDDER_CODE,
isBidRequestValid: bid => !!bid.params.adSpotId,
buildRequests: validBidRequests => {
const bidRequests = []
const bidRequests = [];
validBidRequests.forEach(bid => {
const params = bid.params
const params = bid.params;
bidRequests.push({
method: 'GET',
url: config.getConfig('rdn.endpoint') || ENDPOINT,
Expand All @@ -29,26 +29,29 @@ export const spec = {
pp: encodeURIComponent(utils.getTopWindowReferrer())
}
})
})
});
return bidRequests
},
interpretResponse: (response, request) => {
const sb = response.body
const bidResponses = []
bidResponses.push({
requestId: sb.bid_id,
cpm: sb.cpm || 0,
width: sb.width || 0,
height: sb.height || 0,
creativeId: sb.creative_id || 0,
dealId: sb.deal_id || '',
currency: sb.currency || 'JPY',
netRevenue: (sb.net_revenue === undefined) ? true : sb.net_revenue,
mediaType: BANNER,
ttl: sb.ttl,
referrer: utils.getTopWindowUrl(),
ad: sb.ad
})
const sb = response.body;
const bidResponses = [];

if (sb.cpm && sb.ad) {
bidResponses.push({
requestId: sb.bid_id,
cpm: sb.cpm,
width: sb.width || 0,
height: sb.height || 0,
creativeId: sb.creative_id || 0,
dealId: sb.deal_id || '',
currency: sb.currency || 'JPY',
netRevenue: (typeof sb.net_revenue === 'undefined') ? true : !!sb.net_revenue,
mediaType: BANNER,
ttl: sb.ttl,
referrer: utils.getTopWindowUrl(),
ad: sb.ad
});
}

return bidResponses
},
Expand All @@ -62,7 +65,7 @@ export const spec = {
}
if (bidResponseObj.sync_urls && bidResponseObj.sync_urls.length > 0) {
bidResponseObj.sync_urls.forEach(syncUrl => {
if (syncUrl && syncUrl != 'null' && syncUrl.length > 0) {
if (syncUrl && syncUrl !== 'null' && syncUrl.length > 0) {
syncs.push({
type: 'image',
url: syncUrl
Expand All @@ -75,4 +78,4 @@ export const spec = {
}
}

registerBidder(spec)
registerBidder(spec);
10 changes: 9 additions & 1 deletion test/spec/modules/rdnBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ describe('rdnBidAdapter', function() {

const serverResponse = {
noAd: [],
noAd2: {
requestId: 'biequa9oaph4we'
},
banner: {
requestId: 'biequa9oaph4we',
cpm: 37.66,
Expand All @@ -113,10 +116,15 @@ describe('rdnBidAdapter', function() {
it('handles nobid responses', () => {
const result = spec.interpretResponse(
{ body: serverResponse.noAd },
bidRequests.banner
);
expect(result.length).to.equal(0);

const result2 = spec.interpretResponse(
{ body: serverResponse.noAd2 },
bidRequests.banner
);
expect(result.length).to.equal(1)
expect(result2.length).to.equal(0);
})
});
describe('spec.getUserSyncs', function () {
Expand Down

0 comments on commit bac0173

Please sign in to comment.