forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmaruBidAdapter.js
99 lines (80 loc) · 2.22 KB
/
admaruBidAdapter.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {BANNER} from '../src/mediaTypes.js';
const ADMARU_ENDPOINT = 'https://p1.admaru.net/AdCall';
const BIDDER_CODE = 'admaru';
const DEFAULT_BID_TTL = 360;
const SYNC_URL = 'https://p2.admaru.net/UserSync/sync'
function parseBid(rawBid, currency) {
const bid = {};
bid.cpm = rawBid.price;
bid.impid = rawBid.impid;
bid.requestId = rawBid.impid;
bid.netRevenue = true;
bid.dealId = '';
bid.creativeId = rawBid.crid;
bid.currency = currency;
bid.ad = rawBid.adm;
bid.width = rawBid.w;
bid.height = rawBid.h;
bid.mediaType = BANNER;
bid.ttl = DEFAULT_BID_TTL;
return bid;
}
export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER],
isBidRequestValid: function (bid) {
return !!(bid && bid.params && bid.params.pub_id && bid.params.adspace_id);
},
buildRequests: function (validBidRequests, bidderRequest) {
return validBidRequests.map(bid => {
const payload = {
pub_id: bid.params.pub_id,
adspace_id: bid.params.adspace_id,
bidderRequestId: bid.bidderRequestId,
bidId: bid.bidId
};
return {
method: 'GET',
url: ADMARU_ENDPOINT,
data: payload,
}
})
},
interpretResponse: function (serverResponse, bidRequest) {
const bidResponses = [];
let bid = null;
if (!serverResponse.hasOwnProperty('body') || !serverResponse.body.hasOwnProperty('seatbid')) {
return bidResponses;
}
const serverBody = serverResponse.body;
const seatbid = serverBody.seatbid;
for (let i = 0; i < seatbid.length; i++) {
if (!seatbid[i].hasOwnProperty('bid')) {
continue;
}
const innerBids = seatbid[i].bid;
for (let j = 0; j < innerBids.length; j++) {
bid = parseBid(innerBids[j], serverBody.cur);
bidResponses.push(bid);
}
}
return bidResponses;
},
getUserSyncs: function (syncOptions, responses) {
if (syncOptions.iframeEnabled) {
return [{
type: 'iframe',
url: SYNC_URL
}];
}
if (syncOptions.pixelEnabled) {
return [{
type: 'image',
url: SYNC_URL
}];
}
return [];
},
}
registerBidder(spec);