From 210a06f0aa4f4f798f527007b8ddf86df9e7e21c Mon Sep 17 00:00:00 2001 From: Max Cherry Date: Fri, 28 Dec 2018 15:39:16 +0200 Subject: [PATCH] adcom1: helper objects (object bundles) for openrtb3, tests --- adcom1/adcom1_suite_test.go | 13 ++++++ adcom1/adcom1_test.go | 31 ++++++++++++++ adcom1/bid_media.go | 10 +++++ adcom1/item_spec.go | 10 +++++ adcom1/request_context.go | 17 ++++++++ adcom1/testdata/item-specifications.json | 30 ++++++++++++++ adcom1/testdata/media-response.json | 29 ++++++++++++++ adcom1/testdata/request-context.json | 51 ++++++++++++++++++++++++ openrtb3/bid.go | 2 + openrtb3/item.go | 2 + openrtb3/request.go | 2 + 11 files changed, 197 insertions(+) create mode 100644 adcom1/adcom1_suite_test.go create mode 100644 adcom1/adcom1_test.go create mode 100644 adcom1/bid_media.go create mode 100644 adcom1/item_spec.go create mode 100644 adcom1/request_context.go create mode 100644 adcom1/testdata/item-specifications.json create mode 100644 adcom1/testdata/media-response.json create mode 100644 adcom1/testdata/request-context.json diff --git a/adcom1/adcom1_suite_test.go b/adcom1/adcom1_suite_test.go new file mode 100644 index 0000000..306b230 --- /dev/null +++ b/adcom1/adcom1_suite_test.go @@ -0,0 +1,13 @@ +package adcom1_test + +import ( + "testing" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" +) + +func TestAdcom1(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "Adcom1 Suite") +} diff --git a/adcom1/adcom1_test.go b/adcom1/adcom1_test.go new file mode 100644 index 0000000..b004dfd --- /dev/null +++ b/adcom1/adcom1_test.go @@ -0,0 +1,31 @@ +package adcom1_test + +import ( + "encoding/json" + "io/ioutil" + "path/filepath" + + . "github.com/onsi/ginkgo/extensions/table" + . "github.com/onsi/gomega" + + . "github.com/mxmCherry/openrtb/adcom1" +) + +var _ = DescribeTable( + "Marshaling", + func(obj interface{}, file string) { + golden, err := ioutil.ReadFile(filepath.Join("testdata", file)) + Expect(err).NotTo(HaveOccurred()) + + Expect(json.Unmarshal(golden, obj)).To(Succeed()) + + b, err := json.Marshal(obj) + Expect(err).NotTo(HaveOccurred()) + + Expect(b).To(MatchJSON(golden)) + }, + + Entry("request context", new(RequestContext), "request-context.json"), + Entry("item specifications", new(ItemSpec), "item-specifications.json"), + Entry("media response", new(BidMedia), "media-response.json"), +) diff --git a/adcom1/bid_media.go b/adcom1/bid_media.go new file mode 100644 index 0000000..a71e511 --- /dev/null +++ b/adcom1/bid_media.go @@ -0,0 +1,10 @@ +package adcom1 + +// BidMedia represents a bunch of data for OpenRTB 3 Bid.media field. +// Refer to OpenRTB 3.0 specification for details. +// +// For AdCOM v1.x, the objects allowed here are “Ad” and any objects subordinate thereto as specified by AdCOM. +// +type BidMedia struct { + Ad *Ad `json:"ad,omitempty"` +} diff --git a/adcom1/item_spec.go b/adcom1/item_spec.go new file mode 100644 index 0000000..b91f142 --- /dev/null +++ b/adcom1/item_spec.go @@ -0,0 +1,10 @@ +package adcom1 + +// ItemSpec represents a bunch of data for OpenRTB 3 Item.spec field. +// Refer to OpenRTB 3.0 specification for details. +// +// For AdCOM v1.x, the objects allowed here are Placement and any objects subordinate to these as specified by AdCOM. +// +type ItemSpec struct { + Placement *Placement `json:"placement,omitempty"` +} diff --git a/adcom1/request_context.go b/adcom1/request_context.go new file mode 100644 index 0000000..fffa77d --- /dev/null +++ b/adcom1/request_context.go @@ -0,0 +1,17 @@ +package adcom1 + +// RequestContext represents a bunch of data for OpenRTB 3 Request.context field. +// Refer to OpenRTB 3.0 specification for details. +// +// For AdCOM v1.x, the objects allowed here all of which are optional are one of the DistributionChannel subtypes (i.e., Site, App, or Dooh), User, Device, Regs, Restrictions, and any objects subordinate to these as specified by AdCOM. +// +type RequestContext struct { + Site *Site `json:"site,omitempty"` + App *App `json:"app,omitempty"` + DOOH *DOOH `json:"dooh,omitempty"` + + User *User `json:"user,omitempty"` + Device *Device `json:"device,omitempty"` + Regs *Regs `json:"regs,omitempty"` + Restrictions *Restrictions `json:"restrictions,omitempty"` +} diff --git a/adcom1/testdata/item-specifications.json b/adcom1/testdata/item-specifications.json new file mode 100644 index 0000000..9d5e516 --- /dev/null +++ b/adcom1/testdata/item-specifications.json @@ -0,0 +1,30 @@ +{ + "placement": { + "tagid": "plc-ftr-123abc", + "secure": 1, + "display": { + "ctype": [ + 2, + 3 + ], + "displayfmt": [ + { + "w": 320, + "h": 50 + }, + { + "w": 320, + "h": 250 + } + ], + "event": [ + { + "type": 1, + "method": [ + 1 + ] + } + ] + } + } +} diff --git a/adcom1/testdata/media-response.json b/adcom1/testdata/media-response.json new file mode 100644 index 0000000..2bf68a3 --- /dev/null +++ b/adcom1/testdata/media-response.json @@ -0,0 +1,29 @@ +{ + "ad": { + "id": "d0bcb39723af87c2bb00942afee5710e", + "adomain": [ + "ford.com" + ], + "secure": 1, + "display": { + "mime": "image/jpeg", + "type": 3, + "w": 320, + "h": 50, + "banner": { + "img": "https://somebuyer.com/creative", + "link": { + "url": "https://somebuyer.com/click", + "urlfb": "https://somebuyer.com" + } + }, + "event": [ + { + "type": 1, + "method": 1, + "url": "https://somebuyer.com/pixel" + } + ] + } + } +} diff --git a/adcom1/testdata/request-context.json b/adcom1/testdata/request-context.json new file mode 100644 index 0000000..57e9e80 --- /dev/null +++ b/adcom1/testdata/request-context.json @@ -0,0 +1,51 @@ +{ + "regs": {}, + "restrictions": { + "bcat": [ + "IAB24", + "IAB25", + "IAB26" + ], + "cattax": 1, + "badv": [ + "ford.com", + "buick.com" + ] + }, + "site": { + "id": "1234", + "name": "Awesome Example Site", + "domain": "examplesitedomain.com", + "mobile": 1, + "pub": { + "id": "9876", + "name": "Example Publisher, Inc.", + "domain": "examplepubdomain.com" + } + }, + "user": { + "id": "a0af45c77890045deec100acb8443baff57c", + "buyeruid": "fcd4282456238256034abcdef220d9aa5892", + "yob": 1990, + "gender": "F" + }, + "device": { + "type": 4, + "ifa": "8846d6fa10008bceaaf322908dfcb221", + "ip": "1.2.3.4", + "ua": "...user agent string...", + "make": "Apple", + "model": "iPhone", + "hwv": "6s", + "os": 13, + "osv": "11.4.1", + "mccmnc": "310-005", + "geo": { + "type": 1, + "lat": 42.3601, + "lon": 71.0581, + "country": "USA", + "utcoffset": -300 + } + } +} diff --git a/openrtb3/bid.go b/openrtb3/bid.go index 8b47162..f41c7ef 100644 --- a/openrtb3/bid.go +++ b/openrtb3/bid.go @@ -116,6 +116,8 @@ type Bid struct { // Definition: // Layer-4 domain object structure that specifies the media to be presented if the bid is won conforming to the specification and version referenced in openrtb.domainspec and openrtb.domainver // For AdCOM v1.x, the objects allowed here are “Ad” and any objects subordinate thereto as specified by AdCOM. + // Dev note: + // This object is implemented as ../adcom1.BidMedia type. Media json.RawMessage `json:"media,omitempty"` // Attribute: diff --git a/openrtb3/item.go b/openrtb3/item.go index 487986d..6d5793a 100644 --- a/openrtb3/item.go +++ b/openrtb3/item.go @@ -104,6 +104,8 @@ type Item struct { // Definition: // Layer-4 domain object structure that provides specifies the item being offered conforming to the specification and version referenced in openrtb.domainspec and openrtb.domainver. // For AdCOM v1.x, the objects allowed here are Placement and any objects subordinate to these as specified by AdCOM. + // Dev note: + // This object is implemented as ../adcom1.ItemSpec type. Spec json.RawMessage `json:"spec"` // Attribute: diff --git a/openrtb3/request.go b/openrtb3/request.go index 9c36807..dffd22f 100644 --- a/openrtb3/request.go +++ b/openrtb3/request.go @@ -112,6 +112,8 @@ type Request struct { // Definition: // Layer-4 domain object structure that provides context for the items being offered conforming to the specification and version referenced in openrtb.domainspec and openrtb.domainver. // For AdCOM v1.x, the objects allowed here all of which are optional are one of the DistributionChannel subtypes (i.e., Site, App, or Dooh), User, Device, Regs, Restrictions, and any objects subordinate to these as specified by AdCOM. + // Dev note: + // This object is implemented as ../adcom1.RequestContext type. Context json.RawMessage `json:"context,omitempty"` // Attribute: