-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
bidfactory.js
72 lines (65 loc) · 1.47 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { getUniqueIdentifierStr } from './utils.js';
/**
Required paramaters
bidderCode,
height,
width,
statusCode
Optional paramaters
adId,
cpm,
ad,
adUrl,
dealId,
priceKeyString;
*/
function Bid(statusCode, {src = 'client', bidder = '', bidId, transactionId, adUnitId, auctionId} = {}) {
var _bidSrc = src;
var _statusCode = statusCode || 0;
Object.assign(this, {
bidderCode: bidder,
width: 0,
height: 0,
statusMessage: _getStatus(),
adId: getUniqueIdentifierStr(),
requestId: bidId,
transactionId,
adUnitId,
auctionId,
mediaType: 'banner',
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;
};
this.getIdentifiers = function () {
return {
src: this.source,
bidder: this.bidderCode,
bidId: this.requestId,
transactionId: this.transactionId,
adUnitId: this.adUnitId,
auctionId: this.auctionId
}
};
}
// Bid factory function.
export function createBid(statusCode, identifiers) {
return new Bid(statusCode, identifiers);
}