Skip to content

Commit 53155b9

Browse files
committed
sync fork. pulls in additive changes only to not break existing references
2 parents 8e6cd18 + e622479 commit 53155b9

Some content is hidden

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

65 files changed

+1726
-977
lines changed

.github/workflows/test.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Test
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
7+
branches:
8+
- master
9+
jobs:
10+
go:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
go-version: [1.18.x, 1.19.x]
15+
steps:
16+
- uses: actions/checkout@v3
17+
- uses: actions/setup-go@v3
18+
with:
19+
go-version: ${{ matrix.go-version }}
20+
cache: true
21+
- run: make test
22+
golangci:
23+
runs-on: ubuntu-latest
24+
steps:
25+
- uses: actions/checkout@v3
26+
- uses: actions/setup-go@v3
27+
with:
28+
go-version: 1.x
29+
cache: true
30+
- uses: golangci/golangci-lint-action@v3
31+
with:
32+
version: latest

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*.makefile
2+
3+
.idea
4+
.vscode

.travis.yml

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

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: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
# Go OpenRTB v2.x
1+
# OpenRTB
22

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

5-
OpenRTB implementation for Go
5+
OpenRTB structs and validations for Go.
6+
7+
## Requirements
8+
9+
Requires Go 1.8+ for proper `json.RawMessage` marshaling.
610

711
## Installation
812

@@ -14,13 +18,12 @@ go get github.com/UnityTech/openrtb
1418

1519
## Usage
1620

17-
Import the package:
18-
1921
```go
2022
package main
2123

2224
import (
2325
"log"
26+
2427
"github.com/UnityTech/openrtb"
2528
)
2629

@@ -32,38 +35,10 @@ func main() {
3235
defer file.Close()
3336

3437
var req *openrtb.BidRequest
35-
err = json.NewDecoder(file).Decode(&req)
36-
if err != nil {
38+
if err := json.NewDecoder(file).Decode(&req); err != nil {
3739
log.Fatal(err)
3840
}
3941

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

audio.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var (
1010
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 {
1515
Mimes []string `json:"mimes"` // Content MIME types supported.
1616
MinDuration int `json:"minduration,omitempty"` // Minimum video ad duration in seconds
@@ -35,7 +35,7 @@ type Audio struct {
3535

3636
type jsonAudio Audio
3737

38-
// Validates the object
38+
// Validate the object
3939
func (a *Audio) Validate() error {
4040
if len(a.Mimes) == 0 {
4141
return ErrInvalidAudioNoMimes

audio_test.go

Lines changed: 55 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,62 @@
1-
package openrtb
1+
package openrtb_test
22

33
import (
4-
. "github.com/onsi/ginkgo"
5-
. "github.com/onsi/gomega"
4+
"errors"
5+
"reflect"
6+
"testing"
7+
8+
. "github.com/UnityTech/openrtb"
69
)
710

8-
var _ = Describe("Audio", func() {
11+
func TestAudio(t *testing.T) {
912
var subject *Audio
13+
if err := fixture("audio", &subject); err != nil {
14+
t.Fatalf("expected no error, got %v", err)
15+
}
1016

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{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}},
33-
},
34-
API: []int{APIFrameworkVPAID1, APIFrameworkVPAID2},
35-
CompanionType: []int{VASTCompanionStatic, VASTCompanionHTML},
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{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}},
53-
},
54-
CompanionType: []int{VASTCompanionStatic, VASTCompanionHTML},
55-
}).Validate()).To(Equal(ErrInvalidAudioNoMimes))
56-
})
17+
exp := &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{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}},
33+
},
34+
API: []int{APIFrameworkVPAID1, APIFrameworkVPAID2},
35+
CompanionType: []int{VASTCompanionStatic, VASTCompanionHTML},
36+
}
37+
if got := subject; !reflect.DeepEqual(exp, got) {
38+
t.Errorf("expected %+v, got %+v", exp, got)
39+
}
40+
}
5741

58-
})
42+
func TestAudio_Validate(t *testing.T) {
43+
subject := &Audio{
44+
MinDuration: 5,
45+
MaxDuration: 30,
46+
Protocols: []int{AudioProtocolDAAST1, AudioProtocolDAAST1Wrapper},
47+
Sequence: 1,
48+
BAttr: []int{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert},
49+
MaxExtended: 30,
50+
MinBitrate: 300,
51+
MaxBitrate: 1500,
52+
Delivery: []int{ContentDeliveryProgressive},
53+
CompanionAd: []Banner{
54+
{W: 300, H: 250, ID: "1234567893-1", Pos: AdPosAboveFold, BAttr: []int{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert}, ExpDir: []int{ExpDirRight, ExpDirDown}},
55+
{W: 728, H: 90, ID: "1234567893-2", Pos: AdPosAboveFold, BAttr: []int{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert}},
56+
},
57+
CompanionType: []int{VASTCompanionStatic, VASTCompanionHTML},
58+
}
59+
if exp, got := ErrInvalidAudioNoMimes, subject.Validate(); !errors.Is(exp, got) {
60+
t.Fatalf("expected %v, got %v", exp, got)
61+
}
62+
}

banner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package openrtb
22

3-
// The "banner" object must be included directly in the impression object if the impression offered
3+
// Banner object must be included directly in the impression object if the impression offered
44
// for auction is display or rich media, or it may be optionally embedded in the video object to
55
// describe the companion banners available for the linear or non-linear video ad. The banner
66
// object may include a unique identifier; this can be useful if these IDs can be leveraged in the

banner_test.go

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1-
package openrtb
1+
package openrtb_test
22

33
import (
4-
. "github.com/onsi/ginkgo"
5-
. "github.com/onsi/gomega"
4+
"reflect"
5+
"testing"
6+
7+
. "github.com/UnityTech/openrtb"
68
)
79

8-
var _ = Describe("Banner", func() {
10+
func TestBanner(t *testing.T) {
911
var subject *Banner
12+
if err := fixture("banner", &subject); err != nil {
13+
t.Fatalf("expected no error, got %v", err)
14+
}
1015

11-
BeforeEach(func() {
12-
err := fixture("banner", &subject)
13-
Expect(err).NotTo(HaveOccurred())
14-
})
15-
16-
It("should parse correctly", func() {
17-
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-
}))
25-
})
26-
27-
})
16+
exp := &Banner{
17+
W: 728,
18+
H: 90,
19+
Pos: AdPosAboveFold,
20+
BType: []int{BannerTypeFrame},
21+
BAttr: []int{CreativeAttributeWindowsDialogOrAlert},
22+
Api: []int{APIFrameworkMRAID1},
23+
VCM: 1,
24+
}
25+
if got := subject; !reflect.DeepEqual(exp, got) {
26+
t.Errorf("expected %+v, got %+v", exp, got)
27+
}
28+
}

bench_test.go

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

33
import (
44
"encoding/json"
5-
"io/ioutil"
5+
"os"
66
"path/filepath"
77
"testing"
88
)
99

1010
func BenchmarkBidRequest_Unmarshal(b *testing.B) {
11-
data, err := ioutil.ReadFile(filepath.Join("testdata", "breq.video.json"))
11+
data, err := os.ReadFile(filepath.Join("testdata", "breq.video.json"))
1212
if err != nil {
1313
b.Fatal(err.Error())
1414
}
@@ -23,7 +23,7 @@ func BenchmarkBidRequest_Unmarshal(b *testing.B) {
2323
}
2424

2525
func BenchmarkBidRequest_Marshal(b *testing.B) {
26-
data, err := ioutil.ReadFile(filepath.Join("testdata", "breq.video.json"))
26+
data, err := os.ReadFile(filepath.Join("testdata", "breq.video.json"))
2727
if err != nil {
2828
b.Fatal(err.Error())
2929
}

0 commit comments

Comments
 (0)