Skip to content

Commit 9f0e716

Browse files
authored
Merge pull request #3 from UnityTech/APIN-632
[APIN-632] add Metric to Impression object
2 parents 62306bb + 667a10e commit 9f0e716

6 files changed

Lines changed: 66 additions & 0 deletions

File tree

impression.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ var (
1717
// subordinate to the Imp object indicates the type of impression being offered.
1818
type Impression struct {
1919
ID string `json:"id"` // A unique identifier for this impression
20+
Metric []*Metric `json:"metric,omitempty"`
2021
Banner *Banner `json:"banner,omitempty"`
2122
Video *Video `json:"video,omitempty"`
2223
Audio *Audio `json:"audio,omitempty"`

impression_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@ var _ = Describe("Impression", func() {
1616
It("should parse correctly", func() {
1717
Expect(subject).To(Equal(&Impression{
1818
ID: "1",
19+
Metric: []*Metric{
20+
{
21+
Type: "viewable_percentage_1",
22+
Value: 0.99,
23+
Vendor: "MOAT",
24+
},
25+
{
26+
Type: "viewable_percentage_2",
27+
Value: 0.98,
28+
Vendor: "MOAT",
29+
},
30+
},
1931
Banner: &Banner{
2032
W: 300,
2133
H: 250,

metric.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package openrtb
2+
3+
// Metric object is associated with an impression as an array of metrics. These metrics can offer insight into
4+
// the impression to assist with decisioning such as average recent viewability, click-through rate, etc. Each
5+
// metric is identified by its type, reports the value of the metric, and optionally identifies the source or
6+
// vendor measuring the value.
7+
type Metric struct {
8+
Type string `json:"type"`
9+
Value float64 `json:"value"`
10+
Vendor string `json:"vendor"`
11+
Ext Extension `json:"ext,omitempty"`
12+
}

metric_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package openrtb
2+
3+
import (
4+
. "github.com/onsi/ginkgo"
5+
. "github.com/onsi/gomega"
6+
)
7+
8+
var _ = Describe("Metric", func() {
9+
var metric *Metric
10+
11+
BeforeEach(func() {
12+
err := fixture("metric", &metric)
13+
Expect(err).NotTo(HaveOccurred())
14+
})
15+
16+
It("should parse correctly", func() {
17+
Expect(metric).To(Equal(&Metric{
18+
Type: "viewable_percentage",
19+
Value: 0.99,
20+
Vendor: "MOAT",
21+
}))
22+
})
23+
24+
})

testdata/impression.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
{
22
"id": "1",
3+
"metric": [
4+
{
5+
"type": "viewable_percentage_1",
6+
"value": 0.99,
7+
"vendor": "MOAT"
8+
},
9+
{
10+
"type": "viewable_percentage_2",
11+
"value": 0.98,
12+
"vendor": "MOAT"
13+
}
14+
],
315
"banner": {
416
"h": 250,
517
"w": 300,

testdata/metric.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"type": "viewable_percentage",
3+
"value": 0.99,
4+
"vendor": "MOAT"
5+
}

0 commit comments

Comments
 (0)