Skip to content

Commit 955f399

Browse files
GalphimblJustas Pupelis
authored and
Justas Pupelis
committed
Upgrade Admixer adapter for Prebid 1.0 (prebid#1755)
* Migrating to Prebid 1.0 * Migrating to Prebid 1.0 * Fix spec
1 parent d4712be commit 955f399

File tree

3 files changed

+243
-0
lines changed

3 files changed

+243
-0
lines changed

modules/admixerBidAdapter.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import * as utils from 'src/utils';
2+
import {registerBidder} from 'src/adapters/bidderFactory';
3+
4+
const BIDDER_CODE = 'admixer';
5+
const ENDPOINT_URL = '//inv-nets.admixer.net/prebid.1.0.aspx';
6+
export const spec = {
7+
code: BIDDER_CODE,
8+
aliases: [],
9+
supportedMediaTypes: ['banner', 'video'],
10+
/**
11+
* Determines whether or not the given bid request is valid.
12+
*
13+
* @param {BidRequest} bid The bid params to validate.
14+
* @return boolean True if this is a valid bid, and false otherwise.
15+
*/
16+
isBidRequestValid: function (bid) {
17+
return !!bid.params.zone;
18+
},
19+
/**
20+
* Make a server request from the list of BidRequests.
21+
*
22+
* @param {bidderRequest} - bidderRequest.bids[] is an array of AdUnits and bids
23+
* @return ServerRequest Info describing the request to the server.
24+
*/
25+
buildRequests: function (bidderRequest) {
26+
const payload = {
27+
imps: [],
28+
referrer: utils.getTopWindowUrl(),
29+
};
30+
bidderRequest.forEach((bid) => {
31+
if (bid.bidder === BIDDER_CODE) {
32+
payload.imps.push(bid);
33+
}
34+
});
35+
const payloadString = JSON.stringify(payload);
36+
return {
37+
method: 'GET',
38+
url: ENDPOINT_URL,
39+
data: `data=${payloadString}`,
40+
};
41+
},
42+
/**
43+
* Unpack the response from the server into a list of bids.
44+
*
45+
* @param {*} serverResponse A successful response from the server.
46+
* @return {Bid[]} An array of bids which were nested inside the server.
47+
*/
48+
interpretResponse: function (serverResponse, bidRequest) {
49+
const bidResponses = [];
50+
// loop through serverResponses {
51+
try {
52+
serverResponse = serverResponse.body;
53+
serverResponse.forEach((bidResponse) => {
54+
const bidResp = {
55+
requestId: bidResponse.bidId,
56+
cpm: bidResponse.cpm,
57+
width: bidResponse.width,
58+
height: bidResponse.height,
59+
ad: bidResponse.ad,
60+
ttl: bidResponse.ttl,
61+
creativeId: bidResponse.creativeId,
62+
netRevenue: bidResponse.netRevenue,
63+
currency: bidResponse.currency,
64+
vastUrl: bidResponse.vastUrl,
65+
};
66+
bidResponses.push(bidResp);
67+
});
68+
} catch (e) {
69+
utils.logError(e);
70+
}
71+
return bidResponses;
72+
}
73+
};
74+
registerBidder(spec);

modules/admixerBidAdapter.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Overview
2+
3+
Module Name: Admixer Bidder Adapter
4+
Module Type: Bidder Adapter
5+
Maintainer: [email protected]
6+
7+
# Description
8+
9+
Connects to Admixer demand source to fetch bids.
10+
Banner and Video formats are supported.
11+
Please use ```admixer``` as the bidder code.
12+
13+
# Test Parameters
14+
```
15+
var adUnits = [
16+
{
17+
code: 'desktop-banner-ad-div',
18+
sizes: [[300, 250]], // a display size
19+
bids: [
20+
{
21+
bidder: "admixer",
22+
params: {
23+
zone: '2eb6bd58-865c-47ce-af7f-a918108c3fd2'
24+
}
25+
}
26+
]
27+
},{
28+
code: 'mobile-banner-ad-div',
29+
sizes: [[300, 50]], // a mobile size
30+
bids: [
31+
{
32+
bidder: "admixer",
33+
params: {
34+
zone: '62211486-c50b-4356-9f0f-411778d31fcc'
35+
}
36+
}
37+
]
38+
},{
39+
code: 'video-ad',
40+
sizes: [[300, 50]],
41+
mediaType: 'video',
42+
bids: [
43+
{
44+
bidder: "admixer",
45+
params: {
46+
zone: 'ebeb1e79-8cb4-4473-b2d0-2e24b7ff47fd'
47+
}
48+
}
49+
]
50+
},
51+
];
52+
```
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
import {expect} from 'chai';
2+
import {spec} from 'modules/admixerBidAdapter';
3+
import {newBidder} from 'src/adapters/bidderFactory';
4+
5+
const BIDDER_CODE = 'admixer';
6+
const ENDPOINT_URL = '//inv-nets.admixer.net/prebid.1.0.aspx';
7+
const ZONE_ID = '2eb6bd58-865c-47ce-af7f-a918108c3fd2';
8+
9+
describe('AdmixerAdapter', () => {
10+
const adapter = newBidder(spec);
11+
12+
describe('inherited functions', () => {
13+
it('exists and is a function', () => {
14+
expect(adapter.callBids).to.be.exist.and.to.be.a('function');
15+
});
16+
});
17+
18+
describe('isBidRequestValid', () => {
19+
let bid = {
20+
'bidder': BIDDER_CODE,
21+
'params': {
22+
'zone': ZONE_ID
23+
},
24+
'adUnitCode': 'adunit-code',
25+
'sizes': [[300, 250], [300, 600]],
26+
'bidId': '30b31c1838de1e',
27+
'bidderRequestId': '22edbae2733bf6',
28+
'auctionId': '1d1a030790a475',
29+
};
30+
31+
it('should return true when required params found', () => {
32+
expect(spec.isBidRequestValid(bid)).to.equal(true);
33+
});
34+
35+
it('should return false when required params are not passed', () => {
36+
let bid = Object.assign({}, bid);
37+
delete bid.params;
38+
bid.params = {
39+
'placementId': 0
40+
};
41+
expect(spec.isBidRequestValid(bid)).to.equal(false);
42+
});
43+
});
44+
45+
describe('buildRequests', () => {
46+
let bidRequests = [
47+
{
48+
'bidder': BIDDER_CODE,
49+
'params': {
50+
'zone': ZONE_ID
51+
},
52+
'adUnitCode': 'adunit-code',
53+
'sizes': [[300, 250], [300, 600]],
54+
'bidId': '30b31c1838de1e',
55+
'bidderRequestId': '22edbae2733bf6',
56+
'auctionId': '1d1a030790a475',
57+
}
58+
];
59+
60+
it('should add referrer and imp to be equal bidRequest', () => {
61+
const request = spec.buildRequests(bidRequests);
62+
const payload = JSON.parse(request.data.substr(5));
63+
expect(payload.referrer).to.not.be.undefined;
64+
expect(payload.imps[0]).to.deep.equal(bidRequests[0]);
65+
});
66+
67+
it('sends bid request to ENDPOINT via GET', () => {
68+
const request = spec.buildRequests(bidRequests);
69+
expect(request.url).to.equal(ENDPOINT_URL);
70+
expect(request.method).to.equal('GET');
71+
});
72+
});
73+
74+
describe('interpretResponse', () => {
75+
let response = {
76+
body: [{
77+
'currency': 'USD',
78+
'cpm': 6.210000,
79+
'ad': '<div>ad</div>',
80+
'width': 300,
81+
'height': 600,
82+
'creativeId': 'ccca3e5e-0c54-4761-9667-771322fbdffc',
83+
'ttl': 360,
84+
'netRevenue': false,
85+
'bidId': '5e4e763b6bc60b'
86+
}]
87+
};
88+
89+
it('should get correct bid response', () => {
90+
const body = response.body;
91+
let expectedResponse = [
92+
{
93+
'requestId': body[0].bidId,
94+
'cpm': body[0].cpm,
95+
'creativeId': body[0].creativeId,
96+
'width': body[0].width,
97+
'height': body[0].height,
98+
'ad': body[0].ad,
99+
'vastUrl': undefined,
100+
'currency': body[0].currency,
101+
'netRevenue': body[0].netRevenue,
102+
'ttl': body[0].ttl,
103+
}
104+
];
105+
106+
let result = spec.interpretResponse(response);
107+
expect(result[0]).to.deep.equal(expectedResponse[0]);
108+
});
109+
110+
it('handles nobid responses', () => {
111+
let response = [];
112+
113+
let result = spec.interpretResponse(response);
114+
expect(result.length).to.equal(0);
115+
});
116+
});
117+
});

0 commit comments

Comments
 (0)