Skip to content

Commit

Permalink
Merge pull request #35 from UnityTech/syncFork
Browse files Browse the repository at this point in the history
[PAT-376] Sync Fork to get ORTB 2.6 changes
  • Loading branch information
rourkewhite authored Mar 26, 2024
2 parents 8e6cd18 + f9fae6e commit 6c1a9c3
Show file tree
Hide file tree
Showing 66 changed files with 1,759 additions and 948 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Test
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
go:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [1.18.x, 1.19.x]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
cache: true
- run: make test
golangci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: 1.x
cache: true
- uses: golangci/golangci-lint-action@v3
with:
version: latest
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.makefile

.idea
.vscode
7 changes: 0 additions & 7 deletions .travis.yml

This file was deleted.

24 changes: 24 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Copyright (c) 2015 Black Square Media Ltd. All rights reserved.
(The MIT License)

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Some test examples were taken from:
https://code.google.com/p/openrtb/wiki/OpenRTB_Examples
41 changes: 8 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# Go OpenRTB v2.x
# OpenRTB

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

OpenRTB implementation for Go
OpenRTB structs and validations for Go.

## Requirements

Requires Go 1.8+ for proper `json.RawMessage` marshaling.

## Installation

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

## Usage

Import the package:

```go
package main

import (
"log"

"github.com/UnityTech/openrtb"
)

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

var req *openrtb.BidRequest
err = json.NewDecoder(file).Decode(&req)
if err != nil {
if err := json.NewDecoder(file).Decode(&req); err != nil {
log.Fatal(err)
}

log.Printf("%+v\n", req)
}
```

## Licence

Copyright (c) 2015 Black Square Media Ltd. All rights reserved.
(The MIT License)

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Some test examples were taken from:
https://code.google.com/p/openrtb/wiki/OpenRTB_Examples
4 changes: 2 additions & 2 deletions audio.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var (
ErrInvalidAudioNoMimes = errors.New("openrtb: audio has no mimes")
)

// The "audio" object must be included directly in the impression object
// Audio object must be included directly in the impression object
type Audio struct {
Mimes []string `json:"mimes"` // Content MIME types supported.
MinDuration int `json:"minduration,omitempty"` // Minimum video ad duration in seconds
Expand All @@ -35,7 +35,7 @@ type Audio struct {

type jsonAudio Audio

// Validates the object
// Validate the object
func (a *Audio) Validate() error {
if len(a.Mimes) == 0 {
return ErrInvalidAudioNoMimes
Expand Down
106 changes: 55 additions & 51 deletions audio_test.go
Original file line number Diff line number Diff line change
@@ -1,58 +1,62 @@
package openrtb
package openrtb_test

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"errors"
"reflect"
"testing"

. "github.com/UnityTech/openrtb"
)

var _ = Describe("Audio", func() {
func TestAudio(t *testing.T) {
var subject *Audio
if err := fixture("audio", &subject); err != nil {
t.Fatalf("expected no error, got %v", err)
}

BeforeEach(func() {
err := fixture("audio", &subject)
Expect(err).NotTo(HaveOccurred())
})

It("should parse correctly", func() {
Expect(subject).To(Equal(&Audio{
Mimes: []string{
"audio/mp4",
},
MinDuration: 5,
MaxDuration: 30,
Protocols: []int{AudioProtocolDAAST1, AudioProtocolDAAST1Wrapper},
Sequence: 1,
BAttr: []int{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert},
MaxExtended: 30,
MinBitrate: 300,
MaxBitrate: 1500,
Delivery: []int{ContentDeliveryProgressive},
CompanionAd: []Banner{
{W: 300, H: 250, ID: "1234567893-1", Pos: AdPosAboveFold, BAttr: []int{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert}, ExpDir: []int{ExpDirRight, ExpDirDown}},
{W: 728, H: 90, ID: "1234567893-2", Pos: AdPosAboveFold, BAttr: []int{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert}},
},
API: []int{APIFrameworkVPAID1, APIFrameworkVPAID2},
CompanionType: []int{VASTCompanionStatic, VASTCompanionHTML},
}))
})

It("should validate", func() {
Expect((&Audio{
MinDuration: 5,
MaxDuration: 30,
Protocols: []int{AudioProtocolDAAST1, AudioProtocolDAAST1Wrapper},
Sequence: 1,
BAttr: []int{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert},
MaxExtended: 30,
MinBitrate: 300,
MaxBitrate: 1500,
Delivery: []int{ContentDeliveryProgressive},
CompanionAd: []Banner{
{W: 300, H: 250, ID: "1234567893-1", Pos: AdPosAboveFold, BAttr: []int{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert}, ExpDir: []int{ExpDirRight, ExpDirDown}},
{W: 728, H: 90, ID: "1234567893-2", Pos: AdPosAboveFold, BAttr: []int{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert}},
},
CompanionType: []int{VASTCompanionStatic, VASTCompanionHTML},
}).Validate()).To(Equal(ErrInvalidAudioNoMimes))
})
exp := &Audio{
Mimes: []string{
"audio/mp4",
},
MinDuration: 5,
MaxDuration: 30,
Protocols: []int{AudioProtocolDAAST1, AudioProtocolDAAST1Wrapper},
Sequence: 1,
BAttr: []int{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert},
MaxExtended: 30,
MinBitrate: 300,
MaxBitrate: 1500,
Delivery: []int{ContentDeliveryProgressive},
CompanionAd: []Banner{
{W: 300, H: 250, ID: "1234567893-1", Pos: AdPosAboveFold, BAttr: []int{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert}, ExpDir: []int{ExpDirRight, ExpDirDown}},
{W: 728, H: 90, ID: "1234567893-2", Pos: AdPosAboveFold, BAttr: []int{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert}},
},
API: []int{APIFrameworkVPAID1, APIFrameworkVPAID2},
CompanionType: []int{VASTCompanionStatic, VASTCompanionHTML},
}
if got := subject; !reflect.DeepEqual(exp, got) {
t.Errorf("expected %+v, got %+v", exp, got)
}
}

})
func TestAudio_Validate(t *testing.T) {
subject := &Audio{
MinDuration: 5,
MaxDuration: 30,
Protocols: []int{AudioProtocolDAAST1, AudioProtocolDAAST1Wrapper},
Sequence: 1,
BAttr: []int{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert},
MaxExtended: 30,
MinBitrate: 300,
MaxBitrate: 1500,
Delivery: []int{ContentDeliveryProgressive},
CompanionAd: []Banner{
{W: 300, H: 250, ID: "1234567893-1", Pos: AdPosAboveFold, BAttr: []int{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert}, ExpDir: []int{ExpDirRight, ExpDirDown}},
{W: 728, H: 90, ID: "1234567893-2", Pos: AdPosAboveFold, BAttr: []int{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert}},
},
CompanionType: []int{VASTCompanionStatic, VASTCompanionHTML},
}
if exp, got := ErrInvalidAudioNoMimes, subject.Validate(); !errors.Is(exp, got) {
t.Fatalf("expected %v, got %v", exp, got)
}
}
2 changes: 1 addition & 1 deletion banner.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package openrtb

// The "banner" object must be included directly in the impression object if the impression offered
// Banner object must be included directly in the impression object if the impression offered
// for auction is display or rich media, or it may be optionally embedded in the video object to
// describe the companion banners available for the linear or non-linear video ad. The banner
// object may include a unique identifier; this can be useful if these IDs can be leveraged in the
Expand Down
43 changes: 22 additions & 21 deletions banner_test.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
package openrtb
package openrtb_test

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"reflect"
"testing"

. "github.com/UnityTech/openrtb"
)

var _ = Describe("Banner", func() {
func TestBanner(t *testing.T) {
var subject *Banner
if err := fixture("banner", &subject); err != nil {
t.Fatalf("expected no error, got %v", err)
}

BeforeEach(func() {
err := fixture("banner", &subject)
Expect(err).NotTo(HaveOccurred())
})

It("should parse correctly", func() {
Expect(subject).To(Equal(&Banner{
W: 728,
H: 90,
Pos: AdPosAboveFold,
BType: []int{BannerTypeFrame},
BAttr: []int{CreativeAttributeWindowsDialogOrAlert},
Api: []int{APIFrameworkMRAID1},
}))
})

})
exp := &Banner{
W: 728,
H: 90,
Pos: AdPosAboveFold,
BType: []int{BannerTypeFrame},
BAttr: []int{CreativeAttributeWindowsDialogOrAlert},
Api: []int{APIFrameworkMRAID1},
VCM: 1,
}
if got := subject; !reflect.DeepEqual(exp, got) {
t.Errorf("expected %+v, got %+v", exp, got)
}
}
6 changes: 3 additions & 3 deletions bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package openrtb

import (
"encoding/json"
"io/ioutil"
"os"
"path/filepath"
"testing"
)

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

func BenchmarkBidRequest_Marshal(b *testing.B) {
data, err := ioutil.ReadFile(filepath.Join("testdata", "breq.video.json"))
data, err := os.ReadFile(filepath.Join("testdata", "breq.video.json"))
if err != nil {
b.Fatal(err.Error())
}
Expand Down
21 changes: 15 additions & 6 deletions bid.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var (
ErrInvalidBidNoImpID = errors.New("openrtb: bid is missing impression ID")
)

// Bid object contains bid information.
// ID, ImpID and Price are required; all other optional.
// If the bidder wins the impression, the exchange calls notice URL (nurl)
// a) to inform the bidder of the win;
Expand All @@ -32,7 +33,7 @@ type Bid struct {
Tactic string `json:"tactic,omitempty"` // Tactic ID to enable buyers to label bids for reporting to the exchange the tactic through which their bid was submitted.
Cat []string `json:"cat,omitempty"` // IAB content categories of the creative. Refer to List 5.1
Attr []int `json:"attr,omitempty"` // Array of creative attributes.
API int `json:"api,omitempty"` // API required by the markup if applicable
API int `json:"api,omitempty"` // API required by the markup if applicable, NOTE: for ORTB ver <= 2.5 APIFramework supported is 1 to 6.
Protocol int `json:"protocol,omitempty"` // Video response protocol of the markup if applicable
QAGMediaRating int `json:"qagmediarating,omitempty"` // Creative media rating per IQG guidelines.
Language string `json:"language,omitempty"` // Language of the creative using ISO-639-1-alpha-2.
Expand All @@ -41,11 +42,19 @@ type Bid struct {
W int `json:"w,omitempty"` // Width of the ad in pixels.
WRatio int `json:"wratio,omitempty"` // Relative width of the creative when expressing size as a ratio.
HRatio int `json:"hratio,omitempty"` // Relative height of the creative when expressing size as a ratio.
Exp int `json:"exp,omitempty"` // Advisory as to the number of seconds the bidder is willing to wait between the auction and the actual impression.
ContentType string `json:"-"` // Content of the bid
MediaType string `json:"-"` // Media of the impression e.g. video/display
IsOMEnabled bool `json:"-"` // Flag to send indicate to the Sdk whether or not to run om scripts
Ext Extension `json:"ext,omitempty"`

APIS []int `json:"apis,omitempty"` // APIS required by the markup if applicable.
LangB string `json:"langb,omitempty"` // Language of the creative using IETF BCP 47. Only one of language or langb should be present.
Duration int `json:"dur,omitempty"` // Duration of the video or audio creative in seconds.
MarkupType MarkupType `json:"mtype,omitempty"` // Creative markup so that it can properly be associated.
SlotInPod SlotPositionInPod `json:"slotinpod,omitempty"` // Indicates that the bid response is only eligible for a specific position.
CategoryTaxonomy CategoryTaxonomy `json:"cattax,omitempty"` // Defines the taxonomy in use.

Exp int `json:"exp,omitempty"` // Advisory as to the number of seconds the bidder is willing to wait between the auction and the actual impression.
ContentType string `json:"-"` // Content of the bid
MediaType string `json:"-"` // Media of the impression e.g. video/display
IsOMEnabled bool `json:"-"` // Flag to send indicate to the Sdk whether or not to run om scripts
Ext Extension `json:"ext,omitempty"`
}

// Validate required attributes
Expand Down
Loading

0 comments on commit 6c1a9c3

Please sign in to comment.