forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbidfactory.js
56 lines (50 loc) · 1.2 KB
/
bidfactory.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
var utils = require('./utils.js');
/**
Required paramaters
bidderCode,
height,
width,
statusCode
Optional paramaters
adId,
cpm,
ad,
adUrl,
dealId,
priceKeyString;
*/
function Bid(statusCode, bidRequest) {
var _bidSrc = (bidRequest && bidRequest.src) || 'client';
var _statusCode = statusCode || 0;
this.bidderCode = (bidRequest && bidRequest.bidder) || '';
this.width = 0;
this.height = 0;
this.statusMessage = _getStatus();
this.adId = utils.getUniqueIdentifierStr();
this.requestId = bidRequest && bidRequest.bidId;
this.mediaType = 'banner';
this.source = _bidSrc;
function _getStatus() {
switch (_statusCode) {
case 0:
return 'Pending';
case 1:
return 'Bid available';
case 2:
return 'Bid returned empty or error response';
case 3:
return 'Bid timed out';
}
}
this.getStatusCode = function () {
return _statusCode;
};
// returns the size of the bid creative. Concatenation of width and height by ‘x’.
this.getSize = function () {
return this.width + 'x' + this.height;
};
}
// Bid factory function.
export function createBid(statusCode, bidRequest) {
return new Bid(statusCode, bidRequest);
}