Skip to content

Commit a6d47db

Browse files
committed
Improvements for OpenRTB 2.2
1 parent f0fde97 commit a6d47db

21 files changed

+300
-323
lines changed

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
default: test
2+
3+
deps:
4+
go get -t ./...
5+
6+
test: deps
7+
go test ./...

app_test.go

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
package openrtb
22

33
import (
4-
"github.com/stretchr/testify/assert"
5-
"testing"
4+
. "github.com/onsi/ginkgo"
5+
. "github.com/onsi/gomega"
66
)
77

8-
func TestApp_IsPrivacyPolicy(t *testing.T) {
9-
a := &App{}
10-
assert.Equal(t, a.IsPrivacyPolicy(), false)
11-
}
8+
var _ = Describe("App", func() {
9+
var subject *App
1210

13-
func TestApp_IsPaid(t *testing.T) {
14-
a := &App{}
15-
assert.Equal(t, a.IsPaid(), false)
16-
}
11+
BeforeEach(func() {
12+
subject = new(App)
13+
})
1714

18-
func TestApp_WithDefaults(t *testing.T) {
19-
a := &App{}
20-
app := a.WithDefaults()
21-
assert.Equal(t, *app.Privacypolicy, 0)
22-
assert.Equal(t, *app.Paid, 0)
23-
}
15+
It("should have accessors", func() {
16+
Expect(subject.IsPrivacyPolicy()).To(BeFalse())
17+
Expect(subject.IsPaid()).To(BeFalse())
18+
})
19+
20+
It("should have defaults", func() {
21+
subject.WithDefaults()
22+
Expect(*subject.Privacypolicy).To(Equal(0))
23+
Expect(*subject.Paid).To(Equal(0))
24+
})
25+
})

banner.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ package openrtb
99
type Banner struct {
1010
W *int `json:"w,omitempty"` // Width
1111
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:"wmax,omitempty"` // Width minimum
15+
Hmin *int `json:"hmax,omitempty"` // Height minimum
1216
Id *string `json:"id,omitempty"` // A unique identifier
1317
Pos *int `json:"pos,omitempty"` // Ad Position
1418
Btype []int `json:"btype,omitempty"` // Blocked creative types

banner_test.go

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
package openrtb
22

33
import (
4-
"github.com/stretchr/testify/assert"
5-
"testing"
4+
. "github.com/onsi/ginkgo"
5+
. "github.com/onsi/gomega"
66
)
77

8-
func TestBanner_IsTopFrame(t *testing.T) {
9-
b := &Banner{}
10-
assert.Equal(t, b.IsTopFrame(), false)
11-
}
8+
var _ = Describe("Banner", func() {
9+
var subject *Banner
1210

13-
func TestBanner_Position(t *testing.T) {
14-
b := &Banner{}
15-
assert.Equal(t, b.Position(), 0)
16-
}
11+
BeforeEach(func() {
12+
subject = new(Banner)
13+
})
1714

18-
func TestBanner_WithDefaults(t *testing.T) {
19-
b := &Banner{}
20-
banner := b.WithDefaults()
21-
assert.Equal(t, *banner.Topframe, 0)
22-
assert.Equal(t, *banner.Pos, AD_POS_UNKNOWN)
23-
}
15+
It("should have accessors", func() {
16+
Expect(subject.IsTopFrame()).To(BeFalse())
17+
Expect(subject.Position()).To(Equal(0))
18+
})
19+
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+
})
25+
})

bid.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,20 @@ type Bid struct {
2929

3030
// Validation errors
3131
var (
32-
invalidBidId = errors.New("openrtb response: bid is missing ID")
33-
invalidBidImpid = errors.New("openrtb response: bid is missing impression ID")
34-
invalidBidPrice = errors.New("openrtb response: bid is missing price")
32+
ErrInvalidBidID = errors.New("openrtb response: bid is missing ID")
33+
ErrInvalidBidImpID = errors.New("openrtb response: bid is missing impression ID")
34+
ErrInvalidBidPrice = errors.New("openrtb response: bid is missing price")
3535
)
3636

3737
// Validate Bid required attributes
3838
func (bid *Bid) Valid() (bool, error) {
3939

4040
if bid.Id == nil {
41-
return false, invalidBidId
41+
return false, ErrInvalidBidID
4242
} else if bid.Impid == nil {
43-
return false, invalidBidImpid
43+
return false, ErrInvalidBidImpID
4444
} else if bid.Price == nil {
45-
return false, invalidBidPrice
45+
return false, ErrInvalidBidPrice
4646
}
4747

4848
return true, nil

bid_test.go

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

33
import (
4-
"github.com/stretchr/testify/assert"
5-
"testing"
4+
. "github.com/onsi/ginkgo"
5+
. "github.com/onsi/gomega"
66
)
77

8-
func TestBid_Valid(t *testing.T) {
9-
bid := &Bid{}
8+
var _ = Describe("Bid", func() {
9+
var subject *Bid
1010

11-
ok, err := bid.Valid()
12-
assert.Equal(t, ok, false)
13-
if err != nil {
14-
assert.Equal(t, err.Error(), "openrtb response: bid is missing ID")
15-
}
11+
BeforeEach(func() {
12+
subject = new(Bid)
13+
})
1614

17-
bid.SetID("BIDID")
18-
ok, err = bid.Valid()
19-
assert.Equal(t, ok, false)
20-
if err != nil {
21-
assert.Equal(t, err.Error(), "openrtb response: bid is missing impression ID")
22-
}
15+
It("should have validation", func() {
16+
ok, err := subject.Valid()
17+
Expect(err).To(HaveOccurred())
18+
Expect(ok).To(BeFalse())
2319

24-
bid.SetImpID("IMPID")
25-
ok, err = bid.Valid()
26-
assert.Equal(t, ok, false)
27-
if err != nil {
28-
assert.Equal(t, err.Error(), "openrtb response: bid is missing price")
29-
}
20+
subject.SetID("BIDID")
21+
subject.SetImpID("IMPID")
22+
subject.SetPrice(0.0)
3023

31-
bid.SetPrice(0.0)
32-
ok, err = bid.Valid()
33-
assert.Equal(t, ok, true)
34-
}
24+
ok, err = subject.Valid()
25+
Expect(err).NotTo(HaveOccurred())
26+
Expect(ok).To(BeTrue())
27+
})
28+
29+
})

device.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ type Device struct {
1212
Didmd5 *string `json:"didmd5,omitempty"` // MD5 hashed device ID
1313
Dpidsha1 *string `json:"dpidsha1,omitempty"` // SHA1 hashed platform device ID
1414
Dpidmd5 *string `json:"dpidmd5,omitempty"` // MD5 hashed platform device ID
15+
Macsha1 *string `json:"macsha1,omitempty"` // SHA1 hashed device ID; IMEI when available, else MEID or ESN
16+
Macmd5 *string `json:"macmd5,omitempty"` // MD5 hashed device ID; IMEI when available, else MEID or ESN
1517
Ipv6 *string `json:"ipv6,omitempty"` // IPv6
1618
Carrier *string `json:"carrier,omitempty"` // Carrier or ISP derived from the IP address
1719
Language *string `json:"language,omitempty"` // Browser language
@@ -23,6 +25,7 @@ type Device struct {
2325
Connectiontype *int `json:"connectiontype,omitempty"`
2426
Devicetype *int `json:"devicetype,omitempty"`
2527
Flashver *string `json:"flashver,omitempty"` // Flash version
28+
Ifa *string `json:"ifa,omitempty"` // Native identifier for advertisers
2629
Ext Extensions `json:"ext,omitempty"`
2730
}
2831

device_test.go

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

33
import (
4-
"github.com/stretchr/testify/assert"
5-
"testing"
4+
. "github.com/onsi/ginkgo"
5+
. "github.com/onsi/gomega"
66
)
77

8-
func TestDevice_IsDnt(t *testing.T) {
9-
d := &Device{}
10-
assert.Equal(t, d.IsDnt(), false)
11-
}
8+
var _ = Describe("Device", func() {
9+
var subject *Device
1210

13-
func TestDevice_IsJs(t *testing.T) {
14-
d := &Device{}
15-
assert.Equal(t, d.IsJs(), false)
16-
}
11+
BeforeEach(func() {
12+
subject = new(Device)
13+
})
1714

18-
func TestDevice_ConnectionType(t *testing.T) {
19-
d := &Device{}
20-
assert.Equal(t, d.ConnectionType(), 0)
21-
}
15+
It("should have accessors", func() {
16+
Expect(subject.IsDnt()).To(BeFalse())
17+
Expect(subject.IsJs()).To(BeFalse())
18+
Expect(subject.ConnectionType()).To(Equal(0))
19+
Expect(subject.DeviceType()).To(Equal(0))
20+
})
2221

23-
func TestDevice_DeviceType(t *testing.T) {
24-
d := &Device{}
25-
assert.Equal(t, d.DeviceType(), 0)
26-
}
27-
28-
func TestDevice_WithDefaults(t *testing.T) {
29-
d := &Device{}
30-
device := d.WithDefaults()
31-
32-
assert.Equal(t, *device.Dnt, 0)
33-
assert.Equal(t, *device.Js, 0)
34-
assert.Equal(t, *device.Connectiontype, CONN_TYPE_UNKNOWN)
35-
assert.Equal(t, *device.Devicetype, DEVICE_TYPE_UNKNOWN)
36-
}
22+
It("should have defaults", func() {
23+
subject.WithDefaults()
24+
Expect(*subject.Dnt).To(Equal(0))
25+
Expect(*subject.Js).To(Equal(0))
26+
Expect(*subject.Connectiontype).To(Equal(CONN_TYPE_UNKNOWN))
27+
Expect(*subject.Connectiontype).To(Equal(DEVICE_TYPE_UNKNOWN))
28+
})
29+
})

impression.go

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,32 @@ type Impression struct {
1919
Tagid *string `json:"tagid,omitempty"` // Identifier for specific ad placement or ad tag
2020
Bidfloor *float32 `json:"bidfloor,omitempty"` // Bid floor for this impression in CPM
2121
Bidfloorcur *string `json:"bidfloorcur,omitempty"` // Currency of bid floor
22+
Secure *int `json:"secure,omitempty"` // Flag to indicate whether the impression requires secure HTTPS URL creative assets and markup.
2223
Iframebuster []string `json:"iframebuster,omitempty"` // Array of names for supportediframe busters.
24+
Pmp *Pmp `json:"pmp,omitempty"` // A reference to the PMP object containing any Deals eligible for the impression object.
2325
Ext Extensions `json:"ext,omitempty"`
2426
}
2527

2628
// Validation errors
2729
var (
28-
invalidImpId = errors.New("openrtb parse: impression ID missing")
29-
invalidImpBoV = errors.New("openrtb parse: impression has neither a banner nor video")
30-
invalidImpBaV = errors.New("openrtb parse: impression has banner and video")
30+
ErrInvalidImpID = errors.New("openrtb parse: impression ID missing")
31+
ErrInvalidImpBoV = errors.New("openrtb parse: impression has neither a banner nor video")
32+
ErrInvalidImpBaV = errors.New("openrtb parse: impression has banner and video")
3133
)
3234

3335
// Validates the `imp` object
3436
func (imp *Impression) Valid() (bool, error) {
3537

3638
if imp.Id == nil {
37-
return false, invalidImpId
39+
return false, ErrInvalidImpID
3840
} else if imp.Banner != nil && imp.Video != nil {
39-
return false, invalidImpBaV
41+
return false, ErrInvalidImpBaV
4042
} else if imp.Video != nil {
4143
if ok, err := imp.Video.Valid(); !ok {
4244
return ok, err
4345
}
4446
} else if imp.Banner == nil {
45-
return false, invalidImpBoV
47+
return false, ErrInvalidImpBoV
4648
}
4749

4850
return true, nil
@@ -86,19 +88,13 @@ func (imp *Impression) SetId(id string) *Impression {
8688
}
8789

8890
// Set the Banner
89-
func (imp *Impression) SetBanner(b Banner) *Impression {
90-
if imp.Banner == nil {
91-
imp.Banner = new(Banner)
92-
}
93-
*imp.Banner = b
91+
func (imp *Impression) SetBanner(b *Banner) *Impression {
92+
imp.Banner = b
9493
return imp
9594
}
9695

9796
// Set the Video
98-
func (imp *Impression) SetVideo(v Video) *Impression {
99-
if imp.Video == nil {
100-
imp.Video = new(Video)
101-
}
102-
*imp.Video = v
97+
func (imp *Impression) SetVideo(v *Video) *Impression {
98+
imp.Video = v
10399
return imp
104100
}

0 commit comments

Comments
 (0)