Skip to content

Commit

Permalink
Adding support for all AST parameters (#923)
Browse files Browse the repository at this point in the history
* Adding support for all AST parameters

* adding braces on if

* changing memberId into member to match AST doc
  • Loading branch information
jdelhommeau authored and Matt Kendall committed Jan 16, 2017
1 parent 5358744 commit 32fcc76
Showing 1 changed file with 38 additions and 4 deletions.
42 changes: 38 additions & 4 deletions src/adapters/appnexusAst.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function AppnexusAstAdapter() {
/* Prebid executes this function when the page asks to send out bid requests */
baseAdapter.callBids = function(bidRequest) {
const bids = bidRequest.bids || [];
var member = 0;
const tags = bids
.filter(bid => valid(bid))
.map(bid => {
Expand All @@ -36,10 +37,39 @@ function AppnexusAstAdapter() {
tag.sizes = getSizes(bid.sizes);
tag.primary_size = tag.sizes[0];
tag.uuid = bid.bidId;
tag.id = parseInt(bid.params.placementId, 10);
if(bid.params.placementId) {
tag.id = parseInt(bid.params.placementId, 10);
} else {
tag.code = bid.params.invCode;
}
tag.allow_smaller_sizes = bid.params.allowSmallerSizes || false;
tag.prebid = true;
tag.disable_psa = true;
member = parseInt(bid.params.member, 10);
if (bid.params.reserve) {
tag.reserve = bid.params.reserve;
}
if (bid.params.position) {
tag.position = {'above': 1, 'below': 2}[bid.params.position] || 0;
}
if (bid.params.trafficSourceCode) {
tag.traffic_source_code = bid.params.trafficSourceCode;
}
if (bid.params.privateSizes) {
tag.private_sizes = getSizes(bid.params.privateSizes);
}
if (bid.params.supplyType) {
tag.supply_type = bid.params.supplyType;
}
if (bid.params.pubClick) {
tag.pubclick = bid.params.pubClick;
}
if (bid.params.extInvCode) {
tag.ext_inv_code = bid.params.extInvCode;
}
if (bid.params.externalImpId) {
tag.external_imp_id = bid.params.externalImpId;
}
if (!utils.isEmpty(bid.params.keywords)) {
tag.keywords = getKeywords(bid.params.keywords);
}
Expand All @@ -64,7 +94,11 @@ function AppnexusAstAdapter() {
});

if (!utils.isEmpty(tags)) {
const payload = JSON.stringify({tags: [...tags]});
const payloadJson = {tags: [...tags]};
if (member > 0) {
payloadJson.member_id = member;
}
const payload = JSON.stringify(payloadJson);
ajax(ENDPOINT, handleResponse, payload, {
contentType: 'text/plain',
withCredentials : true
Expand Down Expand Up @@ -133,10 +167,10 @@ function AppnexusAstAdapter() {

/* Check that a bid has required paramters */
function valid(bid) {
if (bid.params.placementId || bid.params.memberId && bid.params.invCode) {
if (bid.params.placementId || bid.params.member && bid.params.invCode) {
return bid;
} else {
utils.logError('bid requires placementId or (memberId and invCode) params');
utils.logError('bid requires placementId or (member and invCode) params');
}
}

Expand Down

0 comments on commit 32fcc76

Please sign in to comment.