Skip to content

Commit

Permalink
New major release
Browse files Browse the repository at this point in the history
  • Loading branch information
dim committed Oct 28, 2019
1 parent f0c31f9 commit 62ce92d
Show file tree
Hide file tree
Showing 50 changed files with 1,196 additions and 691 deletions.
10 changes: 5 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
language: go
go:
- 1.10.x
- 1.11.x
install:
- go get -t ./...
- 1.12.x
- 1.13.x
env:
- GO111MODULE=on

cache:
directories:
- $GOPATH/pkg/mod
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
42 changes: 6 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
# Go OpenRTB v2.x
# OpenRTB

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

OpenRTB implementation for Go
OpenRTB structs and validations for Go.

## Requirements

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

## Installation

To install, use `go get`:

```shell
go get github.com/bsm/openrtb
go get github.com/bsm/openrtb/v3
```

## Usage

Import the package:

```go
package main

import (
"log"
"github.com/bsm/openrtb"
"github.com/bsm/openrtb/v3"
)

func main() {
Expand All @@ -36,38 +34,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
48 changes: 24 additions & 24 deletions audio.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,38 @@ import (

// Validation errors
var (
ErrInvalidAudioNoMimes = errors.New("openrtb: audio has no mimes")
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
MaxDuration int `json:"maxduration,omitempty"` // Maximum video ad duration in seconds
Protocols []int `json:"protocols,omitempty"` // Video bid response protocols
StartDelay int `json:"startdelay,omitempty"` // Indicates the start delay in seconds
Sequence int `json:"sequence,omitempty"` // Default: 1
BAttr []int `json:"battr,omitempty"` // Blocked creative attributes
MaxExtended int `json:"maxextended,omitempty"` // Maximum extended video ad duration
MinBitrate int `json:"minbitrate,omitempty"` // Minimum bit rate in Kbps
MaxBitrate int `json:"maxbitrate,omitempty"` // Maximum bit rate in Kbps
Delivery []int `json:"delivery,omitempty"` // List of supported delivery methods
CompanionAd []Banner `json:"companionad,omitempty"`
API []int `json:"api,omitempty"`
CompanionType []int `json:"companiontype,omitempty"`
MaxSequence int `json:"maxseq,omitempty"` // The maximumnumber of ads that canbe played in an ad pod.
Feed int `json:"feed,omitempty"` // Type of audio feed.
Stitched int `json:"stitched,omitempty"` // Indicates if the ad is stitched with audio content or delivered independently
NVol int `json:"nvol,omitempty"` // Volume normalization mode.
Ext json.RawMessage `json:"ext,omitempty"`
MIMEs []string `json:"mimes"` // Content MIME types supported.
MinDuration int `json:"minduration,omitempty"` // Minimum video ad duration in seconds
MaxDuration int `json:"maxduration,omitempty"` // Maximum video ad duration in seconds
Protocols []Protocol `json:"protocols,omitempty"` // Video bid response protocols
StartDelay StartDelay `json:"startdelay,omitempty"` // Indicates the start delay in seconds
Sequence int `json:"sequence,omitempty"` // Default: 1
BlockedAttrs []CreativeAttribute `json:"battr,omitempty"` // Blocked creative attributes
MaxExtended int `json:"maxextended,omitempty"` // Maximum extended video ad duration
MinBitrate int `json:"minbitrate,omitempty"` // Minimum bit rate in Kbps
MaxBitrate int `json:"maxbitrate,omitempty"` // Maximum bit rate in Kbps
Delivery []ContentDelivery `json:"delivery,omitempty"` // List of supported delivery methods
CompanionAds []Banner `json:"companionad,omitempty"`
APIs []APIFramework `json:"api,omitempty"`
CompanionTypes []CompanionType `json:"companiontype,omitempty"`
MaxSequence int `json:"maxseq,omitempty"` // The maximumnumber of ads that canbe played in an ad pod.
Feed FeedType `json:"feed,omitempty"` // Type of audio feed.
Stitched int `json:"stitched,omitempty"` // Indicates if the ad is stitched with audio content or delivered independently
VolumeNorm VolumeNorm `json:"nvol,omitempty"` // Volume normalization mode.
Ext json.RawMessage `json:"ext,omitempty"`
}

type jsonAudio Audio

// Validates the object
// Validate the object
func (a *Audio) Validate() error {
if len(a.Mimes) == 0 {
return ErrInvalidAudioNoMimes
if len(a.MIMEs) == 0 {
return ErrInvalidAudioNoMIMEs
}
return nil
}
Expand Down
61 changes: 30 additions & 31 deletions audio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,50 +9,49 @@ var _ = Describe("Audio", func() {
var subject *Audio

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

It("should parse correctly", func() {
Expect(subject).To(Equal(&Audio{
Mimes: []string{
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}},
MinDuration: 5,
MaxDuration: 30,
Protocols: []Protocol{ProtocolDAAST1, ProtocolDAAST1Wrapper},
Sequence: 1,
BlockedAttrs: []CreativeAttribute{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert},
MaxExtended: 30,
MinBitrate: 300,
MaxBitrate: 1500,
Delivery: []ContentDelivery{ContentDeliveryProgressive},
CompanionAds: []Banner{
{Width: 300, Height: 250, ID: "1234567893-1", Position: AdPositionAboveFold, BlockedAttrs: []CreativeAttribute{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert}, ExpDirs: []ExpDir{ExpDirRight, ExpDirDown}},
{Width: 728, Height: 90, ID: "1234567893-2", Position: AdPositionAboveFold, BlockedAttrs: []CreativeAttribute{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert}},
},
API: []int{APIFrameworkVPAID1, APIFrameworkVPAID2},
CompanionType: []int{VASTCompanionStatic, VASTCompanionHTML},
APIs: []APIFramework{APIFrameworkVPAID1, APIFrameworkVPAID2},
CompanionTypes: []CompanionType{CompanionTypeStatic, CompanionTypeHTML},
}))
})

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}},
MinDuration: 5,
MaxDuration: 30,
Protocols: []Protocol{ProtocolDAAST1, ProtocolDAAST1Wrapper},
Sequence: 1,
BlockedAttrs: []CreativeAttribute{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert},
MaxExtended: 30,
MinBitrate: 300,
MaxBitrate: 1500,
Delivery: []ContentDelivery{ContentDeliveryProgressive},
CompanionAds: []Banner{
{Width: 300, Height: 250, ID: "1234567893-1", Position: AdPositionAboveFold, BlockedAttrs: []CreativeAttribute{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert}, ExpDirs: []ExpDir{ExpDirRight, ExpDirDown}},
{Width: 728, Height: 90, ID: "1234567893-2", Position: AdPositionAboveFold, BlockedAttrs: []CreativeAttribute{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert}},
},
CompanionType: []int{VASTCompanionStatic, VASTCompanionHTML},
}).Validate()).To(Equal(ErrInvalidAudioNoMimes))
CompanionTypes: []CompanionType{CompanionTypeStatic, CompanionTypeHTML},
}).Validate()).To(Equal(ErrInvalidAudioNoMIMEs))
})

})
36 changes: 18 additions & 18 deletions banner.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@ package openrtb

import "encoding/json"

// 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
// VAST response to dictate placement of the companion creatives when multiple companion ad
// opportunities of the same size are available on a page.
type Banner struct {
W int `json:"w,omitempty"` // Width
H int `json:"h,omitempty"` // Height
Format []Format `json:"format,omitempty"` //Array of format objects representing the banner sizes permitted.
WMax int `json:"wmax,omitempty"` // Width maximum DEPRECATED
HMax int `json:"hmax,omitempty"` // Height maximum DEPRECATED
WMin int `json:"wmin,omitempty"` // Width minimum DEPRECATED
HMin int `json:"hmin,omitempty"` // Height minimum DEPRECATED
ID string `json:"id,omitempty"` // A unique identifier
BType []int `json:"btype,omitempty"` // Blocked creative types
BAttr []int `json:"battr,omitempty"` // Blocked creative attributes
Pos int `json:"pos,omitempty"` // Ad Position
Mimes []string `json:"mimes,omitempty"` // Whitelist of content MIME types supported
TopFrame int `json:"topframe,omitempty"` // Default: 0 ("1": Delivered in top frame, "0": Elsewhere)
ExpDir []int `json:"expdir,omitempty"` // Specify properties for an expandable ad
Api []int `json:"api,omitempty"` // List of supported API frameworks
Vcm int `json:"vcm,omitempty"` // Represents the relationship with video. 0 = concurrent, 1 = end-card
Ext json.RawMessage `json:"ext,omitempty"`
Width int `json:"w,omitempty"` // Width
Height int `json:"h,omitempty"` // Height
Formats []Format `json:"format,omitempty"` // Array of format objects representing the banner sizes permitted.
WidthMax int `json:"wmax,omitempty"` // Width maximum DEPRECATED
HeightMax int `json:"hmax,omitempty"` // Height maximum DEPRECATED
WidthMin int `json:"wmin,omitempty"` // Width minimum DEPRECATED
HeightMin int `json:"hmin,omitempty"` // Height minimum DEPRECATED
ID string `json:"id,omitempty"` // A unique identifier
BlockedTypes []BannerType `json:"btype,omitempty"` // Blocked banner types
BlockedAttrs []CreativeAttribute `json:"battr,omitempty"` // Blocked creative attributes
Position AdPosition `json:"pos,omitempty"` // Ad Position
MIMEs []string `json:"mimes,omitempty"` // Whitelist of content MIME types supported
TopFrame int `json:"topframe,omitempty"` // Default: 0 ("1": Delivered in top frame, "0": Elsewhere)
ExpDirs []ExpDir `json:"expdir,omitempty"` // Specify properties for an expandable ad
APIs []APIFramework `json:"api,omitempty"` // List of supported API frameworks
VCM int `json:"vcm,omitempty"` // Represents the relationship with video. 0 = concurrent, 1 = end-card
Ext json.RawMessage `json:"ext,omitempty"`
}
17 changes: 8 additions & 9 deletions banner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,18 @@ var _ = Describe("Banner", func() {
var subject *Banner

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

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},
Vcm: 1,
Width: 728,
Height: 90,
Position: AdPositionAboveFold,
BlockedTypes: []BannerType{BannerTypeFrame},
BlockedAttrs: []CreativeAttribute{CreativeAttributeWindowsDialogOrAlert},
APIs: []APIFramework{APIFrameworkMRAID1},
VCM: 1,
}))
})

Expand Down
Loading

0 comments on commit 62ce92d

Please sign in to comment.