Skip to content

Commit 19c332a

Browse files
committed
Draft of v2
1 parent ff28769 commit 19c332a

Some content is hidden

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

63 files changed

+1857
-2058
lines changed

.editorconfig

+12
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ go:
44
- 1.2
55
- 1.3
66
- 1.4
7-
7+
- 1.5

README.md

+28-24
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Go OpenRTB 2.3
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,40 @@ OpenRTB implementation for Go
88

99
To install, use `go get`:
1010

11-
go get github.com/bsm/openrtb
12-
13-
To update, use `go get -u`:
14-
15-
go get -u github.com/bsm/openrtb
11+
```shell
12+
go get github.com/bsm/openrtb
13+
```
1614

1715
Import the package:
1816

19-
package main
17+
```go
18+
package main
2019

21-
import (
22-
"github.com/bsm/openrtb"
23-
)
20+
import (
21+
"log"
22+
"github.com/bsm/openrtb"
23+
)
2424

25-
## Example
25+
func main() {
26+
file, err := os.Open("stored.json")
27+
if err != nil {
28+
log.Fatal(err)
29+
}
30+
defer file.Close()
2631

27-
// Handle a HTTP request
28-
http.HandleFunc("/bid", func(w http.ResponseWriter, r *http.Request) {
29-
defer r.Body().Close()
32+
var req *openrtb.BidRequest
33+
err = json.NewDecoder(file).Decode(&req)
34+
if err != nil {
35+
log.Fatal(err)
36+
}
3037

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-
}
37-
38-
w.WriteHeader(204) // respond with 'no bid'
39-
})
38+
log.Printf("%+v\n", req)
39+
}
40+
```
4041

4142
## Licence
4243

43-
Copyright (c) 2014 Black Square Media Ltd. All rights reserved.
44+
Copyright (c) 2015 Black Square Media Ltd. All rights reserved.
4445
(The MIT License)
4546

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

app.go

-51
This file was deleted.

app_test.go

-25
This file was deleted.

asset.go

-44
This file was deleted.

asset_test.go

-19
This file was deleted.

banner.go

+17-44
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,27 @@
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-
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
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"`
5427
}

banner_test.go

+11-9
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,19 @@ var _ = Describe("Banner", func() {
99
var subject *Banner
1010

1111
BeforeEach(func() {
12-
subject = new(Banner)
12+
err := fixture("banner", &subject)
13+
Expect(err).NotTo(HaveOccurred())
1314
})
1415

15-
It("should have accessors", func() {
16-
Expect(subject.IsTopFrame()).To(BeFalse())
17-
Expect(subject.Position()).To(Equal(0))
16+
It("should parse correctly", func() {
17+
Expect(subject).To(Equal(&Banner{
18+
W: 728,
19+
H: 90,
20+
Pos: AdPosAboveFold,
21+
BType: []int{4},
22+
BAttr: []int{14},
23+
Api: []int{3},
24+
}))
1825
})
1926

20-
It("should have defaults", func() {
21-
subject.WithDefaults()
22-
Expect(*subject.Topframe).To(Equal(0))
23-
Expect(*subject.Pos).To(Equal(AD_POS_UNKNOWN))
24-
})
2527
})

0 commit comments

Comments
 (0)