forked from bsm/openrtb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bidrequest.go
54 lines (47 loc) · 2.71 KB
/
bidrequest.go
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
package openrtb
import "errors"
// Validation errors
var (
ErrInvalidReqNoID = errors.New("openrtb: request ID missing")
ErrInvalidReqNoImps = errors.New("openrtb: request has no impressions")
ErrInvalidReqMultiInv = errors.New("openrtb: request has multiple inventory sources") // has site and app
)
// The top-level bid request object contains a globally unique bid request or auction ID. This "id"
// attribute is required as is at least one "imp" (i.e., impression) object. Other attributes are
// optional since an exchange may establish default values.
type BidRequest struct {
ID string `json:"id"` // Unique ID of the bid request
Imp []Impression `json:"imp,omitempty"`
Site *Site `json:"site,omitempty"`
App *App `json:"app,omitempty"`
Device *Device `json:"device,omitempty"`
User *User `json:"user,omitempty"`
Test int `json:"test,omitempty"` // Indicator of test mode in which auctions are not billable, where 0 = live mode, 1 = test mode
AuctionType int `json:"at"` // Auction type, where 1 = First Price, 2 = Second Price Plus. Exchange-specific auction types can be defined using values greater than 500.
TMax int `json:"tmax,omitempty"` // Maximum amount of time in milliseconds to submit a bid
WSeat []string `json:"wseat,omitempty"` // Array of buyer seats allowed to bid on this auction
AllImps int `json:"allimps,omitempty"` // Flag to indicate whether exchange can verify that all impressions offered represent all of the impressions available in context, Default: 0
Cur []string `json:"cur,omitempty"` // Array of allowed currencies
Bcat []string `json:"bcat,omitempty"` // Blocked Advertiser Categories.
BAdv []string `json:"badv,omitempty"` // Array of strings of blocked toplevel domains of advertisers
BApp []string `json:"bapp,omitempty"` // Block list of applications by their platform-specific exchange-independent application identifiers. On Android, these should be bundle or package names (e.g., com.foo.mygame). On iOS, these are numeric IDs.
Regs *Regulations `json:"regs,omitempty"`
Ext Extension `json:"ext,omitempty"`
Pmp *Pmp `json:"pmp,omitempty"` // DEPRECATED: kept for backwards compatibility
}
// Validates the request
func (req *BidRequest) Validate() error {
if req.ID == "" {
return ErrInvalidReqNoID
} else if len(req.Imp) == 0 {
return ErrInvalidReqNoImps
} else if req.Site != nil && req.App != nil {
return ErrInvalidReqMultiInv
}
for _, imp := range req.Imp {
if err := (&imp).Validate(); err != nil {
return err
}
}
return nil
}