Skip to content

Commit f0bcd59

Browse files
author
Ev Dolzhenko
committed
Add all Native objects
1 parent cdbda12 commit f0bcd59

File tree

18 files changed

+452
-0
lines changed

18 files changed

+452
-0
lines changed

native/request/asset.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package request
2+
3+
import "encoding/json"
4+
5+
// The main container object for each asset requested or supported by Exchange
6+
// on behalf of the rendering client. Only one of the {title,img,video,data}
7+
// objects should be present in each object. The id is to be unique within the
8+
// AssetObject array so that the response can be aligned.
9+
type Asset struct {
10+
ID int `json:"id"` // Unique asset ID, assigned by exchange
11+
Required int `json:"required,omitempty"` // Set to 1 if asset is required
12+
Title *Title `json:"title,omitempty"` // Title object for title assets
13+
Image *Image `json:"img,omitempty"` // Image object for image assets
14+
Video *Video `json:"video,omitempty"` // Video object for video assets
15+
Data *Data `json:"data,omitempty"` // Data object for brand name, description, ratings, prices etc.
16+
Ext json.RawMessage `json:"ext,omitempty"`
17+
}

native/request/data.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package request
2+
3+
import "encoding/json"
4+
5+
type Data_Type int
6+
7+
const (
8+
Data_Sponsored Data_Type = 1 // Sponsored By message where response should contain the brand name of the sponsor
9+
Data_Desc Data_Type = 2 // Descriptive text associated with the product or service being advertised
10+
Data_Rating Data_Type = 3 // Rating of the product being offered to the user
11+
Data_Likes Data_Type = 4 // Number of social ratings or “likes” of the product being offered to the user
12+
Data_Downloads Data_Type = 5 // Number downloads/installs of this product
13+
Data_Price Data_Type = 6 // Price for product / app / in-app purchase. Value should include currency symbol in localised format
14+
Data_SalePrice Data_Type = 7 // Sale price that can be used together with price to indicate a discounted price compared to a regular price. Value should include currency symbol in localised format
15+
Data_Phone Data_Type = 8 // Phone number
16+
Data_Address Data_Type = 9 // Address
17+
Data_DescAdditional Data_Type = 10 // Additional descriptive text associated with the product or service being advertised
18+
Data_DisplayURL Data_Type = 11 // Display URL for the text ad. To be used when sponsoring entity doesn’t own the content. IE sponsored by BRAND on SITE (where SITE is transmitted in this field)
19+
Data_CTADesc Data_Type = 12 // CTA description - descriptive text describing a ‘call to action’ button for the destination URL
20+
21+
)
22+
23+
type Data struct {
24+
Type Data_Type `json:"type"` // Type ID of the element supported by the publisher. The publisher can display this information in an appropriate format
25+
Length int `json:"len"` // Maximum length of the text in the element’s response
26+
Ext json.RawMessage `json:"ext,omitempty"`
27+
}

native/request/image.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package request
2+
3+
import "encoding/json"
4+
5+
type Image_Type int
6+
7+
const (
8+
Image_Icon Image_Type = 1 // Icon image
9+
Image_Logo Image_Type = 2 // Logo image for the brand/app
10+
Image_Main Image_Type = 3 // Large image preview for the ad
11+
)
12+
13+
type Image struct {
14+
Type Image_Type `json:"type,omitempty"` // Type ID of the image element supported by the publisher
15+
16+
Width int `json:"w,omitempty"` // Width of the image in pixels
17+
WidthMin int `json:"wmin,omitempty"` // The minimum requested width of the image in pixels
18+
Height int `json:"h,omitempty"` // Height of the image in pixels
19+
HeightMin int `json:"hmin,omitempty"` // The minimum requested height of the image in pixels
20+
// Either h/w or hmin/wmin should be transmitted. If only h/w is included, it
21+
// should be considered an exact requirement
22+
Mimes []string `json:"mimes,omitempty"` // Whitelist of content MIME types supported
23+
Ext json.RawMessage `json:"ext,omitempty"`
24+
}

native/request/request.go

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package request
2+
3+
import "encoding/json"
4+
5+
type Request_Layout int
6+
7+
const (
8+
Request_ContentWall Request_Layout = 1
9+
Request_AppWall Request_Layout = 2
10+
Request_NewsFeed Request_Layout = 3
11+
Request_ChatList Request_Layout = 4
12+
Request_Carousel Request_Layout = 5
13+
Request_ContentStream Request_Layout = 6
14+
Request_GridAdjoiningContent Request_Layout = 7
15+
)
16+
17+
type Request_AdUnit int
18+
19+
const (
20+
Request_PaidSearchUnits Request_AdUnit = 1
21+
Request_RecommendationWidgets Request_AdUnit = 2
22+
Request_PromotedListings Request_AdUnit = 3
23+
Request_InAdWithNativeElementUnits Request_AdUnit = 4
24+
Request_Custom Request_AdUnit = 5
25+
)
26+
27+
type Request_Context int
28+
29+
const (
30+
Request_Content Request_Context = 1 // newsfeed, article, image gallery, video gallery
31+
Request_Social Request_Context = 2 // social network feed, email, chat
32+
Request_Product Request_Context = 3 // product listings, details, recommendations, reviews
33+
)
34+
35+
type Request_ContextSubType int
36+
37+
const (
38+
Request_General Request_ContextSubType = 10
39+
Request_Article Request_ContextSubType = 11
40+
Request_Video Request_ContextSubType = 12
41+
Request_Audio Request_ContextSubType = 13
42+
Request_Image Request_ContextSubType = 14
43+
Request_UserGenerated Request_ContextSubType = 15
44+
Request_SubSocial Request_ContextSubType = 20
45+
Request_Email Request_ContextSubType = 21
46+
Request_Chat Request_ContextSubType = 22
47+
Request_Selling Request_ContextSubType = 30
48+
Request_AppStore Request_ContextSubType = 31
49+
Request_ProductReviews Request_ContextSubType = 32
50+
)
51+
52+
type Request_PlacementType int
53+
54+
const (
55+
Request_InFeed Request_PlacementType = 1 // In the feed of content - for example as an item inside the organic feed/grid/listing/carousel
56+
Request_Atomic Request_PlacementType = 2 // In the atomic unit of the content - IE in the article page or single image page
57+
Request_Outside Request_PlacementType = 3 // Outside the core content - for example in the ads section on the right rail, as a banner-style placement near the content, etc.
58+
Request_Recommendation Request_PlacementType = 4 // Recommendation widget, most commonly presented below the article content
59+
)
60+
61+
// This object represents a native type impression. Native ad units are intended to blend seamlessly into
62+
// the surrounding content (e.g., a sponsored Twitter or Facebook post). As such, the response must be
63+
// well-structured to afford the publisher fine-grained control over rendering.
64+
// The presence of a Native as a subordinate of the Imp object indicates that this impression is offered as
65+
// a native type impression. At the publisher’s discretion, that same impression may also be offered as
66+
// banner and/or video by also including as Imp subordinates the Banner and/or Video objects,
67+
// respectively. However, any given bid for the impression must conform to one of the offered types.
68+
type Request struct {
69+
Ver string `json:"ver,omitempty"` // Version of the Native Markup
70+
Layout Request_Layout `json:"layout,omitempty"` // DEPRECATED The Layout ID of the native ad
71+
AdUnit Request_AdUnit `json:"adunit,omitempty"` // DEPRECATED The Ad unit ID of the native ad
72+
Context Request_Context `json:"context,omitempty` // The context in which the ad appears
73+
ContextSubType Request_ContextSubType `json:"contextsubtype,omitempty"` // A more detailed context in which the ad appears
74+
PlacementType Request_PlacementType `json:"plcmttype,omitempty"` // The design/format/layout of the ad unit being offered
75+
PlacementCount int `json:"plcmtcnt,omitempty"` // The number of identical placements in this Layout
76+
Sequence int `json:"seq,omitempty"` // 0 for the first ad, 1 for the second ad, and so on
77+
Assets []Asset `json:"assets"` // An array of Asset Objects
78+
Ext json.RawMessage `json:"ext,omitempty"`
79+
}

native/request/request_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package request
2+
3+
import (
4+
"encoding/json"
5+
"io/ioutil"
6+
"testing"
7+
8+
. "github.com/onsi/ginkgo"
9+
. "github.com/onsi/gomega"
10+
)
11+
12+
var _ = Describe("Request", func() {
13+
It("should parse correctly", func() {
14+
Expect(fixture("testdata/request1.json")).To(Equal(Request{
15+
Ver: "1.1",
16+
Context: Request_Social,
17+
ContextSubType: Request_SubSocial,
18+
PlacementType: Request_PlacementType(11),
19+
PlacementCount: 1,
20+
Sequence: 2,
21+
Assets: []Asset{
22+
{ID: 123, Required: 1, Title: &Title{Length: 140}},
23+
{ID: 128, Image: &Image{Type: Image_Main, WidthMin: 836, HeightMin: 627, Width: 1000, Height: 800, Mimes: []string{"image/jpg"}}},
24+
{ID: 126, Required: 1, Data: &Data{Type: Data_Sponsored, Length: 25}},
25+
{ID: 127, Required: 1, Data: &Data{Type: Data_Desc, Length: 140}},
26+
{ID: 4, Video: &Video{MinDuration: 15, MaxDuration: 30, Protocols: []int{2, 3}, Mimes: []string{"video/mp4"}}},
27+
},
28+
}))
29+
})
30+
})
31+
32+
func TestSuite(t *testing.T) {
33+
RegisterFailHandler(Fail)
34+
RunSpecs(t, "openrtb/native/request")
35+
}
36+
37+
func fixture(path string) Request {
38+
var subject Request
39+
enc, err := ioutil.ReadFile(path)
40+
Expect(err).ToNot(HaveOccurred())
41+
Expect(json.Unmarshal(enc, &subject)).To(Succeed())
42+
return subject
43+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"ver": "1.1",
3+
"context": 2,
4+
"contextsubtype": 20,
5+
"plcmttype": 11,
6+
"plcmtcnt": 1,
7+
"seq": 2,
8+
"assets": [
9+
{
10+
"id": 123,
11+
"required": 1,
12+
"title": {
13+
"len": 140
14+
}
15+
},
16+
{
17+
"id": 128,
18+
"required": 0,
19+
"img": {
20+
"w": 1000,
21+
"h": 800,
22+
"mimes": ["image/jpg"],
23+
"wmin": 836,
24+
"hmin": 627,
25+
"type": 3
26+
}
27+
},
28+
{
29+
"id": 126,
30+
"required": 1,
31+
"data": {
32+
"type": 1,
33+
"len": 25
34+
}
35+
},
36+
{
37+
"id": 127,
38+
"required": 1,
39+
"data": {
40+
"type": 2,
41+
"len": 140
42+
}
43+
},
44+
{
45+
"id": 4,
46+
"video": {
47+
"linearity": 1,
48+
"minduration": 15,
49+
"maxduration": 30,
50+
"protocols": [2, 3],
51+
"mimes": ["video/mp4"]
52+
}
53+
}
54+
]
55+
}

native/request/title.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package request
2+
3+
import "encoding/json"
4+
5+
type Title struct {
6+
Length int `json:"len"` // Maximum length of the text in the title element
7+
Ext json.RawMessage `json:"ext,omitempty"`
8+
}

native/request/video.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package request
2+
3+
import "encoding/json"
4+
5+
// TODO unclear if its the same as imp.video https://github.com/openrtb/OpenRTB/issues/26
6+
type Video struct {
7+
Mimes []string `json:"mimes,omitempty"` // Whitelist of content MIME types supported
8+
MinDuration int `json:"minduration,omitempty"` // Minimum video ad duration in seconds
9+
MaxDuration int `json:"maxduration,omitempty"` // Maximum video ad duration in seconds
10+
Protocols []int `json:"protocols,omitempty"` // Video bid response protocols
11+
Ext json.RawMessage `json:"ext,omitempty"`
12+
}

native/response/asset.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package response
2+
3+
import "encoding/json"
4+
5+
// Corresponds to the Asset Object in the request. The main container object for
6+
// each asset requested or supported by Exchange on behalf of the rendering
7+
// client. Any object that is required is to be flagged as such. Only one of the
8+
// {title,img,video,data} objects should be present in each object. All others
9+
// should be null/absent. The id is to be unique within the AssetObject array so
10+
// that the response can be aligned.
11+
type Asset struct {
12+
ID int `json:"id"` // Unique asset ID, assigned by exchange, must match one of the asset IDs in request
13+
Required int `json:"required,omitempty"` // Set to 1 if asset is required
14+
Title *Title `json:"title,omitempty"` // Title object for title assets
15+
Image *Image `json:"img,omitempty"` // Image object for image assets
16+
Video *Video `json:"video,omitempty"` // Video object for video assets
17+
Data *Data `json:"data,omitempty"` // Data object for brand name, description, ratings, prices etc.
18+
Link *Link `json:"link,omitempty"` // Link object for call to actions. The link object applies if the asset item is activated (clicked)
19+
Ext json.RawMessage `json:"ext,omitempty"`
20+
}

native/response/data.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package response
2+
3+
import "encoding/json"
4+
5+
type Data struct {
6+
Label string `json:"label,omitempty"` // The optional formatted string name of the data type to be displayed
7+
Value string `json:"value"` // The formatted string of data to be displayed. Can contain a formatted value such as “5 stars” or “$10” or “3.4 stars out of 5”
8+
Ext json.RawMessage `json:"ext,omitempty"`
9+
}

0 commit comments

Comments
 (0)