forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmabidderBidAdapter.js
65 lines (61 loc) · 1.84 KB
/
mabidderBidAdapter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER } from '../src/mediaTypes.js';
import { ortbConverter } from '../libraries/ortbConverter/converter.js';
const BIDDER_CODE = 'mabidder';
export const baseUrl = 'https://prebid.ecdrsvc.com/bid';
const converter = ortbConverter({})
export const spec = {
supportedMediaTypes: [BANNER],
code: BIDDER_CODE,
isBidRequestValid: function(bid) {
if (typeof bid.params === 'undefined') {
return false;
}
return !!(bid.params.ppid && bid.sizes && Array.isArray(bid.sizes) && Array.isArray(bid.sizes[0]))
},
buildRequests: function(validBidRequests, bidderRequest) {
const fpd = converter.toORTB({ bidRequests: validBidRequests, bidderRequest: bidderRequest });
const bids = [];
validBidRequests.forEach(bidRequest => {
const sizes = [];
bidRequest.sizes.forEach(size => {
sizes.push({
width: size[0],
height: size[1]
});
});
bids.push({
bidId: bidRequest.bidId,
sizes: sizes,
ppid: bidRequest.params.ppid,
mediaType: BANNER
})
});
const req = {
url: baseUrl,
method: 'POST',
data: {
v: 'v' + '$prebid.version$',
bids: bids,
url: bidderRequest.refererInfo.page || '',
referer: bidderRequest.refererInfo.ref || '',
fpd: fpd || {}
}
};
return req;
},
interpretResponse: function(serverResponse, request) {
const bidResponses = [];
if (serverResponse.body) {
const body = serverResponse.body;
if (!body || typeof body !== 'object' || !body.Responses || !(body.Responses.length > 0)) {
return [];
}
body.Responses.forEach((bidResponse) => {
bidResponses.push(bidResponse);
});
}
return bidResponses;
}
}
registerBidder(spec);