Skip to content

Commit 88dbbc5

Browse files
authored
Merge pull request bsm#63 from mxmCherry/feature/use-json-rawmessage
switch back custom Extension to json.RawMessage
2 parents 643b4f1 + d4bd648 commit 88dbbc5

32 files changed

+375
-386
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
OpenRTB implementation for Go
66

7+
## Requirements
8+
9+
Requires Go 1.8+ for proper `json.RawMessage` marshalling.
10+
711
## Installation
812

913
To install, use `go get`:

audio.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,25 @@ var (
1212

1313
// The "audio" object must be included directly in the impression object
1414
type Audio struct {
15-
Mimes []string `json:"mimes"` // Content MIME types supported.
16-
MinDuration int `json:"minduration,omitempty"` // Minimum video ad duration in seconds
17-
MaxDuration int `json:"maxduration,omitempty"` // Maximum video ad duration in seconds
18-
Protocols []int `json:"protocols,omitempty"` // Video bid response protocols
19-
StartDelay int `json:"startdelay,omitempty"` // Indicates the start delay in seconds
20-
Sequence int `json:"sequence,omitempty"` // Default: 1
21-
BAttr []int `json:"battr,omitempty"` // Blocked creative attributes
22-
MaxExtended int `json:"maxextended,omitempty"` // Maximum extended video ad duration
23-
MinBitrate int `json:"minbitrate,omitempty"` // Minimum bit rate in Kbps
24-
MaxBitrate int `json:"maxbitrate,omitempty"` // Maximum bit rate in Kbps
25-
Delivery []int `json:"delivery,omitempty"` // List of supported delivery methods
26-
CompanionAd []Banner `json:"companionad,omitempty"`
27-
API []int `json:"api,omitempty"`
28-
CompanionType []int `json:"companiontype,omitempty"`
29-
MaxSequence int `json:"maxseq,omitempty"` // The maximumnumber of ads that canbe played in an ad pod.
30-
Feed int `json:"feed,omitempty"` // Type of audio feed.
31-
Stitched int `json:"stitched,omitempty"` // Indicates if the ad is stitched with audio content or delivered independently
32-
NVol int `json:"nvol,omitempty"` // Volume normalization mode.
33-
Ext Extension `json:"ext,omitempty"`
15+
Mimes []string `json:"mimes"` // Content MIME types supported.
16+
MinDuration int `json:"minduration,omitempty"` // Minimum video ad duration in seconds
17+
MaxDuration int `json:"maxduration,omitempty"` // Maximum video ad duration in seconds
18+
Protocols []int `json:"protocols,omitempty"` // Video bid response protocols
19+
StartDelay int `json:"startdelay,omitempty"` // Indicates the start delay in seconds
20+
Sequence int `json:"sequence,omitempty"` // Default: 1
21+
BAttr []int `json:"battr,omitempty"` // Blocked creative attributes
22+
MaxExtended int `json:"maxextended,omitempty"` // Maximum extended video ad duration
23+
MinBitrate int `json:"minbitrate,omitempty"` // Minimum bit rate in Kbps
24+
MaxBitrate int `json:"maxbitrate,omitempty"` // Maximum bit rate in Kbps
25+
Delivery []int `json:"delivery,omitempty"` // List of supported delivery methods
26+
CompanionAd []Banner `json:"companionad,omitempty"`
27+
API []int `json:"api,omitempty"`
28+
CompanionType []int `json:"companiontype,omitempty"`
29+
MaxSequence int `json:"maxseq,omitempty"` // The maximumnumber of ads that canbe played in an ad pod.
30+
Feed int `json:"feed,omitempty"` // Type of audio feed.
31+
Stitched int `json:"stitched,omitempty"` // Indicates if the ad is stitched with audio content or delivered independently
32+
NVol int `json:"nvol,omitempty"` // Volume normalization mode.
33+
Ext json.RawMessage `json:"ext,omitempty"`
3434
}
3535

3636
type jsonAudio Audio

banner.go

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
11
package openrtb
22

3+
import "encoding/json"
4+
35
// The "banner" object must be included directly in the impression object if the impression offered
46
// for auction is display or rich media, or it may be optionally embedded in the video object to
57
// describe the companion banners available for the linear or non-linear video ad. The banner
68
// object may include a unique identifier; this can be useful if these IDs can be leveraged in the
79
// VAST response to dictate placement of the companion creatives when multiple companion ad
810
// opportunities of the same size are available on a page.
911
type Banner struct {
10-
W int `json:"w,omitempty"` // Width
11-
H int `json:"h,omitempty"` // Height
12-
Format []Format `json:"format,omitempty"` //Array of format objects representing the banner sizes permitted.
13-
WMax int `json:"wmax,omitempty"` // Width maximum DEPRECATED
14-
HMax int `json:"hmax,omitempty"` // Height maximum DEPRECATED
15-
WMin int `json:"wmin,omitempty"` // Width minimum DEPRECATED
16-
HMin int `json:"hmin,omitempty"` // Height minimum DEPRECATED
17-
ID string `json:"id,omitempty"` // A unique identifier
18-
BType []int `json:"btype,omitempty"` // Blocked creative types
19-
BAttr []int `json:"battr,omitempty"` // Blocked creative attributes
20-
Pos int `json:"pos,omitempty"` // Ad Position
21-
Mimes []string `json:"mimes,omitempty"` // Whitelist of content MIME types supported
22-
TopFrame int `json:"topframe,omitempty"` // Default: 0 ("1": Delivered in top frame, "0": Elsewhere)
23-
ExpDir []int `json:"expdir,omitempty"` // Specify properties for an expandable ad
24-
Api []int `json:"api,omitempty"` // List of supported API frameworks
25-
Ext Extension `json:"ext,omitempty"`
12+
W int `json:"w,omitempty"` // Width
13+
H int `json:"h,omitempty"` // Height
14+
Format []Format `json:"format,omitempty"` //Array of format objects representing the banner sizes permitted.
15+
WMax int `json:"wmax,omitempty"` // Width maximum DEPRECATED
16+
HMax int `json:"hmax,omitempty"` // Height maximum DEPRECATED
17+
WMin int `json:"wmin,omitempty"` // Width minimum DEPRECATED
18+
HMin int `json:"hmin,omitempty"` // Height minimum DEPRECATED
19+
ID string `json:"id,omitempty"` // A unique identifier
20+
BType []int `json:"btype,omitempty"` // Blocked creative types
21+
BAttr []int `json:"battr,omitempty"` // Blocked creative attributes
22+
Pos int `json:"pos,omitempty"` // Ad Position
23+
Mimes []string `json:"mimes,omitempty"` // Whitelist of content MIME types supported
24+
TopFrame int `json:"topframe,omitempty"` // Default: 0 ("1": Delivered in top frame, "0": Elsewhere)
25+
ExpDir []int `json:"expdir,omitempty"` // Specify properties for an expandable ad
26+
Api []int `json:"api,omitempty"` // List of supported API frameworks
27+
Ext json.RawMessage `json:"ext,omitempty"`
2628
}

bid.go

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package openrtb
22

3-
import "errors"
3+
import (
4+
"encoding/json"
5+
"errors"
6+
)
47

58
// Validation errors
69
var (
@@ -16,33 +19,33 @@ var (
1619
// Cid can be used to block ads that were previously identified as inappropriate.
1720
// Substitution macros may allow a bidder to use a static notice URL for all of its bids.
1821
type Bid struct {
19-
ID string `json:"id"`
20-
ImpID string `json:"impid"` // Required string ID of the impression object to which this bid applies.
21-
Price float64 `json:"price"` // Bid price in CPM. Suggests using integer math for accounting to avoid rounding errors.
22-
AdID string `json:"adid,omitempty"` // References the ad to be served if the bid wins.
23-
NURL string `json:"nurl,omitempty"` // Win notice URL.
24-
BURL string `json:"burl,omitempty"` // Billing notice URL.
25-
LURL string `json:"lurl,omitempty"` // Loss notice URL.
26-
AdMarkup string `json:"adm,omitempty"` // Actual ad markup. XHTML if a response to a banner object, or VAST XML if a response to a video object.
27-
AdvDomain []string `json:"adomain,omitempty"` // Advertiser’s primary or top-level domain for advertiser checking; or multiple if imp rotating.
28-
Bundle string `json:"bundle,omitempty"` // A platform-specific application identifier intended to be unique to the app and independent of the exchange.
29-
IURL string `json:"iurl,omitempty"` // Sample image URL.
30-
CampaignID StringOrNumber `json:"cid,omitempty"` // Campaign ID that appears with the Ad markup.
31-
CreativeID string `json:"crid,omitempty"` // Creative ID for reporting content issues or defects. This could also be used as a reference to a creative ID that is posted with an exchange.
32-
Tactic string `json:"tactic,omitempty"` // Tactic ID to enable buyers to label bids for reporting to the exchange the tactic through which their bid was submitted.
33-
Cat []string `json:"cat,omitempty"` // IAB content categories of the creative. Refer to List 5.1
34-
Attr []int `json:"attr,omitempty"` // Array of creative attributes.
35-
API int `json:"api,omitempty"` // API required by the markup if applicable
36-
Protocol int `json:"protocol,omitempty"` // Video response protocol of the markup if applicable
37-
QAGMediaRating int `json:"qagmediarating,omitempty"` // Creative media rating per IQG guidelines.
38-
Language string `json:"language,omitempty"` // Language of the creative using ISO-639-1-alpha-2.
39-
DealID string `json:"dealid,omitempty"` // DealID extension of private marketplace deals
40-
H int `json:"h,omitempty"` // Height of the ad in pixels.
41-
W int `json:"w,omitempty"` // Width of the ad in pixels.
42-
WRatio int `json:"wratio,omitempty"` // Relative width of the creative when expressing size as a ratio.
43-
HRatio int `json:"hratio,omitempty"` // Relative height of the creative when expressing size as a ratio.
44-
Exp int `json:"exp,omitempty"` // Advisory as to the number of seconds the bidder is willing to wait between the auction and the actual impression.
45-
Ext Extension `json:"ext,omitempty"`
22+
ID string `json:"id"`
23+
ImpID string `json:"impid"` // Required string ID of the impression object to which this bid applies.
24+
Price float64 `json:"price"` // Bid price in CPM. Suggests using integer math for accounting to avoid rounding errors.
25+
AdID string `json:"adid,omitempty"` // References the ad to be served if the bid wins.
26+
NURL string `json:"nurl,omitempty"` // Win notice URL.
27+
BURL string `json:"burl,omitempty"` // Billing notice URL.
28+
LURL string `json:"lurl,omitempty"` // Loss notice URL.
29+
AdMarkup string `json:"adm,omitempty"` // Actual ad markup. XHTML if a response to a banner object, or VAST XML if a response to a video object.
30+
AdvDomain []string `json:"adomain,omitempty"` // Advertiser’s primary or top-level domain for advertiser checking; or multiple if imp rotating.
31+
Bundle string `json:"bundle,omitempty"` // A platform-specific application identifier intended to be unique to the app and independent of the exchange.
32+
IURL string `json:"iurl,omitempty"` // Sample image URL.
33+
CampaignID StringOrNumber `json:"cid,omitempty"` // Campaign ID that appears with the Ad markup.
34+
CreativeID string `json:"crid,omitempty"` // Creative ID for reporting content issues or defects. This could also be used as a reference to a creative ID that is posted with an exchange.
35+
Tactic string `json:"tactic,omitempty"` // Tactic ID to enable buyers to label bids for reporting to the exchange the tactic through which their bid was submitted.
36+
Cat []string `json:"cat,omitempty"` // IAB content categories of the creative. Refer to List 5.1
37+
Attr []int `json:"attr,omitempty"` // Array of creative attributes.
38+
API int `json:"api,omitempty"` // API required by the markup if applicable
39+
Protocol int `json:"protocol,omitempty"` // Video response protocol of the markup if applicable
40+
QAGMediaRating int `json:"qagmediarating,omitempty"` // Creative media rating per IQG guidelines.
41+
Language string `json:"language,omitempty"` // Language of the creative using ISO-639-1-alpha-2.
42+
DealID string `json:"dealid,omitempty"` // DealID extension of private marketplace deals
43+
H int `json:"h,omitempty"` // Height of the ad in pixels.
44+
W int `json:"w,omitempty"` // Width of the ad in pixels.
45+
WRatio int `json:"wratio,omitempty"` // Relative width of the creative when expressing size as a ratio.
46+
HRatio int `json:"hratio,omitempty"` // Relative height of the creative when expressing size as a ratio.
47+
Exp int `json:"exp,omitempty"` // Advisory as to the number of seconds the bidder is willing to wait between the auction and the actual impression.
48+
Ext json.RawMessage `json:"ext,omitempty"`
4649
}
4750

4851
// Validate required attributes

bidrequest.go

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package openrtb
22

3-
import "errors"
3+
import (
4+
"encoding/json"
5+
"errors"
6+
)
47

58
// Validation errors
69
var (
@@ -13,26 +16,26 @@ var (
1316
// attribute is required as is at least one "imp" (i.e., impression) object. Other attributes are
1417
// optional since an exchange may establish default values.
1518
type BidRequest struct {
16-
ID string `json:"id"` // Unique ID of the bid request
17-
Imp []Impression `json:"imp,omitempty"`
18-
Site *Site `json:"site,omitempty"`
19-
App *App `json:"app,omitempty"`
20-
Device *Device `json:"device,omitempty"`
21-
User *User `json:"user,omitempty"`
22-
Test int `json:"test,omitempty"` // Indicator of test mode in which auctions are not billable, where 0 = live mode, 1 = test mode
23-
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.
24-
TMax int `json:"tmax,omitempty"` // Maximum amount of time in milliseconds to submit a bid
25-
WSeat []string `json:"wseat,omitempty"` // Array of buyer seats allowed to bid on this auction
26-
BSeat []string `json:"bseat,omitempty"` // Array of buyer seats blocked to bid on this auction
27-
WLang []string `json:"wlang,omitempty"` // Array of languages for creatives using ISO-639-1-alpha-2
28-
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
29-
Cur []string `json:"cur,omitempty"` // Array of allowed currencies
30-
Bcat []string `json:"bcat,omitempty"` // Blocked Advertiser Categories.
31-
BAdv []string `json:"badv,omitempty"` // Array of strings of blocked toplevel domains of advertisers
32-
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.
33-
Source *Source `json:"source,omitempty"` // A Source object that provides data about the inventory source and which entity makes the final decision
34-
Regs *Regulations `json:"regs,omitempty"`
35-
Ext Extension `json:"ext,omitempty"`
19+
ID string `json:"id"` // Unique ID of the bid request
20+
Imp []Impression `json:"imp,omitempty"`
21+
Site *Site `json:"site,omitempty"`
22+
App *App `json:"app,omitempty"`
23+
Device *Device `json:"device,omitempty"`
24+
User *User `json:"user,omitempty"`
25+
Test int `json:"test,omitempty"` // Indicator of test mode in which auctions are not billable, where 0 = live mode, 1 = test mode
26+
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.
27+
TMax int `json:"tmax,omitempty"` // Maximum amount of time in milliseconds to submit a bid
28+
WSeat []string `json:"wseat,omitempty"` // Array of buyer seats allowed to bid on this auction
29+
BSeat []string `json:"bseat,omitempty"` // Array of buyer seats blocked to bid on this auction
30+
WLang []string `json:"wlang,omitempty"` // Array of languages for creatives using ISO-639-1-alpha-2
31+
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
32+
Cur []string `json:"cur,omitempty"` // Array of allowed currencies
33+
Bcat []string `json:"bcat,omitempty"` // Blocked Advertiser Categories.
34+
BAdv []string `json:"badv,omitempty"` // Array of strings of blocked toplevel domains of advertisers
35+
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.
36+
Source *Source `json:"source,omitempty"` // A Source object that provides data about the inventory source and which entity makes the final decision
37+
Regs *Regulations `json:"regs,omitempty"`
38+
Ext json.RawMessage `json:"ext,omitempty"`
3639

3740
Pmp *Pmp `json:"pmp,omitempty"` // DEPRECATED: kept for backwards compatibility
3841
}

0 commit comments

Comments
 (0)