Skip to content

Commit 969ded8

Browse files
authored
Merge pull request #2 from ClearcodeHQ/fix-structs-order
Fix some structs order to comply with IAB's .xsd
2 parents eef7d98 + e8adefe commit 969ded8

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

vast.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ type CDATAString struct {
5353
type InLine struct {
5454
// The name of the ad server that returned the ad
5555
AdSystem *AdSystem
56-
// The common name of the ad
57-
AdTitle CDATAString
5856
// One or more URIs that directs the video player to a tracking resource file that the
5957
// video player should request when the first frame of the ad is displayed
6058
Impressions []Impression `xml:"Impression"`
6159
// Any ad server that returns a VAST containing an <InLine> ad must generate a pseudo- unique identifier
6260
// that is appropriate for all involved parties to track the lifecycle of that ad.
6361
// Example: ServerName-47ed3bac-1768-4b9a-9d0e-0b92422ab066
6462
AdServingId string `xml:",omitempty" json:",omitempty"`
63+
// The common name of the ad
64+
AdTitle CDATAString
6565
// The container for one or more <Creative> elements
6666
Creatives []Creative `xml:"Creatives>Creative"`
6767
// A string value that provides a longer description of the ad.
@@ -162,14 +162,14 @@ type Creative struct {
162162
AdID string `xml:"AdID,attr,omitempty" json:",omitempty"`
163163
// The technology used for any included API
164164
APIFramework string `xml:"apiFramework,attr,omitempty" json:",omitempty"`
165+
// If present, provides a VAST 4.x universal ad id
166+
UniversalAdID *UniversalAdID `xml:"UniversalAdId,omitempty" json:",omitempty"`
165167
// If present, defines a linear creative
166168
Linear *Linear `xml:",omitempty" json:",omitempty"`
167169
// If defined, defins companions creatives
168170
CompanionAds *CompanionAds `xml:",omitempty" json:",omitempty"`
169171
// If defined, defines non linear creatives
170172
NonLinearAds *NonLinearAds `xml:",omitempty" json:",omitempty"`
171-
// If present, provides a VAST 4.x universal ad id
172-
UniversalAdID *UniversalAdID `xml:"UniversalAdId,omitempty" json:",omitempty"`
173173
// When an API framework is needed to execute creative, a
174174
// <CreativeExtensions> element can be added under the <Creative>. This
175175
// extension can be used to load an executable creative with or without using
@@ -248,13 +248,13 @@ type Linear struct {
248248
// indicates when the skip control should be provided after the creative
249249
// begins playing.
250250
SkipOffset *Offset `xml:"skipoffset,attr,omitempty" json:",omitempty"`
251-
// Duration in standard time format, hh:mm:ss
252-
Duration Duration
253251
AdParameters *AdParameters `xml:",omitempty" json:",omitempty"`
254252
Icons *Icons `json:",omitempty"`
255253
TrackingEvents []Tracking `xml:"TrackingEvents>Tracking,omitempty" json:",omitempty"`
256-
VideoClicks *VideoClicks `xml:",omitempty" json:",omitempty"`
254+
// Duration in standard time format, hh:mm:ss
255+
Duration Duration
257256
MediaFiles []MediaFile `xml:"MediaFiles>MediaFile,omitempty" json:",omitempty"`
257+
VideoClicks *VideoClicks `xml:",omitempty" json:",omitempty"`
258258
}
259259

260260
// LinearWrapper defines a wrapped linear creative
@@ -539,6 +539,6 @@ type MediaFile struct {
539539
// UniversalAdID describes a VAST 4.x universal ad id.
540540
type UniversalAdID struct {
541541
IDRegistry string `xml:"idRegistry,attr"`
542-
IDValue string `xml:"idValue,attr"`
542+
IDValue string `xml:"idValue,attr,omitempty"`
543543
ID string `xml:",cdata"`
544544
}

vast_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func TestQuickStart(t *testing.T) {
7474
},
7575
}
7676

77-
want := []byte(`{"Version":"3.0","Ad":[{"ID":"123","Type":"front","InLine":{"AdSystem":{"Data":"DSP"},"AdTitle":{"Data":"adTitle"},"Impressions":[{"ID":"11111","URI":"http://impressionv1.track.com"},{"ID":"11112","URI":"http://impressionv2.track.com"}],"Creatives":[{"ID":"987","Linear":{"SkipOffset":"00:00:05","Duration":"00:00:15","TrackingEvents":[{"Event":"start","URI":"http://track.xxx.com/q/start?xx"},{"Event":"firstQuartile","URI":"http://track.xxx.com/q/firstQuartile?xx"},{"Event":"midpoint","URI":"http://track.xxx.com/q/midpoint?xx"},{"Event":"thirdQuartile","URI":"http://track.xxx.com/q/thirdQuartile?xx"},{"Event":"complete","URI":"http://track.xxx.com/q/complete?xx"}],"MediaFiles":[{"Delivery":"progressive","Type":"video/mp4","Width":1024,"Height":576,"URI":"http://mp4.res.xxx.com/new_video/2020/01/14/1485/335928CBA9D02E95E63ED9F4D45DF6DF_20200114_1_1_1051.mp4","Label":"123"}]}}],"Extensions":[{"Type":"ClassName","Data":"AdsVideoView"},{"Type":"ExtURL","Data":"http://xxxxxxxx"}]}}],"Mute":true}`)
77+
want := []byte(`{"Version":"3.0","Ad":[{"ID":"123","Type":"front","InLine":{"AdSystem":{"Data":"DSP"},"Impressions":[{"ID":"11111","URI":"http://impressionv1.track.com"},{"ID":"11112","URI":"http://impressionv2.track.com"}],"AdTitle":{"Data":"adTitle"},"Creatives":[{"ID":"987","Linear":{"SkipOffset":"00:00:05","TrackingEvents":[{"Event":"start","URI":"http://track.xxx.com/q/start?xx"},{"Event":"firstQuartile","URI":"http://track.xxx.com/q/firstQuartile?xx"},{"Event":"midpoint","URI":"http://track.xxx.com/q/midpoint?xx"},{"Event":"thirdQuartile","URI":"http://track.xxx.com/q/thirdQuartile?xx"},{"Event":"complete","URI":"http://track.xxx.com/q/complete?xx"}],"Duration":"00:00:15","MediaFiles":[{"Delivery":"progressive","Type":"video/mp4","Width":1024,"Height":576,"URI":"http://mp4.res.xxx.com/new_video/2020/01/14/1485/335928CBA9D02E95E63ED9F4D45DF6DF_20200114_1_1_1051.mp4","Label":"123"}]}}],"Extensions":[{"Type":"ClassName","Data":"AdsVideoView"},{"Type":"ExtURL","Data":"http://xxxxxxxx"}]}}],"Mute":true}`)
7878
got, err := json.Marshal(v)
7979
t.Logf("%s", got)
8080
if err != nil {
@@ -218,7 +218,7 @@ func TestCreateVastJson(t *testing.T) {
218218
want []byte
219219
wantErr bool
220220
}{
221-
{name: "testCase1", want: []byte(`{"Version":"3.0","xmlns":"http://www.iab.com/VAST","Ad":[{"ID":"123","Type":"front","InLine":{"AdSystem":{"Data":"DSP"},"AdTitle":{"Data":"ad title"},"Impressions":[{"ID":"456","URI":"http://impression.track.cn"}],"Creatives":[{"ID":"123456","Linear":{"Duration":"00:00:15","TrackingEvents":[{"Event":"start","URI":"http://track.xxx.com/q/start?xx"}],"MediaFiles":[{"Delivery":"progressive","Type":"video/mp4","Width":1024,"Height":576,"URI":"http://mp4.res.xxx.com/new_video/2020/01/14/1485/335928CBA9D02E95E63ED9F4D45DF6DF_20200114_1_1_1051.mp4"}]}}]}}]}`),
221+
{name: "testCase1", want: []byte(`{"Version":"3.0","xmlns":"http://www.iab.com/VAST","Ad":[{"ID":"123","Type":"front","InLine":{"AdSystem":{"Data":"DSP"},"Impressions":[{"ID":"456","URI":"http://impression.track.cn"}],"AdTitle":{"Data":"ad title"},"Creatives":[{"ID":"123456","Linear":{"TrackingEvents":[{"Event":"start","URI":"http://track.xxx.com/q/start?xx"}],"Duration":"00:00:15","MediaFiles":[{"Delivery":"progressive","Type":"video/mp4","Width":1024,"Height":576,"URI":"http://mp4.res.xxx.com/new_video/2020/01/14/1485/335928CBA9D02E95E63ED9F4D45DF6DF_20200114_1_1_1051.mp4"}]}}]}}]}`),
222222
wantErr: false},
223223
}
224224
for _, tt := range tests {
@@ -242,7 +242,7 @@ func TestCreateVastXML(t *testing.T) {
242242
want []byte
243243
wantErr bool
244244
}{
245-
{name: "testCase1", want: []byte(`<VAST version="3.0" xmlns="http://www.iab.com/VAST"><Ad id="123" type="front"><InLine><AdSystem><![CDATA[DSP]]></AdSystem><AdTitle><![CDATA[ad title]]></AdTitle><Impression id="456"><![CDATA[http://impression.track.cn]]></Impression><Creatives><Creative id="123456"><Linear><Duration>00:00:15</Duration><TrackingEvents><Tracking event="start"><![CDATA[http://track.xxx.com/q/start?xx]]></Tracking></TrackingEvents><MediaFiles><MediaFile delivery="progressive" type="video/mp4" width="1024" height="576"><![CDATA[http://mp4.res.xxx.com/new_video/2020/01/14/1485/335928CBA9D02E95E63ED9F4D45DF6DF_20200114_1_1_1051.mp4]]></MediaFile></MediaFiles></Linear></Creative></Creatives></InLine></Ad></VAST>`),
245+
{name: "testCase1", want: []byte(`<VAST version="3.0" xmlns="http://www.iab.com/VAST"><Ad id="123" type="front"><InLine><AdSystem><![CDATA[DSP]]></AdSystem><Impression id="456"><![CDATA[http://impression.track.cn]]></Impression><AdTitle><![CDATA[ad title]]></AdTitle><Creatives><Creative id="123456"><Linear><TrackingEvents><Tracking event="start"><![CDATA[http://track.xxx.com/q/start?xx]]></Tracking></TrackingEvents><Duration>00:00:15</Duration><MediaFiles><MediaFile delivery="progressive" type="video/mp4" width="1024" height="576"><![CDATA[http://mp4.res.xxx.com/new_video/2020/01/14/1485/335928CBA9D02E95E63ED9F4D45DF6DF_20200114_1_1_1051.mp4]]></MediaFile></MediaFiles></Linear></Creative></Creatives></InLine></Ad></VAST>`),
246246
wantErr: false},
247247
}
248248
for _, tt := range tests {

0 commit comments

Comments
 (0)