Skip to content

Commit

Permalink
Update v3 native bid shapes
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewlane committed May 5, 2017
1 parent 2d6da07 commit ef6c5c1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
19 changes: 15 additions & 4 deletions src/adapters/appnexusAst.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const VIDEO_TARGETING = ['id', 'mimes', 'minduration', 'maxduration',
'startdelay', 'skippable', 'playback_method', 'frameworks'];
const USER_PARAMS = ['age', 'external_uid', 'segments', 'gender', 'dnt',
'language'];
const NATIVE_MAPPING = {body: 'description', image: 'main_image'};

/**
* Bidder adapter for /ut endpoint. Given the list of all ad unit tag IDs,
Expand Down Expand Up @@ -77,8 +78,18 @@ function AppnexusAstAdapter() {
}

if (bid.mediaType === 'native') {
tag.native = {};
tag.native.layouts = [bid.nativeParams];
tag.ad_types = ["native"];

if (bid.nativeParams) {
const nativeRequest = {};

Object.keys(bid.nativeParams).forEach(key => {
let requestKey = NATIVE_MAPPING[key] || key;
nativeRequest[requestKey] = bid.nativeParams[key]
});

tag.native = {layouts: [nativeRequest]};
}
}

if (bid.mediaType === 'video') {
Expand Down Expand Up @@ -306,8 +317,8 @@ function AppnexusAstAdapter() {
const native = ad.rtb.native;
bid.native = {
title: native.title,
body: native.description,
sponsored_by: native.sponsored_by,
body: native.desc,
sponsored_by: native.sponsored,
image: native.main_img && native.main_img.url,
icon: native.icon && native.icon.url,
click_url: native.link.url,
Expand Down
9 changes: 6 additions & 3 deletions src/native.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,14 @@ export const hasNonNativeBidder = adUnit => adUnit.bids.filter(nonNativeBidder).
*/
export function nativeBidIsValid(bid) {
const bidRequest = getBidRequest(bid.adId);
if (!bidRequest || !bidRequest.nativeParams) {return false;}
if (!bidRequest) {return false;}

const requestedAssets = bidRequest.nativeParams;
const requiredAssets = Object.keys(requestedAssets)
.filter(key => requestedAssets[key].required);
if (!requestedAssets) {return true;}

const requiredAssets = Object.keys(requestedAssets).filter(
key => requestedAssets[key].required
);
const returnedAssets = Object.keys(bid.native);

return requiredAssets.every(asset => returnedAssets.includes(asset));
Expand Down
4 changes: 2 additions & 2 deletions test/spec/adapters/appnexusAst_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ describe('AppNexusAdapter', () => {
RESPONSE.tags[0].ads[0].ad_type = 'native';
RESPONSE.tags[0].ads[0].rtb.native = {
"title": "Native Creative",
"description": "Cool description great stuff",
"sponsored_by": "AppNexus",
"desc": "Cool description great stuff",
"sponsored": "AppNexus",
"icon": {
"width": 0,
"height": 0,
Expand Down

0 comments on commit ef6c5c1

Please sign in to comment.