Skip to content

Commit f01a60f

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 524f629 + fdd38fa commit f01a60f

Some content is hidden

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

82 files changed

+2665
-1517
lines changed

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
indent_style = tab
5+
end_of_line = lf
6+
charset = utf-8
7+
trim_trailing_whitespace = true
8+
insert_final_newline = true
9+
10+
[*.{json,rb,md,yml,yaml,feature}]
11+
indent_style = space
12+
indent_size = 2

.travis.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
language: go
2-
install: make test
2+
sudo: false
33
go:
4-
- 1.2
5-
- 1.3
6-
- 1.4
7-
4+
- 1.6.4
5+
- 1.7.4
6+
install:
7+
- go get -u -t ./...

Makefile

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
default: test
1+
default: vet test
22

3-
deps:
4-
go get -t ./...
3+
test:
4+
go test -a ./...
55

6-
test: deps
7-
go test ./...
6+
bench:
7+
go test ./... -bench=. -run=NONE
8+
9+
vet:
10+
go vet ./...

README.md

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

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

@@ -8,39 +8,42 @@ OpenRTB implementation for Go
88

99
To install, use `go get`:
1010

11-
go get github.com/bsm/openrtb
11+
```shell
12+
go get github.com/bsm/openrtb
13+
```
1214

13-
To update, use `go get -u`:
14-
15-
go get -u github.com/bsm/openrtb
15+
## Usage
1616

1717
Import the package:
1818

19-
package main
20-
21-
import (
22-
"github.com/bsm/openrtb"
23-
)
19+
```go
20+
package main
2421

25-
## Example
22+
import (
23+
"log"
24+
"github.com/bsm/openrtb"
25+
)
2626

27-
// Handle a HTTP request
28-
http.HandleFunc("/bid", func(w http.ResponseWriter, r *http.Request) {
29-
defer r.Body().Close()
27+
func main() {
28+
file, err := os.Open("stored.json")
29+
if err != nil {
30+
log.Fatal(err)
31+
}
32+
defer file.Close()
3033

31-
req, err := openrtb.ParseRequest(r.Body(), true)
32-
if err != nil {
33-
log.Println("ERROR %s", err.Error())
34-
} else {
35-
log.Println("INFO Received bid request %s", *req.Id)
36-
}
34+
var req *openrtb.BidRequest
35+
err = json.NewDecoder(file).Decode(&req)
36+
if err != nil {
37+
log.Fatal(err)
38+
}
3739

38-
w.WriteHeader(204) // respond with 'no bid'
39-
})
40+
log.Printf("%+v\n", req)
41+
}
42+
```
4043

4144
## Licence
4245

43-
Copyright (c) 2014 Black Square Media Ltd. All rights reserved.
46+
Copyright (c) 2015 Black Square Media Ltd. All rights reserved.
4447
(The MIT License)
4548

4649
Permission is hereby granted, free of charge, to any person obtaining
@@ -61,3 +64,6 @@ Import the package:
6164
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
6265
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
6366
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
67+
68+
Some test examples were taken from:
69+
https://code.google.com/p/openrtb/wiki/OpenRTB_Examples

app.go

Lines changed: 0 additions & 51 deletions
This file was deleted.

app_test.go

Lines changed: 0 additions & 25 deletions
This file was deleted.

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 & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -7,48 +7,20 @@ package openrtb
77
// VAST response to dictate placement of the companion creatives when multiple companion ad
88
// opportunities of the same size are available on a page.
99
type Banner struct {
10-
W *int `json:"w,omitempty"` // Width
11-
H *int `json:"h,omitempty"` // Height
12-
Wmax *int `json:"wmax,omitempty"` // Width maximum
13-
Hmax *int `json:"hmax,omitempty"` // Height maximum
14-
Wmin *int `json:"wmin,omitempty"` // Width minimum
15-
Hmin *int `json:"hmin,omitempty"` // Height minimum
16-
Id *string `json:"id,omitempty"` // A unique identifier
17-
Pos *int `json:"pos,omitempty"` // Ad Position
18-
Btype []int `json:"btype,omitempty"` // Blocked creative types
19-
Battr []int `json:"battr,omitempty"` // Blocked creative attributes
20-
Mimes []string `json:"mimes,omitempty"` // Whitelist of content MIME types supported
21-
Topframe *int `json:"topframe,omitempty"` // Default: 0 ("1": Delivered in top frame, "0": Elsewhere)
22-
Expdir []int `json:"expdir,omitempty"` // Specify properties for an expandable ad
23-
Api []int `json:"api,omitempty"` // List of supported API frameworks
24-
Ext Extensions `json:"ext,omitempty"`
25-
}
26-
27-
// Returns topframe status, with default fallback
28-
func (b *Banner) IsTopFrame() bool {
29-
if b.Topframe != nil {
30-
return *b.Topframe == 1
31-
}
32-
return false
33-
}
34-
35-
// Returns the position, with default fallback
36-
func (b *Banner) Position() int {
37-
if b.Pos != nil {
38-
return *b.Pos
39-
}
40-
return AD_POS_UNKNOWN
41-
}
42-
43-
// Applies defaults
44-
func (b *Banner) WithDefaults() *Banner {
45-
if b.Topframe == nil {
46-
b.Topframe = new(int)
47-
*b.Topframe = 0
48-
}
49-
if b.Pos == nil {
50-
b.Pos = new(int)
51-
*b.Pos = AD_POS_UNKNOWN
52-
}
53-
return b
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"`
5426
}

0 commit comments

Comments
 (0)