Skip to content

Commit 236a28e

Browse files
authored
Merge pull request #27 from zukoo/master
Added fields for OpenRTB 2.4
2 parents 1a48cb0 + 0adce5f commit 236a28e

File tree

11 files changed

+271
-53
lines changed

11 files changed

+271
-53
lines changed

audio.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package openrtb
2+
3+
import (
4+
"encoding/json"
5+
"errors"
6+
)
7+
8+
// Validation errors
9+
var (
10+
ErrInvalidAudioNoMimes = errors.New("openrtb: audio has no mimes")
11+
)
12+
13+
// The "audio" object must be included directly in the impression object
14+
type Audio struct {
15+
Mimes []string `json:"mimes,omitempty"` // Content MIME types supported.
16+
MinDuration int `json:"minduration,omitempty"` // Minimum video ad duration in seconds
17+
MaxDuration int `json:"maxduration,omitempty"` // Maximum video ad duration in seconds
18+
Protocols []int `json:"protocols,omitempty"` // Video bid response protocols
19+
StartDelay int `json:"startdelay,omitempty"` // Indicates the start delay in seconds
20+
Sequence int `json:"sequence,omitempty"` // Default: 1
21+
BAttr []int `json:"battr,omitempty"` // Blocked creative attributes
22+
MaxExtended int `json:"maxextended,omitempty"` // Maximum extended video ad duration
23+
MinBitrate int `json:"minbitrate,omitempty"` // Minimum bit rate in Kbps
24+
MaxBitrate int `json:"maxbitrate,omitempty"` // Maximum bit rate in Kbps
25+
Delivery []int `json:"delivery,omitempty"` // List of supported delivery methods
26+
CompanionAd []Banner `json:"companionad,omitempty"`
27+
CompanionType []int `json:"companiontype,omitempty"`
28+
MaxSequence int `json:"maxseq,omitempty"` // The maximumnumber of ads that canbe played in an ad pod.
29+
Feed int `json:"feed,omitempty"` // Type of audio feed.
30+
Stitched int `json:"stitched,omitempty"` // Indicates if the ad is stitched with audio content or delivered independently
31+
NVol int `json:"nvol,omitempty"` // Volume normalization mode.
32+
Ext Extension `json:"ext,omitempty"`
33+
}
34+
35+
type jsonAudio Audio
36+
37+
// Validates the object
38+
func (a *Audio) Validate() error {
39+
if len(a.Mimes) == 0 {
40+
return ErrInvalidAudioNoMimes
41+
}
42+
return nil
43+
}
44+
45+
// MarshalJSON custom marshalling with normalization
46+
func (a *Audio) MarshalJSON() ([]byte, error) {
47+
a.normalize()
48+
return json.Marshal((*jsonAudio)(a))
49+
}
50+
51+
// UnmarshalJSON custom unmarshalling with normalization
52+
func (a *Audio) UnmarshalJSON(data []byte) error {
53+
var h jsonAudio
54+
if err := json.Unmarshal(data, &h); err != nil {
55+
return err
56+
}
57+
58+
*a = (Audio)(h)
59+
a.normalize()
60+
return nil
61+
}
62+
63+
func (a *Audio) normalize() {
64+
if a.Sequence == 0 {
65+
a.Sequence = 1
66+
}
67+
}

audio_test.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package openrtb
2+
3+
import (
4+
. "github.com/onsi/ginkgo"
5+
. "github.com/onsi/gomega"
6+
)
7+
8+
var _ = Describe("Audio", func() {
9+
var subject *Audio
10+
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{13, 14},
26+
MaxExtended: 30,
27+
MinBitrate: 300,
28+
MaxBitrate: 1500,
29+
Delivery: []int{2},
30+
CompanionAd: []Banner{
31+
{W: 300, H: 250, ID: "1234567893-1", Pos: 1, BAttr: []int{13, 14}, ExpDir: []int{ExpDirRight, ExpDirDown}},
32+
{W: 728, H: 90, ID: "1234567893-2", Pos: 1, BAttr: []int{13, 14}},
33+
},
34+
CompanionType: []int{1, 2},
35+
}))
36+
})
37+
38+
It("should validate", func() {
39+
Expect((&Audio{
40+
MinDuration: 5,
41+
MaxDuration: 30,
42+
Protocols: []int{AudioProtocolDAAST1, AudioProtocolDAAST1Wrapper},
43+
Sequence: 1,
44+
BAttr: []int{13, 14},
45+
MaxExtended: 30,
46+
MinBitrate: 300,
47+
MaxBitrate: 1500,
48+
Delivery: []int{2},
49+
CompanionAd: []Banner{
50+
{W: 300, H: 250, ID: "1234567893-1", Pos: 1, BAttr: []int{13, 14}, ExpDir: []int{ExpDirRight, ExpDirDown}},
51+
{W: 728, H: 90, ID: "1234567893-2", Pos: 1, BAttr: []int{13, 14}},
52+
},
53+
CompanionType: []int{1, 2},
54+
}).Validate()).To(Equal(ErrInvalidAudioNoMimes))
55+
})
56+
57+
})

banner.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ 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:"wmin,omitempty"` // Width minimum
15-
HMin int `json:"hmin,omitempty"` // Height minimum
12+
Format *Format `json:"format,omitempty"` //Array of format objects representing the banner sizes permitted.
13+
WMax int `json:"wmax,omitempty"` // Width maximum DEPRECATED
14+
HMax int `json:"hmax,omitempty"` // Height maximum DEPRECATED
15+
WMin int `json:"wmin,omitempty"` // Width minimum DEPRECATED
16+
HMin int `json:"hmin,omitempty"` // Height minimum DEPRECATED
1617
ID string `json:"id,omitempty"` // A unique identifier
17-
Pos int `json:"pos,omitempty"` // Ad Position
1818
BType []int `json:"btype,omitempty"` // Blocked creative types
1919
BAttr []int `json:"battr,omitempty"` // Blocked creative attributes
20+
Pos int `json:"pos,omitempty"` // Ad Position
2021
Mimes []string `json:"mimes,omitempty"` // Whitelist of content MIME types supported
2122
TopFrame int `json:"topframe,omitempty"` // Default: 0 ("1": Delivered in top frame, "0": Elsewhere)
2223
ExpDir []int `json:"expdir,omitempty"` // Specify properties for an expandable ad

bid.go

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,27 @@ var (
1616
// Cid can be used to block ads that were previously identified as inappropriate.
1717
// Substitution macros may allow a bidder to use a static notice URL for all of its bids.
1818
type Bid struct {
19-
ID string `json:"id"`
20-
ImpID string `json:"impid"` // Required string ID of the impression object to which this bid applies.
21-
Price float64 `json:"price"` // Bid price in CPM. Suggests using integer math for accounting to avoid rounding errors.
22-
AdID string `json:"adid,omitempty"` // References the ad to be served if the bid wins.
23-
NURL string `json:"nurl,omitempty"` // Win notice URL.
24-
AdMarkup string `json:"adm,omitempty"` // Actual ad markup. XHTML if a response to a banner object, or VAST XML if a response to a video object.
25-
AdvDomain []string `json:"adomain,omitempty"` // Advertiser’s primary or top-level domain for advertiser checking; or multiple if imp rotating.
26-
IURL string `json:"iurl,omitempty"` // Sample image URL.
27-
CampaignID string `json:"cid,omitempty"` // Campaign ID that appears with the Ad markup.
28-
CreativeID string `json:"crid,omitempty"` // Creative ID for reporting content issues or defects. This could also be used as a reference to a creative ID that is posted with an exchange.
29-
Cat []string `json:"cat,omitempty"` // IAB content categories of the creative. Refer to List 5.1
30-
Attr []int `json:"attr,omitempty"` // Array of creative attributes.
31-
DealID string `json:"dealid,omitempty"` // DealID extension of private marketplace deals
32-
H int `json:"h,omitempty"` // Height of the ad in pixels.
33-
W int `json:"w,omitempty"` // Width of the ad in pixels.
34-
Ext Extension `json:"ext,omitempty"`
19+
ID string `json:"id"`
20+
ImpID string `json:"impid"` // Required string ID of the impression object to which this bid applies.
21+
Price float64 `json:"price"` // Bid price in CPM. Suggests using integer math for accounting to avoid rounding errors.
22+
AdID string `json:"adid,omitempty"` // References the ad to be served if the bid wins.
23+
NURL string `json:"nurl,omitempty"` // Win notice URL.
24+
AdMarkup string `json:"adm,omitempty"` // Actual ad markup. XHTML if a response to a banner object, or VAST XML if a response to a video object.
25+
AdvDomain []string `json:"adomain,omitempty"` // Advertiser’s primary or top-level domain for advertiser checking; or multiple if imp rotating.
26+
Bundle string `json:"bundle,omitempty"` // A platform-specific application identifier intended to be unique to the app and independent of the exchange.
27+
IURL string `json:"iurl,omitempty"` // Sample image URL.
28+
CampaignID string `json:"cid,omitempty"` // Campaign ID that appears with the Ad markup.
29+
CreativeID string `json:"crid,omitempty"` // Creative ID for reporting content issues or defects. This could also be used as a reference to a creative ID that is posted with an exchange.
30+
Cat []string `json:"cat,omitempty"` // IAB content categories of the creative. Refer to List 5.1
31+
Attr []int `json:"attr,omitempty"` // Array of creative attributes.
32+
API int `json:"api,omitempty"` // API required by the markup if applicable
33+
Protocol int `json:"protocol,omitempty"` // Video response protocol of the markup if applicable
34+
QAGMediaRating int `json:"qagmediarating,omitempty"` // Creative media rating per IQG guidelines.
35+
DealID string `json:"dealid,omitempty"` // DealID extension of private marketplace deals
36+
H int `json:"h,omitempty"` // Height of the ad in pixels.
37+
W int `json:"w,omitempty"` // Width of the ad in pixels.
38+
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.
39+
Ext Extension `json:"ext,omitempty"`
3540
}
3641

3742
// Validate required attributes

bidrequest.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type BidRequest struct {
2727
Cur []string `json:"cur,omitempty"` // Array of allowed currencies
2828
Bcat []string `json:"bcat,omitempty"` // Blocked Advertiser Categories.
2929
BAdv []string `json:"badv,omitempty"` // Array of strings of blocked toplevel domains of advertisers
30+
BApp []string `json:"bapp,omitempty"` // Block list of applications by their platform-specific exchange-independent application identifiers. On Android, these should be bundle or package names (e.g., com.foo.mygame). On iOS, these are numeric IDs.
3031
Regs *Regulations `json:"regs,omitempty"`
3132
Ext Extension `json:"ext,omitempty"`
3233

content.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@ type Content struct {
1111
Title string `json:"title,omitempty"` // Content title.
1212
Series string `json:"series,omitempty"` // Content series.
1313
Season string `json:"season,omitempty"` // Content season.
14+
Artist string `json:"artist,omitempty"` // Artist credited with the content.
15+
Genre string `json:"genre,omitempty"` // Genre that best describes the content
16+
Album string `json:"album,omiyempty"` // Album to which the content belongs; typically for audio.
17+
ISRC string `json:"isrc,omitempty"` // International Standard Recording Code conforming to ISO - 3901.
1418
Producer *Producer `json:"producer,omitempty"` // The producer.
1519
URL string `json:"url,omitempty"` // URL of the content, for buy-side contextualization or review.
1620
Cat []string `json:"cat,omitempty"` // Array of IAB content categories that describe the content.
21+
ProdQuality int `json:"prodq,omitempty"` // Production quality per IAB's classification.
1722
VideoQuality int `json:"videoquality,omitempty"` // Video quality per IAB's classification.
1823
Context int `json:"context,omitempty"` // Type of content (game, video, text, etc.).
1924
ContentRating string `json:"contentrating,omitempty"` // Content rating (e.g., MPAA).
@@ -25,5 +30,6 @@ type Content struct {
2530
Len int `json:"len,omitempty"` // Length of content in seconds; appropriate for video or audio.
2631
Language string `json:"language,omitempty"` // Content language using ISO-639-1-alpha-2.
2732
Embeddable int `json:"embeddable,omitempty"` // Indicator of whether or not the content is embeddable (e.g., an embeddable video player), where 0 = no, 1 = yes.
33+
Data []Data `json:"data,omitempty"` // Additional content data.
2834
Ext Extension `json:"ext,omitempty"`
2935
}

device.go

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,34 @@ package openrtb
44
// platform, location, and carrier. This device can refer to a mobile handset, a desktop computer,
55
// set top box or other digital device.
66
type Device struct {
7-
DNT int `json:"dnt,omitempty"` // "1": Do not track
8-
LMT int `json:"lmt,omitempty"` // "1": Limit Ad Tracking
9-
UA string `json:"ua,omitempty"` // User agent
10-
IP string `json:"ip,omitempty"` // IPv4
11-
Geo *Geo `json:"geo,omitempty"`
12-
IDSHA1 string `json:"didsha1,omitempty"` // SHA1 hashed device ID
13-
IDMD5 string `json:"didmd5,omitempty"` // MD5 hashed device ID
14-
PIDSHA1 string `json:"dpidsha1,omitempty"` // SHA1 hashed platform device ID
15-
PIDMD5 string `json:"dpidmd5,omitempty"` // MD5 hashed platform device ID
16-
MacSHA1 string `json:"macsha1,omitempty"` // SHA1 hashed device ID; IMEI when available, else MEID or ESN
17-
MacMD5 string `json:"macmd5,omitempty"` // MD5 hashed device ID; IMEI when available, else MEID or ESN
18-
IPv6 string `json:"ipv6,omitempty"` // IPv6
19-
Carrier string `json:"carrier,omitempty"` // Carrier or ISP derived from the IP address
20-
Language string `json:"language,omitempty"` // Browser language
21-
Make string `json:"make,omitempty"` // Device make
22-
Model string `json:"model,omitempty"` // Device model
23-
OS string `json:"os,omitempty"` // Device OS
24-
OSVer string `json:"osv,omitempty"` // Device OS version
25-
JS int `json:"js,omitempty"` // Javascript status ("0": Disabled, "1": Enabled)
26-
ConnType int `json:"connectiontype,omitempty"`
27-
DeviceType int `json:"devicetype,omitempty"`
28-
FlashVer string `json:"flashver,omitempty"` // Flash version
29-
IFA string `json:"ifa,omitempty"` // Native identifier for advertisers
7+
UA string `json:"ua,omitempty"` // User agent
8+
Geo *Geo `json:"geo,omitempty"` // Location of the device assumed to be the user’s current location
9+
DNT int `json:"dnt,omitempty"` // "1": Do not track
10+
LMT int `json:"lmt,omitempty"` // "1": Limit Ad Tracking
11+
IP string `json:"ip,omitempty"` // IPv4
12+
IPv6 string `json:"ipv6,omitempty"` // IPv6
13+
DeviceType int `json:"devicetype,omitempty"` // The general type of device.
14+
Make string `json:"make,omitempty"` // Device make
15+
Model string `json:"model,omitempty"` // Device model
16+
OS string `json:"os,omitempty"` // Device OS
17+
OSVer string `json:"osv,omitempty"` // Device OS version
18+
HwVer string `json:"hwv,omitempty"` // Hardware version of the device (e.g., "5S" for iPhone 5S).
19+
H int `json:"h,omitempty"` // Physical height of the screen in pixels.
20+
W int `json:"w,omitempty"` // Physical width of the screen in pixels.
21+
PPI int `json:"ppi,omitempty"` // Screen size as pixels per linear inch.
22+
PxRatio float64 `json:"pxratio,omitempty"` // The ratio of physical pixels to device independent pixels.
23+
JS int `json:"js,omitempty"` // Javascript status ("0": Disabled, "1": Enabled)
24+
GeoFetch int `json:"geofetch,omitempty"` // Indicates if the geolocation API will be available to JavaScript code running in the banner,
25+
FlashVer string `json:"flashver,omitempty"` // Flash version
26+
Language string `json:"language,omitempty"` // Browser language
27+
Carrier string `json:"carrier,omitempty"` // Carrier or ISP derived from the IP address
28+
ConnType int `json:"connectiontype,omitempty"` // Network connection type.
29+
IFA string `json:"ifa,omitempty"` // Native identifier for advertisers
30+
IDSHA1 string `json:"didsha1,omitempty"` // SHA1 hashed device ID
31+
IDMD5 string `json:"didmd5,omitempty"` // MD5 hashed device ID
32+
PIDSHA1 string `json:"dpidsha1,omitempty"` // SHA1 hashed platform device ID
33+
PIDMD5 string `json:"dpidmd5,omitempty"` // MD5 hashed platform device ID
34+
MacSHA1 string `json:"macsha1,omitempty"` // SHA1 hashed device ID; IMEI when available, else MEID or ESN
35+
MacMD5 string `json:"macmd5,omitempty"` // MD5 hashed device ID; IMEI when available, else MEID or ESN
3036
Ext Extension `json:"ext,omitempty"`
31-
H int `json:"h,omitempty"` // Physical height of the screen in pixels.
32-
W int `json:"w,omitempty"` // Physical width of the screen in pixels.
33-
PPI int `json:"ppi,omitempty"` // Screen size as pixels per linear inch.
34-
PxRatio float64 `json:"pxratio,omitempty"` // The ratio of physical pixels to device independent pixels.
35-
HwVer string `json:"hwv,omitempty"` // Hardware version of the device (e.g., "5S" for iPhone 5S).
3637
}

impression.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,18 @@ type Impression struct {
2020
ID string `json:"id"` // A unique identifier for this impression
2121
Banner *Banner `json:"banner,omitempty"`
2222
Video *Video `json:"video,omitempty"`
23+
Audio *Audio `json:"audio,omitempty"`
2324
Native *Native `json:"native,omitempty"`
25+
Pmp *Pmp `json:"pmp,omitempty"` // A reference to the PMP object containing any Deals eligible for the impression object.
2426
DisplayManager string `json:"displaymanager,omitempty"` // Name of ad mediation partner, SDK technology, etc
2527
DisplayManagerVer string `json:"displaymanagerver,omitempty"` // Version of the above
2628
Instl int `json:"instl,omitempty"` // Interstitial, Default: 0 ("1": Interstitial, "0": Something else)
2729
TagID string `json:"tagid,omitempty"` // IDentifier for specific ad placement or ad tag
2830
BidFloor float64 `json:"bidfloor,omitempty"` // Bid floor for this impression in CPM
2931
BidFloorCurrency string `json:"bidfloorcur,omitempty"` // Currency of bid floor
3032
Secure int `json:"secure,omitempty"` // Flag to indicate whether the impression requires secure HTTPS URL creative assets and markup.
33+
Exp int `json:"exp,omitempty"` // Advisory as to the number of seconds that may elapse between the auction and the actual impression.
3134
IFrameBuster []string `json:"iframebuster,omitempty"` // Array of names for supportediframe busters.
32-
Pmp *Pmp `json:"pmp,omitempty"` // A reference to the PMP object containing any Deals eligible for the impression object.
3335
Ext Extension `json:"ext,omitempty"`
3436
}
3537

0 commit comments

Comments
 (0)