Skip to content

Commit

Permalink
Merge pull request bsm#63 from mxmCherry/feature/use-json-rawmessage
Browse files Browse the repository at this point in the history
switch back custom Extension to json.RawMessage
  • Loading branch information
dim authored Jun 24, 2019
2 parents 643b4f1 + d4bd648 commit 88dbbc5
Show file tree
Hide file tree
Showing 32 changed files with 375 additions and 386 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

OpenRTB implementation for Go

## Requirements

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

## Installation

To install, use `go get`:
Expand Down
38 changes: 19 additions & 19 deletions audio.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,25 @@ var (

// The "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 Extension `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 []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"`
}

type jsonAudio Audio
Expand Down
34 changes: 18 additions & 16 deletions banner.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
package openrtb

import "encoding/json"

// The "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
Ext Extension `json:"ext,omitempty"`
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
Ext json.RawMessage `json:"ext,omitempty"`
}
59 changes: 31 additions & 28 deletions bid.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package openrtb

import "errors"
import (
"encoding/json"
"errors"
)

// Validation errors
var (
Expand All @@ -16,33 +19,33 @@ var (
// Cid can be used to block ads that were previously identified as inappropriate.
// Substitution macros may allow a bidder to use a static notice URL for all of its bids.
type Bid struct {
ID string `json:"id"`
ImpID string `json:"impid"` // Required string ID of the impression object to which this bid applies.
Price float64 `json:"price"` // Bid price in CPM. Suggests using integer math for accounting to avoid rounding errors.
AdID string `json:"adid,omitempty"` // References the ad to be served if the bid wins.
NURL string `json:"nurl,omitempty"` // Win notice URL.
BURL string `json:"burl,omitempty"` // Billing notice URL.
LURL string `json:"lurl,omitempty"` // Loss notice URL.
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.
AdvDomain []string `json:"adomain,omitempty"` // Advertiser’s primary or top-level domain for advertiser checking; or multiple if imp rotating.
Bundle string `json:"bundle,omitempty"` // A platform-specific application identifier intended to be unique to the app and independent of the exchange.
IURL string `json:"iurl,omitempty"` // Sample image URL.
CampaignID StringOrNumber `json:"cid,omitempty"` // Campaign ID that appears with the Ad markup.
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.
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
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.
DealID string `json:"dealid,omitempty"` // DealID extension of private marketplace deals
H int `json:"h,omitempty"` // Height of the ad in pixels.
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.
Ext Extension `json:"ext,omitempty"`
ID string `json:"id"`
ImpID string `json:"impid"` // Required string ID of the impression object to which this bid applies.
Price float64 `json:"price"` // Bid price in CPM. Suggests using integer math for accounting to avoid rounding errors.
AdID string `json:"adid,omitempty"` // References the ad to be served if the bid wins.
NURL string `json:"nurl,omitempty"` // Win notice URL.
BURL string `json:"burl,omitempty"` // Billing notice URL.
LURL string `json:"lurl,omitempty"` // Loss notice URL.
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.
AdvDomain []string `json:"adomain,omitempty"` // Advertiser’s primary or top-level domain for advertiser checking; or multiple if imp rotating.
Bundle string `json:"bundle,omitempty"` // A platform-specific application identifier intended to be unique to the app and independent of the exchange.
IURL string `json:"iurl,omitempty"` // Sample image URL.
CampaignID StringOrNumber `json:"cid,omitempty"` // Campaign ID that appears with the Ad markup.
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.
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
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.
DealID string `json:"dealid,omitempty"` // DealID extension of private marketplace deals
H int `json:"h,omitempty"` // Height of the ad in pixels.
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.
Ext json.RawMessage `json:"ext,omitempty"`
}

// Validate required attributes
Expand Down
45 changes: 24 additions & 21 deletions bidrequest.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package openrtb

import "errors"
import (
"encoding/json"
"errors"
)

// Validation errors
var (
Expand All @@ -13,26 +16,26 @@ var (
// attribute is required as is at least one "imp" (i.e., impression) object. Other attributes are
// optional since an exchange may establish default values.
type BidRequest struct {
ID string `json:"id"` // Unique ID of the bid request
Imp []Impression `json:"imp,omitempty"`
Site *Site `json:"site,omitempty"`
App *App `json:"app,omitempty"`
Device *Device `json:"device,omitempty"`
User *User `json:"user,omitempty"`
Test int `json:"test,omitempty"` // Indicator of test mode in which auctions are not billable, where 0 = live mode, 1 = test mode
AuctionType int `json:"at"` // Auction type, where 1 = First Price, 2 = Second Price Plus. Exchange-specific auction types can be defined using values greater than 500.
TMax int `json:"tmax,omitempty"` // Maximum amount of time in milliseconds to submit a bid
WSeat []string `json:"wseat,omitempty"` // Array of buyer seats allowed to bid on this auction
BSeat []string `json:"bseat,omitempty"` // Array of buyer seats blocked to bid on this auction
WLang []string `json:"wlang,omitempty"` // Array of languages for creatives using ISO-639-1-alpha-2
AllImps int `json:"allimps,omitempty"` // Flag to indicate whether exchange can verify that all impressions offered represent all of the impressions available in context, Default: 0
Cur []string `json:"cur,omitempty"` // Array of allowed currencies
Bcat []string `json:"bcat,omitempty"` // Blocked Advertiser Categories.
BAdv []string `json:"badv,omitempty"` // Array of strings of blocked toplevel domains of advertisers
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.
Source *Source `json:"source,omitempty"` // A Source object that provides data about the inventory source and which entity makes the final decision
Regs *Regulations `json:"regs,omitempty"`
Ext Extension `json:"ext,omitempty"`
ID string `json:"id"` // Unique ID of the bid request
Imp []Impression `json:"imp,omitempty"`
Site *Site `json:"site,omitempty"`
App *App `json:"app,omitempty"`
Device *Device `json:"device,omitempty"`
User *User `json:"user,omitempty"`
Test int `json:"test,omitempty"` // Indicator of test mode in which auctions are not billable, where 0 = live mode, 1 = test mode
AuctionType int `json:"at"` // Auction type, where 1 = First Price, 2 = Second Price Plus. Exchange-specific auction types can be defined using values greater than 500.
TMax int `json:"tmax,omitempty"` // Maximum amount of time in milliseconds to submit a bid
WSeat []string `json:"wseat,omitempty"` // Array of buyer seats allowed to bid on this auction
BSeat []string `json:"bseat,omitempty"` // Array of buyer seats blocked to bid on this auction
WLang []string `json:"wlang,omitempty"` // Array of languages for creatives using ISO-639-1-alpha-2
AllImps int `json:"allimps,omitempty"` // Flag to indicate whether exchange can verify that all impressions offered represent all of the impressions available in context, Default: 0
Cur []string `json:"cur,omitempty"` // Array of allowed currencies
Bcat []string `json:"bcat,omitempty"` // Blocked Advertiser Categories.
BAdv []string `json:"badv,omitempty"` // Array of strings of blocked toplevel domains of advertisers
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.
Source *Source `json:"source,omitempty"` // A Source object that provides data about the inventory source and which entity makes the final decision
Regs *Regulations `json:"regs,omitempty"`
Ext json.RawMessage `json:"ext,omitempty"`

Pmp *Pmp `json:"pmp,omitempty"` // DEPRECATED: kept for backwards compatibility
}
Expand Down
Loading

0 comments on commit 88dbbc5

Please sign in to comment.