Skip to content

Commit da7bfdf

Browse files
authored
Merge pull request bsm#68 from bsm/feature/v3
Ready for v3
2 parents f0c31f9 + 62ce92d commit da7bfdf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1196
-691
lines changed

.travis.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
language: go
22
go:
3-
- 1.10.x
4-
- 1.11.x
5-
install:
6-
- go get -t ./...
3+
- 1.12.x
4+
- 1.13.x
75
env:
86
- GO111MODULE=on
9-
7+
cache:
8+
directories:
9+
- $GOPATH/pkg/mod

LICENSE

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Copyright (c) 2015 Black Square Media Ltd. All rights reserved.
2+
(The MIT License)
3+
4+
Permission is hereby granted, free of charge, to any person obtaining
5+
a copy of this software and associated documentation files (the
6+
'Software'), to deal in the Software without restriction, including
7+
without limitation the rights to use, copy, modify, merge, publish,
8+
distribute, sublicense, and/or sell copies of the Software, and to
9+
permit persons to whom the Software is furnished to do so, subject to
10+
the following conditions:
11+
12+
The above copyright notice and this permission notice shall be
13+
included in all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
16+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
23+
Some test examples were taken from:
24+
https://code.google.com/p/openrtb/wiki/OpenRTB_Examples

README.md

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,29 @@
1-
# Go OpenRTB v2.x
1+
# OpenRTB
22

33
[![Build Status](https://travis-ci.org/bsm/openrtb.svg?branch=master)](https://travis-ci.org/bsm/openrtb)
44

5-
OpenRTB implementation for Go
5+
OpenRTB structs and validations for Go.
66

77
## Requirements
88

9-
Requires Go 1.8+ for proper `json.RawMessage` marshalling.
9+
Requires Go 1.8+ for proper `json.RawMessage` marshaling.
1010

1111
## Installation
1212

1313
To install, use `go get`:
1414

1515
```shell
16-
go get github.com/bsm/openrtb
16+
go get github.com/bsm/openrtb/v3
1717
```
1818

1919
## Usage
2020

21-
Import the package:
22-
2321
```go
2422
package main
2523

2624
import (
2725
"log"
28-
"github.com/bsm/openrtb"
26+
"github.com/bsm/openrtb/v3"
2927
)
3028

3129
func main() {
@@ -36,38 +34,10 @@ func main() {
3634
defer file.Close()
3735

3836
var req *openrtb.BidRequest
39-
err = json.NewDecoder(file).Decode(&req)
40-
if err != nil {
37+
if err := json.NewDecoder(file).Decode(&req); err != nil {
4138
log.Fatal(err)
4239
}
4340

4441
log.Printf("%+v\n", req)
4542
}
4643
```
47-
48-
## Licence
49-
50-
Copyright (c) 2015 Black Square Media Ltd. All rights reserved.
51-
(The MIT License)
52-
53-
Permission is hereby granted, free of charge, to any person obtaining
54-
a copy of this software and associated documentation files (the
55-
'Software'), to deal in the Software without restriction, including
56-
without limitation the rights to use, copy, modify, merge, publish,
57-
distribute, sublicense, and/or sell copies of the Software, and to
58-
permit persons to whom the Software is furnished to do so, subject to
59-
the following conditions:
60-
61-
The above copyright notice and this permission notice shall be
62-
included in all copies or substantial portions of the Software.
63-
64-
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
65-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
66-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
67-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
68-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
69-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
70-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
71-
72-
Some test examples were taken from:
73-
https://code.google.com/p/openrtb/wiki/OpenRTB_Examples

audio.go

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,38 +7,38 @@ import (
77

88
// Validation errors
99
var (
10-
ErrInvalidAudioNoMimes = errors.New("openrtb: audio has no mimes")
10+
ErrInvalidAudioNoMIMEs = errors.New("openrtb: audio has no mimes")
1111
)
1212

13-
// The "audio" object must be included directly in the impression object
13+
// 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 json.RawMessage `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 []Protocol `json:"protocols,omitempty"` // Video bid response protocols
19+
StartDelay StartDelay `json:"startdelay,omitempty"` // Indicates the start delay in seconds
20+
Sequence int `json:"sequence,omitempty"` // Default: 1
21+
BlockedAttrs []CreativeAttribute `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 []ContentDelivery `json:"delivery,omitempty"` // List of supported delivery methods
26+
CompanionAds []Banner `json:"companionad,omitempty"`
27+
APIs []APIFramework `json:"api,omitempty"`
28+
CompanionTypes []CompanionType `json:"companiontype,omitempty"`
29+
MaxSequence int `json:"maxseq,omitempty"` // The maximumnumber of ads that canbe played in an ad pod.
30+
Feed FeedType `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+
VolumeNorm VolumeNorm `json:"nvol,omitempty"` // Volume normalization mode.
33+
Ext json.RawMessage `json:"ext,omitempty"`
3434
}
3535

3636
type jsonAudio Audio
3737

38-
// Validates the object
38+
// Validate the object
3939
func (a *Audio) Validate() error {
40-
if len(a.Mimes) == 0 {
41-
return ErrInvalidAudioNoMimes
40+
if len(a.MIMEs) == 0 {
41+
return ErrInvalidAudioNoMIMEs
4242
}
4343
return nil
4444
}

audio_test.go

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,50 +9,49 @@ var _ = Describe("Audio", func() {
99
var subject *Audio
1010

1111
BeforeEach(func() {
12-
err := fixture("audio", &subject)
13-
Expect(err).NotTo(HaveOccurred())
12+
Expect(fixture("audio", &subject)).To(Succeed())
1413
})
1514

1615
It("should parse correctly", func() {
1716
Expect(subject).To(Equal(&Audio{
18-
Mimes: []string{
17+
MIMEs: []string{
1918
"audio/mp4",
2019
},
21-
MinDuration: 5,
22-
MaxDuration: 30,
23-
Protocols: []int{AudioProtocolDAAST1, AudioProtocolDAAST1Wrapper},
24-
Sequence: 1,
25-
BAttr: []int{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert},
26-
MaxExtended: 30,
27-
MinBitrate: 300,
28-
MaxBitrate: 1500,
29-
Delivery: []int{ContentDeliveryProgressive},
30-
CompanionAd: []Banner{
31-
{W: 300, H: 250, ID: "1234567893-1", Pos: AdPosAboveFold, BAttr: []int{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert}, ExpDir: []int{ExpDirRight, ExpDirDown}},
32-
{W: 728, H: 90, ID: "1234567893-2", Pos: AdPosAboveFold, BAttr: []int{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert}},
20+
MinDuration: 5,
21+
MaxDuration: 30,
22+
Protocols: []Protocol{ProtocolDAAST1, ProtocolDAAST1Wrapper},
23+
Sequence: 1,
24+
BlockedAttrs: []CreativeAttribute{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert},
25+
MaxExtended: 30,
26+
MinBitrate: 300,
27+
MaxBitrate: 1500,
28+
Delivery: []ContentDelivery{ContentDeliveryProgressive},
29+
CompanionAds: []Banner{
30+
{Width: 300, Height: 250, ID: "1234567893-1", Position: AdPositionAboveFold, BlockedAttrs: []CreativeAttribute{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert}, ExpDirs: []ExpDir{ExpDirRight, ExpDirDown}},
31+
{Width: 728, Height: 90, ID: "1234567893-2", Position: AdPositionAboveFold, BlockedAttrs: []CreativeAttribute{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert}},
3332
},
34-
API: []int{APIFrameworkVPAID1, APIFrameworkVPAID2},
35-
CompanionType: []int{VASTCompanionStatic, VASTCompanionHTML},
33+
APIs: []APIFramework{APIFrameworkVPAID1, APIFrameworkVPAID2},
34+
CompanionTypes: []CompanionType{CompanionTypeStatic, CompanionTypeHTML},
3635
}))
3736
})
3837

3938
It("should validate", func() {
4039
Expect((&Audio{
41-
MinDuration: 5,
42-
MaxDuration: 30,
43-
Protocols: []int{AudioProtocolDAAST1, AudioProtocolDAAST1Wrapper},
44-
Sequence: 1,
45-
BAttr: []int{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert},
46-
MaxExtended: 30,
47-
MinBitrate: 300,
48-
MaxBitrate: 1500,
49-
Delivery: []int{ContentDeliveryProgressive},
50-
CompanionAd: []Banner{
51-
{W: 300, H: 250, ID: "1234567893-1", Pos: AdPosAboveFold, BAttr: []int{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert}, ExpDir: []int{ExpDirRight, ExpDirDown}},
52-
{W: 728, H: 90, ID: "1234567893-2", Pos: AdPosAboveFold, BAttr: []int{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert}},
40+
MinDuration: 5,
41+
MaxDuration: 30,
42+
Protocols: []Protocol{ProtocolDAAST1, ProtocolDAAST1Wrapper},
43+
Sequence: 1,
44+
BlockedAttrs: []CreativeAttribute{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert},
45+
MaxExtended: 30,
46+
MinBitrate: 300,
47+
MaxBitrate: 1500,
48+
Delivery: []ContentDelivery{ContentDeliveryProgressive},
49+
CompanionAds: []Banner{
50+
{Width: 300, Height: 250, ID: "1234567893-1", Position: AdPositionAboveFold, BlockedAttrs: []CreativeAttribute{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert}, ExpDirs: []ExpDir{ExpDirRight, ExpDirDown}},
51+
{Width: 728, Height: 90, ID: "1234567893-2", Position: AdPositionAboveFold, BlockedAttrs: []CreativeAttribute{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert}},
5352
},
54-
CompanionType: []int{VASTCompanionStatic, VASTCompanionHTML},
55-
}).Validate()).To(Equal(ErrInvalidAudioNoMimes))
53+
CompanionTypes: []CompanionType{CompanionTypeStatic, CompanionTypeHTML},
54+
}).Validate()).To(Equal(ErrInvalidAudioNoMIMEs))
5655
})
5756

5857
})

banner.go

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

33
import "encoding/json"
44

5-
// The "banner" object must be included directly in the impression object if the impression offered
5+
// Banner object must be included directly in the impression object if the impression offered
66
// for auction is display or rich media, or it may be optionally embedded in the video object to
77
// describe the companion banners available for the linear or non-linear video ad. The banner
88
// object may include a unique identifier; this can be useful if these IDs can be leveraged in the
99
// VAST response to dictate placement of the companion creatives when multiple companion ad
1010
// opportunities of the same size are available on a page.
1111
type Banner struct {
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-
Vcm int `json:"vcm,omitempty"` // Represents the relationship with video. 0 = concurrent, 1 = end-card
28-
Ext json.RawMessage `json:"ext,omitempty"`
12+
Width int `json:"w,omitempty"` // Width
13+
Height int `json:"h,omitempty"` // Height
14+
Formats []Format `json:"format,omitempty"` // Array of format objects representing the banner sizes permitted.
15+
WidthMax int `json:"wmax,omitempty"` // Width maximum DEPRECATED
16+
HeightMax int `json:"hmax,omitempty"` // Height maximum DEPRECATED
17+
WidthMin int `json:"wmin,omitempty"` // Width minimum DEPRECATED
18+
HeightMin int `json:"hmin,omitempty"` // Height minimum DEPRECATED
19+
ID string `json:"id,omitempty"` // A unique identifier
20+
BlockedTypes []BannerType `json:"btype,omitempty"` // Blocked banner types
21+
BlockedAttrs []CreativeAttribute `json:"battr,omitempty"` // Blocked creative attributes
22+
Position AdPosition `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+
ExpDirs []ExpDir `json:"expdir,omitempty"` // Specify properties for an expandable ad
26+
APIs []APIFramework `json:"api,omitempty"` // List of supported API frameworks
27+
VCM int `json:"vcm,omitempty"` // Represents the relationship with video. 0 = concurrent, 1 = end-card
28+
Ext json.RawMessage `json:"ext,omitempty"`
2929
}

banner_test.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,18 @@ var _ = Describe("Banner", func() {
99
var subject *Banner
1010

1111
BeforeEach(func() {
12-
err := fixture("banner", &subject)
13-
Expect(err).NotTo(HaveOccurred())
12+
Expect(fixture("banner", &subject)).To(Succeed())
1413
})
1514

1615
It("should parse correctly", func() {
1716
Expect(subject).To(Equal(&Banner{
18-
W: 728,
19-
H: 90,
20-
Pos: AdPosAboveFold,
21-
BType: []int{BannerTypeFrame},
22-
BAttr: []int{CreativeAttributeWindowsDialogOrAlert},
23-
Api: []int{APIFrameworkMRAID1},
24-
Vcm: 1,
17+
Width: 728,
18+
Height: 90,
19+
Position: AdPositionAboveFold,
20+
BlockedTypes: []BannerType{BannerTypeFrame},
21+
BlockedAttrs: []CreativeAttribute{CreativeAttributeWindowsDialogOrAlert},
22+
APIs: []APIFramework{APIFrameworkMRAID1},
23+
VCM: 1,
2524
}))
2625
})
2726

0 commit comments

Comments
 (0)