forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadliveBidAdapter.js
69 lines (59 loc) · 1.72 KB
/
adliveBidAdapter.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
import * as utils from '../src/utils';
import { registerBidder } from '../src/adapters/bidderFactory';
import { BANNER } from '../src/mediaTypes';
const BIDDER_CODE = 'adlive';
const ENDPOINT_URL = 'https://api.publishers.adlive.io/get?pbjs=1';
const CURRENCY = 'USD';
const TIME_TO_LIVE = 360;
export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER],
isBidRequestValid: function(bid) {
return !!(bid.params.hashes && utils.isArray(bid.params.hashes));
},
buildRequests: function(validBidRequests) {
let requests = [];
utils._each(validBidRequests, function(bid) {
requests.push({
method: 'POST',
url: ENDPOINT_URL,
options: {
contentType: 'application/json',
withCredentials: true
},
data: JSON.stringify({
transaction_id: bid.bidId,
hashes: utils.getBidIdParameter('hashes', bid.params)
}),
bidId: bid.bidId
});
});
return requests;
},
interpretResponse: function(serverResponse, bidRequest) {
try {
const response = serverResponse.body;
const bidResponses = [];
utils._each(response, function(bidResponse) {
if (!bidResponse.is_passback) {
bidResponses.push({
requestId: bidRequest.bidId,
cpm: bidResponse.price,
width: bidResponse.size[0],
height: bidResponse.size[1],
creativeId: bidResponse.hash,
currency: CURRENCY,
netRevenue: false,
ttl: TIME_TO_LIVE,
ad: bidResponse.content
});
}
});
return bidResponses;
} catch (err) {
utils.logError(err);
return [];
}
}
};
registerBidder(spec);