Skip to content

Commit 6b4f0a7

Browse files
committed
Added JSON export for requests
1 parent 0e57cec commit 6b4f0a7

File tree

9 files changed

+163
-146
lines changed

9 files changed

+163
-146
lines changed

app.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@ package openrtb
44
// (as opposed to a mobile website). A bid request must not contain both an "app" object and a
55
// "site" object.
66
type App struct {
7-
Id *string // App ID on the exchange
8-
Name *string // App name
9-
Domain *string
10-
Cat []string // Array of IAB content categories
11-
Sectioncat []string // Array of IAB content categories for subsection
12-
Pagecat []string // Array of IAB content categories for page
13-
Ver *string // App version
14-
Bundle *string // App bundle or package name
15-
Privacypolicy *int // Default: 1 ("1": site has a privacy policy)
16-
Paid *int // "1": Paid, "2": Free
17-
Publisher *Publisher
7+
Id *string `json:"id,omitempty"` // App ID on the exchange
8+
Name *string `json:"name,omitempty"` // App name
9+
Domain *string `json:"domain,omitempty"`
10+
Cat []string `json:"cat,omitempty"` // Array of IAB content categories
11+
Sectioncat []string `json:"sectioncat,omitempty"` // Array of IAB content categories for subsection
12+
Pagecat []string `json:"pagecat,omitempty"` // Array of IAB content categories for page
13+
Ver *string `json:"ver,omitempty"` // App version
14+
Bundle *string `json:"bundle,omitempty"` // App bundle or package name
15+
Privacypolicy *int `json:"privacypolicy,omitempty"` // Default: 1 ("1": site has a privacy policy)
16+
Paid *int `json:"paid,omitempty"` // "1": Paid, "2": Free
17+
Publisher *Publisher `json:"publisher,omitempty"`
1818
// Content Content
19-
Keywords []string
20-
Storeurl *string // App store URL for an installed app
21-
Ext Extensions
19+
Keywords []string `json:"keywords,omitempty"`
20+
Storeurl *string `json:"storeurl,omitempty"` // App store URL for an installed app
21+
Ext Extensions `json:"ext,omitempty"`
2222
}
2323

2424
// Returns the privacy policy status, with default fallback

banner.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ package openrtb
77
// VAST response to dictate placement of the companion creatives when multiple companion ad
88
// opportunities of the same size are available on a page.
99
type Banner struct {
10-
W *int // Width
11-
H *int // Height
12-
Id *string // A unique identifier
13-
Pos *int // Ad Position
14-
Btype []int // Blocked creative types
15-
Battr []int // Blocked creative attributes
16-
Mimes []string // Whitelist of content MIME types supported
17-
Topframe *int // Default: 0 ("1": Delivered in top frame, "0": Elsewhere)
18-
Expdir []int // Specify properties for an expandable ad
19-
Api []int // List of supported API frameworks
20-
Ext Extensions
10+
W *int `json:"w,omitempty"` // Width
11+
H *int `json:"h,omitempty"` // Height
12+
Id *string `json:"id,omitempty"` // A unique identifier
13+
Pos *int `json:"pos,omitempty"` // Ad Position
14+
Btype []int `json:"btype,omitempty"` // Blocked creative types
15+
Battr []int `json:"battr,omitempty"` // Blocked creative attributes
16+
Mimes []string `json:"mimes,omitempty"` // Whitelist of content MIME types supported
17+
Topframe *int `json:"topframe,omitempty"` // Default: 0 ("1": Delivered in top frame, "0": Elsewhere)
18+
Expdir []int `json:"expdir,omitempty"` // Specify properties for an expandable ad
19+
Api []int `json:"api,omitempty"` // List of supported API frameworks
20+
Ext Extensions `json:"ext,omitempty"`
2121
}
2222

2323
// Returns topframe status, with default fallback

device.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,26 @@ 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 // "1": Do not track
8-
Ua *string // User agent
9-
Ip *string // IPv4
10-
Geo *Geo
11-
Didsha1 *string // SHA1 hashed device ID
12-
Didmd5 *string // MD5 hashed device ID
13-
Dpidsha1 *string // SHA1 hashed platform device ID
14-
Dpidmd5 *string // MD5 hashed platform device ID
15-
Ipv6 *string // IPv6
16-
Carrier *string // Carrier or ISP derived from the IP address
17-
Language *string // Browser language
18-
Make *string // Device make
19-
Model *string // Device model
20-
Os *string // Device OS
21-
Osv *string // Device OS version
22-
Js *int // Javascript status ("0": Disabled, "1": Enabled)
23-
Connectiontype *int
24-
Devicetype *int
25-
Flashver *string // Flash version
26-
Ext map[string]string
7+
Dnt *int `json:"dnt,omitempty"` // "1": Do not track
8+
Ua *string `json:"ua,omitempty"` // User agent
9+
Ip *string `json:"ip,omitempty"` // IPv4
10+
Geo *Geo `json:"geo,omitempty"`
11+
Didsha1 *string `json:"didsha1,omitempty"` // SHA1 hashed device ID
12+
Didmd5 *string `json:"didmd5,omitempty"` // MD5 hashed device ID
13+
Dpidsha1 *string `json:"dpidsha1,omitempty"` // SHA1 hashed platform device ID
14+
Dpidmd5 *string `json:"dpidmd5,omitempty"` // MD5 hashed platform device ID
15+
Ipv6 *string `json:"ipv6,omitempty"` // IPv6
16+
Carrier *string `json:"carrier,omitempty"` // Carrier or ISP derived from the IP address
17+
Language *string `json:"language,omitempty"` // Browser language
18+
Make *string `json:"make,omitempty"` // Device make
19+
Model *string `json:"model,omitempty"` // Device model
20+
Os *string `json:"os,omitempty"` // Device OS
21+
Osv *string `json:"osv,omitempty"` // Device OS version
22+
Js *int `json:"js,omitempty"` // Javascript status ("0": Disabled, "1": Enabled)
23+
Connectiontype *int `json:"connectiontype,omitempty"`
24+
Devicetype *int `json:"devicetype,omitempty"`
25+
Flashver *string `json:"flashver,omitempty"` // Flash version
26+
Ext map[string]string `json:"ext,omitempty"`
2727
}
2828

2929
// Returns the DNT status, with default fallback

impression.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ import (
1010
// bids can reference them individually. An exchange can also conduct private auctions by
1111
// restricting involvement to specific subsets of seats within bidders.
1212
type Impression struct {
13-
Id *string // A unique identifier for this impression
14-
Banner *Banner
15-
Video *Video
16-
Displaymanager *string // Name of ad mediation partner, SDK technology, etc
17-
Displaymanagerver *string // Version of the above
18-
Instl *int // Interstitial, Default: 0 ("1": Interstitial, "0": Something else)
19-
Tagid *string // Identifier for specific ad placement or ad tag
20-
Bidfloor *float32 // Bid floor for this impression in CPM
21-
Bidfloorcur *string // Currency of bid floor
22-
Iframebuster []string // Array of names for supportediframe busters.
23-
Ext Extensions
13+
Id *string `json:"id` // A unique identifier for this impression
14+
Banner *Banner `json:"banner,omitempty"`
15+
Video *Video `json:"video,omitempty"`
16+
Displaymanager *string `json:"displaymanager,omitempty"` // Name of ad mediation partner, SDK technology, etc
17+
Displaymanagerver *string `json:"displaymanagerver,omitempty"` // Version of the above
18+
Instl *int `json:"instl,omitempty"` // Interstitial, Default: 0 ("1": Interstitial, "0": Something else)
19+
Tagid *string `json:"tagid,omitempty"` // Identifier for specific ad placement or ad tag
20+
Bidfloor *float32 `json:"bidfloor,omitempty"` // Bid floor for this impression in CPM
21+
Bidfloorcur *string `json:"bidfloorcur,omitempty"` // Currency of bid floor
22+
Iframebuster []string `json:"iframebuster,omitempty"` // Array of names for supportediframe busters.
23+
Ext Extensions `json:"ext,omitempty"`
2424
}
2525

2626
// Validation errors

openrtb.go

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ const (
6565

6666
// Abstract third-party
6767
type ThirdParty struct {
68-
Id *string
69-
Name *string
70-
Cat []string // Array of IAB content categories
71-
Domain *string
72-
Ext Extensions
68+
Id *string `json:"id,omitempty"`
69+
Name *string `json:"name,omitempty"`
70+
Cat []string `json:"cat,omitempty"` // Array of IAB content categories
71+
Domain *string `json:"domain,omitempty"`
72+
Ext Extensions `json:"ext,omitempty"`
7373
}
7474

7575
// The publisher object itself and all of its parameters are optional, so default values are not
@@ -87,70 +87,70 @@ type Producer ThirdParty
8787
// (such as IP geo lookup), or by user registration information (for example provided to a publisher
8888
// through a user registration).
8989
type Geo struct {
90-
Lat *float32 // Latitude from -90 to 90
91-
Lon *float32 // Longitude from -180 to 180
92-
Country *string // Country using ISO 3166-1 Alpha 3
93-
Region *string // Region using ISO 3166-2
94-
Regionfips104 *string // Region of a country using fips 10-4
95-
Metro *string
96-
City *string
97-
Zip *string
98-
Type *int // Indicate the source of the geo data
99-
Ext Extensions
90+
Lat *float32 `json:"lat,omitempty"` // Latitude from -90 to 90
91+
Lon *float32 `json:"lon,omitempty"` // Longitude from -180 to 180
92+
Country *string `json:"country,omitempty"` // Country using ISO 3166-1 Alpha 3
93+
Region *string `json:"region,omitempty"` // Region using ISO 3166-2
94+
Regionfips104 *string `json:"regionfips104,omitempty"` // Region of a country using fips 10-4
95+
Metro *string `json:"metro,omitempty"`
96+
City *string `json:"city,omitempty"`
97+
Zip *string `json:"zip,omitempty"`
98+
Type *int `json:"type,omitempty"` // Indicate the source of the geo data
99+
Ext Extensions `json:"ext,omitempty"`
100100
}
101101

102102
// The "user" object contains information known or derived about the human user of the device.
103103
// Note that the user ID is an exchange artifact (refer to the "device" object for hardware or
104104
// platform derived IDs) and may be subject to rotation policies. However, this user ID must be
105105
// stable long enough to serve reasonably as the basis for frequency capping.
106106
type User struct {
107-
Id *string // Unique consumer ID of this user on the exchange
108-
Buyeruid *string // Buyer's user ID
109-
Yob *int // Year-of-birth
110-
Gender *string // Gender ("M": male, "F" female, "O" Other)
111-
Keywords *string
112-
Customdata *string
113-
Geo *Geo
114-
Data []Data
115-
Ext Extensions
107+
Id *string `json:"id,omitempty"` // Unique consumer ID of this user on the exchange
108+
Buyeruid *string `json:"buyeruid,omitempty"` // Buyer's user ID
109+
Yob *int `json:"yob,omitempty"` // Year-of-birth
110+
Gender *string `json:"gender,omitempty"` // Gender ("M": male, "F" female, "O" Other)
111+
Keywords *string `json:"keywords,omitempty"`
112+
Customdata *string `json:"customdata,omitempty"`
113+
Geo *Geo `json:"geo,omitempty"`
114+
Data []Data `json:"data,omitempty"`
115+
Ext Extensions `json:"ext,omitempty"`
116116
}
117117

118118
// The data and segment objects together allow data about the user to be passed to bidders in the
119119
// bid request. This data may be from multiple sources (e.g., the exchange itself, third party
120120
// providers) as specified by the data object ID field. A bid request can mix data objects from
121121
// multiple providers.
122122
type Data struct {
123-
Id *string
124-
Name *string
125-
Segment []Segment
126-
Ext Extensions
123+
Id *string `json:"id,omitempty"`
124+
Name *string `json:"name,omitempty"`
125+
Segment []Segment `json:"segment,omitempty"`
126+
Ext Extensions `json:"ext,omitempty"`
127127
}
128128

129129
// The data and segment objects together allow data about the user to be passed to bidders in the
130130
// bid request. Segment objects convey specific units of information from the provider identified
131131
// in the parent data object.
132132
type Segment struct {
133-
Id *string
134-
Name *string
135-
Value *string
136-
Ext Extensions
133+
Id *string `json:"id,omitempty"`
134+
Name *string `json:"name,omitempty"`
135+
Value *string `json:"value,omitempty"`
136+
Ext Extensions `json:"ext,omitempty"`
137137
}
138138

139139
// Private Marketplace Object
140140
type Pmp struct {
141-
Private *int
142-
Deals []Deal
143-
Ext Extensions
141+
Private *int `json:"private,omitempty"`
142+
Deals []Deal `json:"deals,omitempty"`
143+
Ext Extensions `json:"ext,omitempty"`
144144
}
145145

146146
// Private Marketplace Deal
147147
type Deal struct {
148-
Id *string // Unique deal ID
149-
At *int // Auction type, Default: 2 ("1": first price auction, "2": then second price auction)
150-
Seats []string // List of seat IDs attached to this deal
151-
Type *int // Deal indicator ("1": Eplicit Deal, "2": Trading Agreement Deal)
152-
Bidfloor *float32
153-
Ext Extensions
148+
Id *string `json:"id,omitempty"` // Unique deal ID
149+
At *int `json:"at,omitempty"` // Auction type, Default: 2 ("1": first price auction, "2": then second price auction)
150+
Seats []string `json:"seats,omitempty"` // List of seat IDs attached to this deal
151+
Type *int `json:"type,omitempty"` // Deal indicator ("1": Eplicit Deal, "2": Trading Agreement Deal)
152+
Bidfloor *float32 `json:"bidfloor,omitempty"`
153+
Ext Extensions `json:"ext,omitempty"`
154154
}
155155

156156
// General Extensions

request.go

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@ import (
1010
// attribute is required as is at least one "imp" (i.e., impression) object. Other attributes are
1111
// optional since an exchange may establish default values.
1212
type Request struct {
13-
Id *string // Unique ID of the bid request
14-
Imp []Impression
15-
Site *Site
16-
App *App
17-
Device *Device
18-
User *User
19-
At *int // Auction type, Default: 2 ("1": first price auction, "2": then second price auction)
20-
Tmax *int // Maximum amount of time in milliseconds to submit a bid
21-
Wseat []string // Array of buyer seats allowed to bid on this auction
22-
Allimps *int // Flag to indicate whether exchange can verify that all impressions offered represent all of the impressions available in context, Default: 0
23-
Cur []string // Array of allowed currencies
24-
Bcat []string // Blocked Advertiser Categories.
25-
Badv []string // Array of strings of blocked toplevel domains of advertisers
26-
Pmp *Pmp
27-
Ext Extensions
13+
Id *string `json:"id"` // Unique ID of the bid request
14+
Imp []Impression `json:"imp,omitempty"`
15+
Site *Site `json:"site,omitempty"`
16+
App *App `json:"app,omitempty"`
17+
Device *Device `json:"device,omitempty"`
18+
User *User `json:"user,omitempty"`
19+
At *int `json:"at"` // Auction type, Default: 2 ("1": first price auction, "2": then second price auction)
20+
Tmax *int `json:"tmax,omitempty"` // Maximum amount of time in milliseconds to submit a bid
21+
Wseat []string `json:"wseat,omitempty"` // Array of buyer seats allowed to bid on this auction
22+
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
23+
Cur []string `json:"cur,omitempty"` // Array of allowed currencies
24+
Bcat []string `json:"bcat,omitempty"` // Blocked Advertiser Categories.
25+
Badv []string `json:"badv,omitempty"` // Array of strings of blocked toplevel domains of advertisers
26+
Pmp *Pmp `json:"pmp,omitempty"`
27+
Ext Extensions `json:"ext,omitempty"`
2828
}
2929

3030
// Parses an OpenRTB Request struct from an io.Reader
@@ -53,6 +53,11 @@ var (
5353
invalidReqSaA = errors.New("openrtb parse: request has site and app")
5454
)
5555

56+
// Generate JSON
57+
func (req *Request) JSON() ([]byte, error) {
58+
return json.Marshal(req)
59+
}
60+
5661
// Validates the request
5762
func (req *Request) Valid() (bool, error) {
5863
if req.Id == nil {

request_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,18 @@ func TestRequest_WithDefaults(t *testing.T) {
6262
assert.Equal(t, "pending", "TODO")
6363
}
6464

65+
func TestRequest_JSON(t *testing.T) {
66+
req, err := ParseRequest(bytes.NewBuffer(expandableCreative))
67+
assert.Nil(t, err)
68+
69+
if req != nil {
70+
assert.Equal(t, "pending", "TODO")
71+
// json, err := req.JSON()
72+
// assert.Nil(t, err)
73+
// assert.Equal(t, string(json), string(expandableCreative))
74+
}
75+
}
76+
6577
var simpleBanner []byte = []byte(`
6678
{
6779
"id":"1234534625254",

site.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@ package openrtb
33
// A site object should be included if the ad supported content is part of a website (as opposed to
44
// an application). A bid request must not contain both a site object and an app object.
55
type Site struct {
6-
Id *string // Site ID on the exchange
7-
Name *string // Site name
8-
Domain *string
9-
Cat []string // Array of IAB content categories
10-
Sectioncat []string // Array of IAB content categories for subsection
11-
Pagecat []string // Array of IAB content categories for page
12-
Page *string // URL of the page
13-
Privacypolicy *int // Default: 1 ("1": site has a privacy policy)
14-
Ref *string // Referrer URL
15-
Search *string // Search string that caused naviation
16-
Publisher *Publisher
6+
Id *string `json:"id,omitempty"` // Site ID on the exchange
7+
Name *string `json:"name,omitempty"` // Site name
8+
Domain *string `json:"domain,omitempty"`
9+
Cat []string `json:"cat,omitempty"` // Array of IAB content categories
10+
Sectioncat []string `json:"sectioncat,omitempty"` // Array of IAB content categories for subsection
11+
Pagecat []string `json:"pagecat,omitempty"` // Array of IAB content categories for page
12+
Page *string `json:"page,omitempty"` // URL of the page
13+
Privacypolicy *int `json:"privacypolicy,omitempty"` // Default: 1 ("1": site has a privacy policy)
14+
Ref *string `json:"ref,omitempty"` // Referrer URL
15+
Search *string `json:"search,omitempty"` // Search string that caused naviation
16+
Publisher *Publisher `json:"publisher,omitempty"`
1717
// Content Content
18-
Keywords []string
19-
Ext Extensions
18+
Keywords []string `json:"keywords,omitempty"`
19+
Ext Extensions `json:"ext,omitempty"`
2020
}
2121

2222
// Returns the privacy policy status, with default fallback

0 commit comments

Comments
 (0)