Skip to content

Commit

Permalink
Merge pull request #6 from mapbox-jp/fix-tracking-and-error-tags
Browse files Browse the repository at this point in the history
Fix tracking and error tags
  • Loading branch information
yukinarit authored Oct 18, 2022
2 parents 7894887 + 0fafa40 commit 7b43fbe
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "vast-protocol"
version = "0.1.0"
version = "0.2.0"
edition = "2018"
description = "VAST protocol v4 parser on top of serde-rs"
readme = "README.md"
Expand Down
20 changes: 12 additions & 8 deletions src/v4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,19 @@ pub struct Wrapper;
#[serde(rename_all = "PascalCase")]
pub struct InLine {
pub ad_system: AdSystem,
pub error: Option<String>,
pub ad_title: AdTitle,
pub error: Option<Error>,
pub impression: Impression,
pub description: Option<String>,
pub advertiser: Option<String>,
pub pricing: Option<Pricing>,
pub ad_title: AdTitle,
pub creatives: Creatives,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Error(pub String);

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AdTitle(pub String);
Expand Down Expand Up @@ -160,13 +164,13 @@ impl From<std::time::Duration> for Duration {
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TrackingEvents {
#[serde(rename(serialize = "TrackingEvent", deserialize = "$value"))]
pub content: Vec<TrackingEvent>,
#[serde(rename(serialize = "Tracking", deserialize = "$value"))]
pub content: Vec<Tracking>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TrackingEvent {
pub struct Tracking {
pub event: String,
pub offset: Option<String>,
#[serde(rename = "$value")]
Expand All @@ -187,17 +191,17 @@ pub struct MediaFiles {
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MediaFile {
pub id: Option<String>,
pub delivery: String,
pub r#type: String,
pub bitrate: Option<u64>,
pub width: u64,
pub height: u64,
pub codec: Option<String>,
pub id: Option<String>,
pub bitrate: Option<u64>,
pub min_bitrate: Option<u64>,
pub max_bitrate: Option<u64>,
pub scalable: Option<String>,
pub maintain_aspect_ratio: Option<String>,
pub codec: Option<String>,
pub api_framework: Option<String>,
#[serde(rename = "$value")]
pub content: String,
Expand Down
5 changes: 4 additions & 1 deletion tests/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ fn deserialize_v4() {
assert_eq!("iabtechlab", in_line.ad_system.content);

// Error tag
assert_eq!("http://example.com/error", in_line.error.as_ref().unwrap());
assert_eq!(
"http://example.com/error",
in_line.error.as_ref().unwrap().0
);

// Impression tag
assert_eq!("Impression-ID", in_line.impression.id);
Expand Down
56 changes: 47 additions & 9 deletions tests/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,45 @@ use vast_protocol::v4::*;

#[test]
fn serialize_v4() {
let xml = r#"<VAST version="4.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.iab.com/VAST"><Ad id="20001" sequence="1" conditionalAd="false"><InLine><AdSystem version="4.0">iabtechlab</AdSystem><AdTitle>iabtechlab video ad</AdTitle><Impression id="Impression-ID">http://example.com/track/impression</Impression><Pricing model="cpm" currency="USD"> 25.00 </Pricing><Creatives><Creative id="5480" sequence="1" adId="2447226"><UniversalAdId idRegistry="Ad-ID" idValue="8465">8465</UniversalAdId><Linear><TrackingEvents><TrackingEvent event="start">http://example.com/tracking/start</TrackingEvent><TrackingEvent event="firstQuartile">http://example.com/tracking/firstQuartile</TrackingEvent><TrackingEvent event="midpoint">http://example.com/tracking/midpoint</TrackingEvent><TrackingEvent event="thirdQuartile">http://example.com/tracking/thirdQuartile</TrackingEvent><TrackingEvent event="complete">http://example.com/tracking/complete</TrackingEvent><TrackingEvent event="progress" offset="00:00:10">http://example.com/tracking/progress-10</TrackingEvent></TrackingEvents><Duration>00:00:16</Duration><MediaFiles><MediaFile delivery="progress" type="video/mp4" width="1280" height="720" codec="H.264" id="5241" bitrate="2000" minBitrate="1500" maxBitrate="2500" scalable="1" maintainAspectRatio="1">https://iab-publicfiles.s3.amazonaws.com/vast/VAST-4.0-Short-Intro.mp4</MediaFile></MediaFiles><VideoClicks><ClickThrough id="blog">https://iabtechlab.com</ClickThrough></VideoClicks></Linear></Creative></Creatives></InLine></Ad></VAST>"#;
let xml = "\
<VAST version=\"4.0\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"http://www.iab.com/VAST\">\
<Ad id=\"20001\" sequence=\"1\" conditionalAd=\"false\">\
<InLine>\
<AdSystem version=\"4.0\">iabtechlab</AdSystem>\
<Error>http://example.com/error</Error>\
<Impression id=\"Impression-ID\">http://example.com/track/impression</Impression>\
<Pricing model=\"cpm\" currency=\"USD\"> 25.00 </Pricing>\
<AdTitle>iabtechlab video ad</AdTitle>\
<Creatives>\
<Creative id=\"5480\" sequence=\"1\" adId=\"2447226\">\
<UniversalAdId idRegistry=\"Ad-ID\" idValue=\"8465\">8465</UniversalAdId>\
<Linear>\
<TrackingEvents>\
<Tracking event=\"start\">http://example.com/tracking/start</Tracking>\
<Tracking event=\"firstQuartile\">http://example.com/tracking/firstQuartile</Tracking>\
<Tracking event=\"midpoint\">http://example.com/tracking/midpoint</Tracking>\
<Tracking event=\"thirdQuartile\">http://example.com/tracking/thirdQuartile</Tracking>\
<Tracking event=\"complete\">http://example.com/tracking/complete</Tracking>\
<Tracking event=\"progress\" offset=\"00:00:10\">http://example.com/tracking/progress-10</Tracking>\
</TrackingEvents>\
<Duration>00:00:16</Duration>\
<MediaFiles>\
<MediaFile id=\"5241\" delivery=\"progressive\" type=\"video/mp4\" bitrate=\"2000\" width=\"1280\" height=\"720\" minBitrate=\"1500\" maxBitrate=\"2500\" scalable=\"1\" maintainAspectRatio=\"1\" codec=\"H.264\">\
https://iab-publicfiles.s3.amazonaws.com/vast/VAST-4.0-Short-Intro.mp4\
</MediaFile>\
</MediaFiles>\
<VideoClicks>\
<ClickThrough id=\"blog\">\
https://iabtechlab.com\
</ClickThrough>\
</VideoClicks>\
</Linear>\
</Creative>\
</Creatives>\
</InLine>\
</Ad>\
</VAST>\
";

let vast = VAST::new("4.0", Ad {
id: "20001".into(),
Expand All @@ -17,7 +55,7 @@ fn serialize_v4() {
ad_title: AdTitle("iabtechlab video ad".into()),
advertiser: None,
description: None,
error: None,
error: Some(Error("http://example.com/error".into())),
impression: Impression {
id: "Impression-ID".into(),
content: "http://example.com/track/impression".into(),
Expand Down Expand Up @@ -45,7 +83,7 @@ fn serialize_v4() {
content: vec![
MediaFile {
id: Some("5241".into()),
delivery: "progress".into(),
delivery: "progressive".into(),
r#type: "video/mp4".into(),
width: 1280,
height: 720,
Expand All @@ -62,12 +100,12 @@ fn serialize_v4() {
},
tracking_events: TrackingEvents {
content: vec![
TrackingEvent { event: "start".into(), offset: None, content:"http://example.com/tracking/start".into() },
TrackingEvent { event: "firstQuartile".into(), offset: None, content: "http://example.com/tracking/firstQuartile".into() },
TrackingEvent { event: "midpoint".into(), offset: None, content: "http://example.com/tracking/midpoint".into() },
TrackingEvent { event: "thirdQuartile".into(), offset: None, content: "http://example.com/tracking/thirdQuartile".into() },
TrackingEvent { event: "complete".into(), offset: None, content: "http://example.com/tracking/complete".into() },
TrackingEvent { event: "progress".into(), offset: Some("00:00:10".into()), content: "http://example.com/tracking/progress-10".into() },
Tracking { event: "start".into(), offset: None, content:"http://example.com/tracking/start".into() },
Tracking { event: "firstQuartile".into(), offset: None, content: "http://example.com/tracking/firstQuartile".into() },
Tracking { event: "midpoint".into(), offset: None, content: "http://example.com/tracking/midpoint".into() },
Tracking { event: "thirdQuartile".into(), offset: None, content: "http://example.com/tracking/thirdQuartile".into() },
Tracking { event: "complete".into(), offset: None, content: "http://example.com/tracking/complete".into() },
Tracking { event: "progress".into(), offset: Some("00:00:10".into()), content: "http://example.com/tracking/progress-10".into() },
]
},
video_clicks: Some(VideoClicks {
Expand Down

0 comments on commit 7b43fbe

Please sign in to comment.