Skip to content

Commit

Permalink
districtmDMX new adapter (prebid#2765)
Browse files Browse the repository at this point in the history
* adding DMX

test @97%, two files added one updated

* Update districtm_spec.js

* Update districtmDMX.js

* adding all districtm needed file

* remove legacy file

* remove typo || 0 in the test method

* force default to return a valid width and height

* update unit test code for failing test

* changed class for an object

* remove package-lock.json
  • Loading branch information
stevealliance authored and AlessandroDG committed Oct 2, 2018
1 parent 9b4e4c8 commit 81c9ff6
Show file tree
Hide file tree
Showing 3 changed files with 719 additions and 0 deletions.
155 changes: 155 additions & 0 deletions modules/districtmDmxAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
import * as utils from 'src/utils';
import { registerBidder } from 'src/adapters/bidderFactory';
import {config} from 'src/config';

const BIDDER_CODE = 'districtmDMX';

const DMXURI = 'https://dmx.districtm.io/b/v1';

export const spec = {
code: BIDDER_CODE,
supportedFormat: ['banner'],
isBidRequestValid(bid) {
return !!(bid.params.dmxid && bid.params.memberid);
},
interpretResponse(response, bidRequest) {
response = response.body || {};
if (response.seatbid) {
if (utils.isArray(response.seatbid)) {
const {seatbid} = response;
let winners = seatbid.reduce((bid, ads) => {
let ad = ads.bid.reduce(function(oBid, nBid) {
if (oBid.price < nBid.price) {
const bid = matchRequest(nBid.impid, bidRequest);
const {width, height} = defaultSize(bid);
nBid.cpm = nBid.price;
nBid.bidId = nBid.impid;
nBid.requestId = nBid.impid;
nBid.width = nBid.w || width;
nBid.height = nBid.h || height;
nBid.ad = nBid.adm;
nBid.netRevenue = true;
nBid.creativeId = nBid.crid;
nBid.currency = 'USD';
nBid.ttl = 60;

return nBid;
} else {
oBid.cpm = oBid.price;
return oBid;
}
}, {price: 0});
if (ad.adm) {
bid.push(ad)
}
return bid;
}, [])
let winnersClean = winners.filter(w => {
if (w.bidId) {
return true;
}
return false;
});
return winnersClean;
} else {
return [];
}
} else {
return [];
}
},
buildRequests(bidRequest, bidderRequest) {
let timeout = config.getConfig('bidderTimeout');
let dmxRequest = {
id: utils.generateUUID(),
cur: ['USD'],
tmax: (timeout - 300),
test: this.test() || 0,
site: {
publisher: { id: String(bidRequest[0].params.memberid) || null }
}
}
if (!dmxRequest.test) {
delete dmxRequest.test;
}
if (bidderRequest.gdprConsent) {
dmxRequest.regs = {};
dmxRequest.regs.ext = {};
dmxRequest.regs.ext.gdpr = bidderRequest.gdprConsent.gdprApplies === true ? 1 : 0;
if (dmxRequest.regs.ext.gdpr) {
dmxRequest.regs.ext.consent = bidderRequest.gdprConsent.consentString;
}
}
let tosendtags = bidRequest.map(dmx => {
var obj = {};
obj.id = dmx.bidId;
obj.tagid = String(dmx.params.dmxid);
obj.secure = window.location.protocol === 'https:' ? 1 : 0;
obj.banner = {
topframe: 1,
w: dmx.sizes[0][0] || 0,
h: dmx.sizes[0][1] || 0,
format: dmx.sizes.map(s => {
return {w: s[0], h: s[1]};
})
};
return obj;
});
dmxRequest.imp = tosendtags;
return {
method: 'POST',
url: DMXURI,
data: JSON.stringify(dmxRequest),
options: {
contentType: 'application/json',
withCredentials: true
},
bidderRequest
}
},
test() {
return window.location.href.indexOf('dmTest=true') !== -1 ? 1 : 0;
},
getUserSyncs(optionsType) {
if (optionsType.iframeEnabled) {
return [{
type: 'iframe',
url: 'https://cdn.districtm.io/ids/index.html'
}];
}
}
}

/**
* Function matchRequest(id: string, BidRequest: object)
* @param id
* @type string
* @param bidRequest
* @type Object
* @returns Object
*
*/
export function matchRequest(id, bidRequest) {
const {bids} = bidRequest.bidderRequest;
const [returnValue] = bids.filter(bid => bid.bidId === id);
return returnValue;
}
export function checkDeepArray(Arr) {
if (Array.isArray(Arr)) {
if (Array.isArray(Arr[0])) {
return Arr[0];
} else {
return Arr;
}
} else {
return Arr;
}
}
export function defaultSize(thebidObj) {
const {sizes} = thebidObj;
const returnObject = {};
returnObject.width = checkDeepArray(sizes)[0];
returnObject.height = checkDeepArray(sizes)[1];
return returnObject;
}
registerBidder(spec);
31 changes: 31 additions & 0 deletions modules/districtmDmxAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Overview

```
Module Name: DistrictM Bid Adapter
Module Type: Bidder Adapter
Maintainer: steve@districtm.net
```

# Description

Adapter that connects to DistrictM's demand sources.
This version only support banner

# Test Parameters
```
var adUnits = [{
code: 'div-gpt-ad-1460505748561-0',
mediaTypes: {
banner: {
sizes: [[300, 250], [300,600]],
}
},
bids: [{
bidder: 'districtmDMX',
params: {
dmxid: 100001,
memberid: 100003
}
}]
}];
```
Loading

0 comments on commit 81c9ff6

Please sign in to comment.