From 9c966227514c9c04b47494cd575d751e9142c9bc Mon Sep 17 00:00:00 2001 From: Dimitrij Denissenko Date: Sun, 16 Apr 2017 08:44:19 +0100 Subject: [PATCH] Better fix for bad exchanges --- bid.go | 54 ++++++++++++++++++------------------- bidrequest_test.go | 4 +-- impression.go | 37 ++++++++++++------------- native/response/response.go | 12 ++++----- numbers.go | 53 ++++++++++++++++++++++++++++++++++++ numbers_test.go | 54 +++++++++++++++++++++++++++++++++++++ 6 files changed, 158 insertions(+), 56 deletions(-) create mode 100644 numbers.go create mode 100644 numbers_test.go diff --git a/bid.go b/bid.go index fac994e..802616b 100644 --- a/bid.go +++ b/bid.go @@ -16,33 +16,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 string `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 Extension `json:"ext,omitempty"` } // Validate required attributes diff --git a/bidrequest_test.go b/bidrequest_test.go index 4b6c97c..68dc085 100644 --- a/bidrequest_test.go +++ b/bidrequest_test.go @@ -1,8 +1,6 @@ package openrtb import ( - "encoding/json" - . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) @@ -30,7 +28,7 @@ var _ = Describe("BidRequest", func() { Imp: []Impression{ { ID: "1", - Secure: json.Number("1"), + Secure: 1, Banner: &Banner{W: 300, H: 250, Pos: AdPosAboveFold, BAttr: []int{CreativeAttributeUserInitiated}}, }, }, diff --git a/impression.go b/impression.go index a3e8b55..3fa096a 100644 --- a/impression.go +++ b/impression.go @@ -1,9 +1,6 @@ package openrtb -import ( - "encoding/json" - "errors" -) +import "errors" // Validation errors var ( @@ -19,22 +16,22 @@ var ( // The presence of Banner, Video, and/or Native objects // subordinate to the Imp object indicates the type of impression being offered. type Impression struct { - ID string `json:"id"` // A unique identifier for this impression - Banner *Banner `json:"banner,omitempty"` - Video *Video `json:"video,omitempty"` - Audio *Audio `json:"audio,omitempty"` - Native *Native `json:"native,omitempty"` - Pmp *Pmp `json:"pmp,omitempty"` // A reference to the PMP object containing any Deals eligible for the impression object. - DisplayManager string `json:"displaymanager,omitempty"` // Name of ad mediation partner, SDK technology, etc - DisplayManagerVer string `json:"displaymanagerver,omitempty"` // Version of the above - Instl int `json:"instl,omitempty"` // Interstitial, Default: 0 ("1": Interstitial, "0": Something else) - TagID string `json:"tagid,omitempty"` // IDentifier for specific ad placement or ad tag - BidFloor float64 `json:"bidfloor,omitempty"` // Bid floor for this impression in CPM - BidFloorCurrency string `json:"bidfloorcur,omitempty"` // Currency of bid floor - Secure json.Number `json:"secure,omitempty"` // Flag to indicate whether the impression requires secure HTTPS URL creative assets and markup. - Exp int `json:"exp,omitempty"` // Advisory as to the number of seconds that may elapse between the auction and the actual impression. - IFrameBuster []string `json:"iframebuster,omitempty"` // Array of names for supportediframe busters. - Ext Extension `json:"ext,omitempty"` + ID string `json:"id"` // A unique identifier for this impression + Banner *Banner `json:"banner,omitempty"` + Video *Video `json:"video,omitempty"` + Audio *Audio `json:"audio,omitempty"` + Native *Native `json:"native,omitempty"` + Pmp *Pmp `json:"pmp,omitempty"` // A reference to the PMP object containing any Deals eligible for the impression object. + DisplayManager string `json:"displaymanager,omitempty"` // Name of ad mediation partner, SDK technology, etc + DisplayManagerVer string `json:"displaymanagerver,omitempty"` // Version of the above + Instl int `json:"instl,omitempty"` // Interstitial, Default: 0 ("1": Interstitial, "0": Something else) + TagID string `json:"tagid,omitempty"` // IDentifier for specific ad placement or ad tag + BidFloor float64 `json:"bidfloor,omitempty"` // Bid floor for this impression in CPM + BidFloorCurrency string `json:"bidfloorcur,omitempty"` // Currency of bid floor + Secure NumberOrString `json:"secure,omitempty"` // Flag to indicate whether the impression requires secure HTTPS URL creative assets and markup. + Exp int `json:"exp,omitempty"` // Advisory as to the number of seconds that may elapse between the auction and the actual impression. + IFrameBuster []string `json:"iframebuster,omitempty"` // Array of names for supportediframe busters. + Ext Extension `json:"ext,omitempty"` } func (imp *Impression) assetCount() int { diff --git a/native/response/response.go b/native/response/response.go index 091c0d3..120acb0 100644 --- a/native/response/response.go +++ b/native/response/response.go @@ -4,10 +4,10 @@ import "github.com/bsm/openrtb" // The native object is the top level JSON object which identifies a native response type Response struct { - Ver string `json:"ver,omitempty"` // Version of the Native Markup - Assets []Asset `json:"assets"` // An array of Asset Objects - Link Link `json:"link"` // Destination Link. This is default link object for the ad - ImpTrackers []string `json:"imptrackers,omitempty"` // Array of impression tracking URLs, expected to return a 1x1 image or 204 response - JSTracker string `json:"jstracker,omitempty"` // Optional JavaScript impression tracker. This is a valid HTML, Javascript is already wrapped in