Skip to content

Commit 705b5ee

Browse files
authored
Merge pull request #1 from bsm/master
Merge upstream to local
2 parents 4b2843e + 20ac189 commit 705b5ee

34 files changed

+634
-396
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
language: go
22
sudo: false
33
go:
4-
- 1.6
5-
- 1.7
4+
- 1.6.4
5+
- 1.7.4
66
install:
77
- go get -u -t ./...

audio.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package openrtb
2+
3+
import (
4+
"encoding/json"
5+
"errors"
6+
)
7+
8+
// Validation errors
9+
var (
10+
ErrInvalidAudioNoMimes = errors.New("openrtb: audio has no mimes")
11+
)
12+
13+
// The "audio" object must be included directly in the impression object
14+
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"`
34+
}
35+
36+
type jsonAudio Audio
37+
38+
// Validates the object
39+
func (a *Audio) Validate() error {
40+
if len(a.Mimes) == 0 {
41+
return ErrInvalidAudioNoMimes
42+
}
43+
return nil
44+
}
45+
46+
// MarshalJSON custom marshalling with normalization
47+
func (a *Audio) MarshalJSON() ([]byte, error) {
48+
a.normalize()
49+
return json.Marshal((*jsonAudio)(a))
50+
}
51+
52+
// UnmarshalJSON custom unmarshalling with normalization
53+
func (a *Audio) UnmarshalJSON(data []byte) error {
54+
var h jsonAudio
55+
if err := json.Unmarshal(data, &h); err != nil {
56+
return err
57+
}
58+
59+
*a = (Audio)(h)
60+
a.normalize()
61+
return nil
62+
}
63+
64+
func (a *Audio) normalize() {
65+
if a.Sequence == 0 {
66+
a.Sequence = 1
67+
}
68+
}

audio_test.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package openrtb
2+
3+
import (
4+
. "github.com/onsi/ginkgo"
5+
. "github.com/onsi/gomega"
6+
)
7+
8+
var _ = Describe("Audio", func() {
9+
var subject *Audio
10+
11+
BeforeEach(func() {
12+
err := fixture("audio", &subject)
13+
Expect(err).NotTo(HaveOccurred())
14+
})
15+
16+
It("should parse correctly", func() {
17+
Expect(subject).To(Equal(&Audio{
18+
Mimes: []string{
19+
"audio/mp4",
20+
},
21+
MinDuration: 5,
22+
MaxDuration: 30,
23+
Protocols: []int{AudioProtocolDAAST1, AudioProtocolDAAST1Wrapper},
24+
Sequence: 1,
25+
BAttr: []int{13, 14},
26+
MaxExtended: 30,
27+
MinBitrate: 300,
28+
MaxBitrate: 1500,
29+
Delivery: []int{2},
30+
CompanionAd: []Banner{
31+
{W: 300, H: 250, ID: "1234567893-1", Pos: 1, BAttr: []int{13, 14}, ExpDir: []int{ExpDirRight, ExpDirDown}},
32+
{W: 728, H: 90, ID: "1234567893-2", Pos: 1, BAttr: []int{13, 14}},
33+
},
34+
API: []int{1, 2},
35+
CompanionType: []int{1, 2},
36+
}))
37+
})
38+
39+
It("should validate", func() {
40+
Expect((&Audio{
41+
MinDuration: 5,
42+
MaxDuration: 30,
43+
Protocols: []int{AudioProtocolDAAST1, AudioProtocolDAAST1Wrapper},
44+
Sequence: 1,
45+
BAttr: []int{13, 14},
46+
MaxExtended: 30,
47+
MinBitrate: 300,
48+
MaxBitrate: 1500,
49+
Delivery: []int{2},
50+
CompanionAd: []Banner{
51+
{W: 300, H: 250, ID: "1234567893-1", Pos: 1, BAttr: []int{13, 14}, ExpDir: []int{ExpDirRight, ExpDirDown}},
52+
{W: 728, H: 90, ID: "1234567893-2", Pos: 1, BAttr: []int{13, 14}},
53+
},
54+
CompanionType: []int{1, 2},
55+
}).Validate()).To(Equal(ErrInvalidAudioNoMimes))
56+
})
57+
58+
})

banner.go

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

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

bid.go

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

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

85
// Validation errors
96
var (
@@ -19,22 +16,27 @@ var (
1916
// Cid can be used to block ads that were previously identified as inappropriate.
2017
// Substitution macros may allow a bidder to use a static notice URL for all of its bids.
2118
type Bid struct {
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-
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.
28-
AdvDomain []string `json:"adomain,omitempty"` // Advertiser’s primary or top-level domain for advertiser checking; or multiple if imp rotating.
29-
IURL string `json:"iurl,omitempty"` // Sample image URL.
30-
CampaignID string `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-
Cat []string `json:"cat,omitempty"` // IAB content categories of the creative. Refer to List 5.1
33-
Attr []int `json:"attr,omitempty"` // Array of creative attributes.
34-
DealID string `json:"dealid,omitempty"` // DealID extension of private marketplace deals
35-
H int `json:"h,omitempty"` // Height of the ad in pixels.
36-
W int `json:"w,omitempty"` // Width of the ad in pixels.
37-
Ext json.RawMessage `json:"ext,omitempty"`
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+
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.
25+
AdvDomain []string `json:"adomain,omitempty"` // Advertiser’s primary or top-level domain for advertiser checking; or multiple if imp rotating.
26+
Bundle string `json:"bundle,omitempty"` // A platform-specific application identifier intended to be unique to the app and independent of the exchange.
27+
IURL string `json:"iurl,omitempty"` // Sample image URL.
28+
CampaignID string `json:"cid,omitempty"` // Campaign ID that appears with the Ad markup.
29+
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.
30+
Cat []string `json:"cat,omitempty"` // IAB content categories of the creative. Refer to List 5.1
31+
Attr []int `json:"attr,omitempty"` // Array of creative attributes.
32+
API int `json:"api,omitempty"` // API required by the markup if applicable
33+
Protocol int `json:"protocol,omitempty"` // Video response protocol of the markup if applicable
34+
QAGMediaRating int `json:"qagmediarating,omitempty"` // Creative media rating per IQG guidelines.
35+
DealID string `json:"dealid,omitempty"` // DealID extension of private marketplace deals
36+
H int `json:"h,omitempty"` // Height of the ad in pixels.
37+
W int `json:"w,omitempty"` // Width of the ad in pixels.
38+
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.
39+
Ext Extension `json:"ext,omitempty"`
3840
}
3941

4042
// Validate required attributes

bidrequest.go

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

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

85
// Validation errors
96
var (
@@ -16,22 +13,23 @@ var (
1613
// attribute is required as is at least one "imp" (i.e., impression) object. Other attributes are
1714
// optional since an exchange may establish default values.
1815
type BidRequest struct {
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-
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
30-
Cur []string `json:"cur,omitempty"` // Array of allowed currencies
31-
Bcat []string `json:"bcat,omitempty"` // Blocked Advertiser Categories.
32-
BAdv []string `json:"badv,omitempty"` // Array of strings of blocked toplevel domains of advertisers
33-
Regs *Regulations `json:"regs,omitempty"`
34-
Ext json.RawMessage `json:"ext,omitempty"`
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+
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
27+
Cur []string `json:"cur,omitempty"` // Array of allowed currencies
28+
Bcat []string `json:"bcat,omitempty"` // Blocked Advertiser Categories.
29+
BAdv []string `json:"badv,omitempty"` // Array of strings of blocked toplevel domains of advertisers
30+
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.
31+
Regs *Regulations `json:"regs,omitempty"`
32+
Ext Extension `json:"ext,omitempty"`
3533

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

bidrequest_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ var _ = Describe("BidRequest", func() {
6767
Expect((&BidRequest{}).Validate()).To(Equal(ErrInvalidReqNoID))
6868
Expect((&BidRequest{ID: "A"}).Validate()).To(Equal(ErrInvalidReqNoImps))
6969
Expect((&BidRequest{ID: "A", Imp: []Impression{{ID: "1"}}, Site: &Site{}, App: &App{}}).Validate()).To(Equal(ErrInvalidReqMultiInv))
70-
Expect((&BidRequest{ID: "A", Imp: []Impression{{ID: "1"}}}).Validate()).To(Equal(ErrInvalidImpNoAssets))
7170

7271
Expect((&BidRequest{ID: "A", Imp: []Impression{{ID: "1", Banner: &Banner{}}}}).Validate()).NotTo(HaveOccurred())
7372
Expect((&BidRequest{ID: "A", Imp: []Impression{{ID: "1", Banner: &Banner{}}}, Site: &Site{}}).Validate()).NotTo(HaveOccurred())

bidresponse.go

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

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

85
// Validation errors
96
var (
@@ -16,13 +13,13 @@ var (
1613
// No-Bids on all impressions should be indicated as a HTTP 204 response.
1714
// For no-bids on specific impressions, the bidder should omit these from the bid response.
1815
type BidResponse struct {
19-
ID string `json:"id"` // Reflection of the bid request ID for logging purposes
20-
SeatBid []SeatBid `json:"seatbid"` // Array of seatbid objects
21-
BidID string `json:"bidid,omitempty"` // Optional response tracking ID for bidders
22-
Currency string `json:"cur,omitempty"` // Bid currency
23-
CustomData string `json:"customdata,omitempty"` // Encoded user features
24-
NBR int `json:"nbr,omitempty"` // Reason for not bidding, where 0 = unknown error, 1 = technical error, 2 = invalid request, 3 = known web spider, 4 = suspected Non-Human Traffic, 5 = cloud, data center, or proxy IP, 6 = unsupported device, 7 = blocked publisher or site, 8 = unmatched user
25-
Ext json.RawMessage `json:"ext,omitempty"` // Custom specifications in JSon
16+
ID string `json:"id"` // Reflection of the bid request ID for logging purposes
17+
SeatBid []SeatBid `json:"seatbid"` // Array of seatbid objects
18+
BidID string `json:"bidid,omitempty"` // Optional response tracking ID for bidders
19+
Currency string `json:"cur,omitempty"` // Bid currency
20+
CustomData string `json:"customdata,omitempty"` // Encoded user features
21+
NBR int `json:"nbr,omitempty"` // Reason for not bidding, where 0 = unknown error, 1 = technical error, 2 = invalid request, 3 = known web spider, 4 = suspected Non-Human Traffic, 5 = cloud, data center, or proxy IP, 6 = unsupported device, 7 = blocked publisher or site, 8 = unmatched user
22+
Ext Extension `json:"ext,omitempty"` // Custom specifications in JSon
2623
}
2724

2825
// Validate required attributes

0 commit comments

Comments
 (0)